2017-03-17 08:47:23 +00:00
|
|
|
// Package http provides a filesystem interface using golang.org/net/http
|
2017-04-22 10:48:32 +00:00
|
|
|
//
|
2017-06-19 16:36:14 +00:00
|
|
|
// It treats HTML pages served from the endpoint as directory
|
2017-04-22 10:48:32 +00:00
|
|
|
// listings, and includes any links found as files.
|
2017-03-17 08:47:23 +00:00
|
|
|
|
2017-06-19 16:36:14 +00:00
|
|
|
// +build go1.7
|
2017-03-17 08:47:23 +00:00
|
|
|
|
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"path"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ncw/rclone/fs"
|
2018-01-12 16:30:54 +00:00
|
|
|
"github.com/ncw/rclone/fs/config"
|
|
|
|
"github.com/ncw/rclone/fs/fshttp"
|
|
|
|
"github.com/ncw/rclone/fs/hash"
|
2018-01-11 16:29:20 +00:00
|
|
|
"github.com/ncw/rclone/lib/rest"
|
2017-03-17 08:47:23 +00:00
|
|
|
"github.com/pkg/errors"
|
2017-06-19 14:05:09 +00:00
|
|
|
"golang.org/x/net/html"
|
2017-03-17 08:47:23 +00:00
|
|
|
)
|
|
|
|
|
2017-06-19 16:36:14 +00:00
|
|
|
var (
|
|
|
|
errorReadOnly = errors.New("http remotes are read only")
|
|
|
|
timeUnset = time.Unix(0, 0)
|
|
|
|
)
|
2017-06-19 14:05:09 +00:00
|
|
|
|
2017-03-17 08:47:23 +00:00
|
|
|
func init() {
|
|
|
|
fsi := &fs.RegInfo{
|
|
|
|
Name: "http",
|
|
|
|
Description: "http Connection",
|
|
|
|
NewFs: NewFs,
|
|
|
|
Options: []fs.Option{{
|
2017-06-19 16:36:14 +00:00
|
|
|
Name: "url",
|
2017-06-19 14:05:09 +00:00
|
|
|
Help: "URL of http host to connect to",
|
2017-03-17 08:47:23 +00:00
|
|
|
Optional: false,
|
|
|
|
Examples: []fs.OptionExample{{
|
2017-06-19 14:05:09 +00:00
|
|
|
Value: "https://example.com",
|
2017-03-17 08:47:23 +00:00
|
|
|
Help: "Connect to example.com",
|
|
|
|
}},
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
fs.Register(fsi)
|
|
|
|
}
|
|
|
|
|
2017-04-22 10:48:32 +00:00
|
|
|
// Fs stores the interface to the remote HTTP files
|
2017-03-17 08:47:23 +00:00
|
|
|
type Fs struct {
|
2017-08-02 12:19:36 +00:00
|
|
|
name string
|
|
|
|
root string
|
|
|
|
features *fs.Features // optional features
|
|
|
|
endpoint *url.URL
|
|
|
|
endpointURL string // endpoint as a string
|
|
|
|
httpClient *http.Client
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Object is a remote object that has been stat'd (so it exists, but is not necessarily open for reading)
|
|
|
|
type Object struct {
|
2017-06-19 16:36:14 +00:00
|
|
|
fs *Fs
|
|
|
|
remote string
|
|
|
|
size int64
|
|
|
|
modTime time.Time
|
|
|
|
contentType string
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 16:36:14 +00:00
|
|
|
// statusError returns an error if the res contained an error
|
|
|
|
func statusError(res *http.Response, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
if res.StatusCode < 200 || res.StatusCode > 299 {
|
|
|
|
_ = res.Body.Close()
|
|
|
|
return errors.Errorf("HTTP Error %d: %s", res.StatusCode, res.Status)
|
|
|
|
}
|
|
|
|
return nil
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewFs creates a new Fs object from the name and root. It connects to
|
|
|
|
// the host specified in the config file.
|
|
|
|
func NewFs(name, root string) (fs.Fs, error) {
|
2018-01-12 16:30:54 +00:00
|
|
|
endpoint := config.FileGet(name, "url")
|
2017-06-19 16:36:14 +00:00
|
|
|
if !strings.HasSuffix(endpoint, "/") {
|
|
|
|
endpoint += "/"
|
|
|
|
}
|
2017-03-17 08:47:23 +00:00
|
|
|
|
2017-06-19 16:36:14 +00:00
|
|
|
// Parse the endpoint and stick the root onto it
|
|
|
|
base, err := url.Parse(endpoint)
|
2017-03-17 08:47:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-01-05 15:55:43 +00:00
|
|
|
u, err := rest.URLJoin(base, rest.URLPathEscape(root))
|
2017-06-19 16:36:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 16:30:54 +00:00
|
|
|
client := fshttp.NewClient(fs.Config)
|
2017-03-17 08:47:23 +00:00
|
|
|
|
2017-06-19 16:36:14 +00:00
|
|
|
var isFile = false
|
|
|
|
if !strings.HasSuffix(u.String(), "/") {
|
|
|
|
// Make a client which doesn't follow redirects so the server
|
|
|
|
// doesn't redirect http://host/dir to http://host/dir/
|
|
|
|
noRedir := *client
|
|
|
|
noRedir.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
|
|
|
return http.ErrUseLastResponse
|
|
|
|
}
|
|
|
|
// check to see if points to a file
|
|
|
|
res, err := noRedir.Head(u.String())
|
|
|
|
err = statusError(res, err)
|
|
|
|
if err == nil {
|
|
|
|
isFile = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newRoot := u.String()
|
|
|
|
if isFile {
|
|
|
|
// Point to the parent if this is a file
|
|
|
|
newRoot, _ = path.Split(u.String())
|
|
|
|
} else {
|
|
|
|
if !strings.HasSuffix(newRoot, "/") {
|
|
|
|
newRoot += "/"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u, err = url.Parse(newRoot)
|
2017-03-17 08:47:23 +00:00
|
|
|
if err != nil {
|
2017-06-19 16:36:14 +00:00
|
|
|
return nil, err
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
|
2017-03-17 08:47:23 +00:00
|
|
|
f := &Fs{
|
2017-08-02 12:19:36 +00:00
|
|
|
name: name,
|
|
|
|
root: root,
|
|
|
|
httpClient: client,
|
|
|
|
endpoint: u,
|
|
|
|
endpointURL: u.String(),
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
2017-08-09 14:27:43 +00:00
|
|
|
f.features = (&fs.Features{
|
|
|
|
CanHaveEmptyDirectories: true,
|
|
|
|
}).Fill(f)
|
2017-06-19 16:36:14 +00:00
|
|
|
if isFile {
|
|
|
|
return f, fs.ErrorIsFile
|
|
|
|
}
|
2017-08-02 12:19:36 +00:00
|
|
|
if !strings.HasSuffix(f.endpointURL, "/") {
|
|
|
|
return nil, errors.New("internal error: url doesn't end with /")
|
|
|
|
}
|
2017-03-17 08:47:23 +00:00
|
|
|
return f, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns the configured name of the file system
|
|
|
|
func (f *Fs) Name() string {
|
|
|
|
return f.name
|
|
|
|
}
|
|
|
|
|
|
|
|
// Root returns the root for the filesystem
|
|
|
|
func (f *Fs) Root() string {
|
|
|
|
return f.root
|
|
|
|
}
|
|
|
|
|
|
|
|
// String returns the URL for the filesystem
|
|
|
|
func (f *Fs) String() string {
|
2017-08-02 12:19:36 +00:00
|
|
|
return f.endpointURL
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Features returns the optional features of this Fs
|
|
|
|
func (f *Fs) Features() *fs.Features {
|
|
|
|
return f.features
|
|
|
|
}
|
|
|
|
|
|
|
|
// Precision is the remote http file system's modtime precision, which we have no way of knowing. We estimate at 1s
|
|
|
|
func (f *Fs) Precision() time.Duration {
|
|
|
|
return time.Second
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewObject creates a new remote http file object
|
|
|
|
func (f *Fs) NewObject(remote string) (fs.Object, error) {
|
|
|
|
o := &Object{
|
|
|
|
fs: f,
|
|
|
|
remote: remote,
|
|
|
|
}
|
|
|
|
err := o.stat()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Stat failed")
|
|
|
|
}
|
|
|
|
return o, nil
|
|
|
|
}
|
|
|
|
|
2017-08-02 12:19:36 +00:00
|
|
|
// Join's the remote onto the base URL
|
|
|
|
func (f *Fs) url(remote string) string {
|
2018-01-05 15:55:43 +00:00
|
|
|
return f.endpointURL + rest.URLPathEscape(remote)
|
2017-08-02 12:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 08:47:23 +00:00
|
|
|
func parseInt64(s string) int64 {
|
|
|
|
n, e := strconv.ParseInt(s, 10, 64)
|
|
|
|
if e != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
2017-06-19 16:36:14 +00:00
|
|
|
// parseName turns a name as found in the page into a remote path or returns false
|
2017-07-30 22:16:32 +00:00
|
|
|
func parseName(base *url.URL, name string) (string, bool) {
|
2017-10-02 16:37:36 +00:00
|
|
|
u, err := rest.URLJoin(base, name)
|
2017-06-19 16:36:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", false
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
uStr := u.String()
|
|
|
|
if strings.Index(uStr, "?") >= 0 {
|
|
|
|
return "", false
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
baseStr := base.String()
|
|
|
|
// check has URL prefix
|
|
|
|
if !strings.HasPrefix(uStr, baseStr) {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
// check has path prefix
|
|
|
|
if !strings.HasPrefix(u.Path, base.Path) {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
// calculate the name relative to the base
|
|
|
|
name = u.Path[len(base.Path):]
|
|
|
|
// musn't be empty
|
|
|
|
if name == "" {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
// mustn't contain a /
|
|
|
|
slash := strings.Index(name, "/")
|
|
|
|
if slash >= 0 && slash != len(name)-1 {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
return name, true
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 16:36:14 +00:00
|
|
|
// Parse turns HTML for a directory into names
|
|
|
|
// base should be the base URL to resolve any relative names from
|
|
|
|
func parse(base *url.URL, in io.Reader) (names []string, err error) {
|
|
|
|
doc, err := html.Parse(in)
|
2017-03-17 08:47:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
var walk func(*html.Node)
|
|
|
|
walk = func(n *html.Node) {
|
|
|
|
if n.Type == html.ElementNode && n.Data == "a" {
|
|
|
|
for _, a := range n.Attr {
|
|
|
|
if a.Key == "href" {
|
|
|
|
name, ok := parseName(base, a.Val)
|
|
|
|
if ok {
|
|
|
|
names = append(names, name)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for c := n.FirstChild; c != nil; c = c.NextSibling {
|
|
|
|
walk(c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
walk(doc)
|
|
|
|
return names, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the directory passed in
|
|
|
|
func (f *Fs) readDir(dir string) (names []string, err error) {
|
2017-08-02 12:19:36 +00:00
|
|
|
URL := f.url(dir)
|
|
|
|
u, err := url.Parse(URL)
|
2017-07-30 22:16:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to readDir")
|
|
|
|
}
|
2017-08-02 12:19:36 +00:00
|
|
|
if !strings.HasSuffix(URL, "/") {
|
|
|
|
return nil, errors.Errorf("internal error: readDir URL %q didn't end in /", URL)
|
2017-06-19 16:36:14 +00:00
|
|
|
}
|
2017-08-02 12:19:36 +00:00
|
|
|
res, err := f.httpClient.Get(URL)
|
2017-06-19 16:36:14 +00:00
|
|
|
if err == nil && res.StatusCode == http.StatusNotFound {
|
|
|
|
return nil, fs.ErrorDirNotFound
|
|
|
|
}
|
|
|
|
err = statusError(res, err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to readDir")
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
2017-04-22 10:48:32 +00:00
|
|
|
defer fs.CheckClose(res.Body, &err)
|
2017-03-17 08:47:23 +00:00
|
|
|
|
2017-06-19 16:36:14 +00:00
|
|
|
contentType := strings.SplitN(res.Header.Get("Content-Type"), ";", 2)[0]
|
|
|
|
switch contentType {
|
2017-03-17 08:47:23 +00:00
|
|
|
case "text/html":
|
2017-06-19 16:36:14 +00:00
|
|
|
names, err = parse(u, res.Body)
|
2017-03-17 08:47:23 +00:00
|
|
|
if err != nil {
|
2017-06-19 16:36:14 +00:00
|
|
|
return nil, errors.Wrap(err, "readDir")
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
default:
|
|
|
|
return nil, errors.Errorf("Can't parse content type %q", contentType)
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
return names, nil
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 14:05:09 +00:00
|
|
|
// List the objects and directories in dir into entries. The
|
|
|
|
// entries can be returned in any order but should be for a
|
|
|
|
// complete directory.
|
|
|
|
//
|
|
|
|
// dir should be "" to list the root, and should not have
|
|
|
|
// trailing slashes.
|
|
|
|
//
|
|
|
|
// This should return ErrDirNotFound if the directory isn't
|
|
|
|
// found.
|
|
|
|
func (f *Fs) List(dir string) (entries fs.DirEntries, err error) {
|
2017-06-19 16:36:14 +00:00
|
|
|
if !strings.HasSuffix(dir, "/") && dir != "" {
|
|
|
|
dir += "/"
|
2017-06-19 14:05:09 +00:00
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
names, err := f.readDir(dir)
|
2017-03-17 08:47:23 +00:00
|
|
|
if err != nil {
|
2017-06-19 14:05:09 +00:00
|
|
|
return nil, errors.Wrapf(err, "error listing %q", dir)
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
for _, name := range names {
|
|
|
|
isDir := name[len(name)-1] == '/'
|
|
|
|
name = strings.TrimRight(name, "/")
|
|
|
|
remote := path.Join(dir, name)
|
|
|
|
if isDir {
|
2017-06-30 12:37:29 +00:00
|
|
|
dir := fs.NewDir(remote, timeUnset)
|
2017-06-19 14:05:09 +00:00
|
|
|
entries = append(entries, dir)
|
2017-03-17 08:47:23 +00:00
|
|
|
} else {
|
|
|
|
file := &Object{
|
|
|
|
fs: f,
|
|
|
|
remote: remote,
|
|
|
|
}
|
|
|
|
if err = file.stat(); err != nil {
|
2017-08-02 12:19:36 +00:00
|
|
|
fs.Debugf(remote, "skipping because of error: %v", err)
|
2017-03-17 08:47:23 +00:00
|
|
|
continue
|
|
|
|
}
|
2017-06-19 14:05:09 +00:00
|
|
|
entries = append(entries, file)
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-19 14:05:09 +00:00
|
|
|
return entries, nil
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 14:05:09 +00:00
|
|
|
// Put in to the remote path with the modTime given of the given size
|
|
|
|
//
|
|
|
|
// May create the object even if it returns an error - if so
|
|
|
|
// will return the object and the error, otherwise will return
|
|
|
|
// nil and the error
|
|
|
|
func (f *Fs) Put(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error) {
|
|
|
|
return nil, errorReadOnly
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
2017-08-19 10:42:31 +00:00
|
|
|
// PutStream uploads to the remote path with the modTime given of indeterminate size
|
|
|
|
func (f *Fs) PutStream(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error) {
|
|
|
|
return nil, errorReadOnly
|
|
|
|
}
|
|
|
|
|
2017-03-17 08:47:23 +00:00
|
|
|
// Fs is the filesystem this remote http file object is located within
|
|
|
|
func (o *Object) Fs() fs.Info {
|
|
|
|
return o.fs
|
|
|
|
}
|
|
|
|
|
2017-04-22 10:48:32 +00:00
|
|
|
// String returns the URL to the remote HTTP file
|
2017-03-17 08:47:23 +00:00
|
|
|
func (o *Object) String() string {
|
|
|
|
if o == nil {
|
|
|
|
return "<nil>"
|
|
|
|
}
|
|
|
|
return o.remote
|
|
|
|
}
|
|
|
|
|
2017-04-22 10:48:32 +00:00
|
|
|
// Remote the name of the remote HTTP file, relative to the fs root
|
2017-03-17 08:47:23 +00:00
|
|
|
func (o *Object) Remote() string {
|
|
|
|
return o.remote
|
|
|
|
}
|
|
|
|
|
2017-04-22 10:48:32 +00:00
|
|
|
// Hash returns "" since HTTP (in Go or OpenSSH) doesn't support remote calculation of hashes
|
2018-01-12 16:30:54 +00:00
|
|
|
func (o *Object) Hash(r hash.Type) (string, error) {
|
2018-01-18 20:27:52 +00:00
|
|
|
return "", hash.ErrUnsupported
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Size returns the size in bytes of the remote http file
|
|
|
|
func (o *Object) Size() int64 {
|
2017-06-19 16:36:14 +00:00
|
|
|
return o.size
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ModTime returns the modification time of the remote http file
|
|
|
|
func (o *Object) ModTime() time.Time {
|
2017-06-19 16:36:14 +00:00
|
|
|
return o.modTime
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 12:19:36 +00:00
|
|
|
// url returns the native url of the object
|
|
|
|
func (o *Object) url() string {
|
|
|
|
return o.fs.url(o.remote)
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// stat updates the info field in the Object
|
|
|
|
func (o *Object) stat() error {
|
2017-08-02 12:19:36 +00:00
|
|
|
url := o.url()
|
|
|
|
res, err := o.fs.httpClient.Head(url)
|
2017-06-19 16:36:14 +00:00
|
|
|
err = statusError(res, err)
|
2017-03-17 08:47:23 +00:00
|
|
|
if err != nil {
|
2017-06-19 16:36:14 +00:00
|
|
|
return errors.Wrap(err, "failed to stat")
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
t, err := http.ParseTime(res.Header.Get("Last-Modified"))
|
|
|
|
if err != nil {
|
2017-06-19 16:36:14 +00:00
|
|
|
t = timeUnset
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
o.size = parseInt64(res.Header.Get("Content-Length"))
|
|
|
|
o.modTime = t
|
|
|
|
o.contentType = res.Header.Get("Content-Type")
|
2017-03-17 08:47:23 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetModTime sets the modification and access time to the specified time
|
|
|
|
//
|
|
|
|
// it also updates the info field
|
|
|
|
func (o *Object) SetModTime(modTime time.Time) error {
|
2017-06-19 14:05:09 +00:00
|
|
|
return errorReadOnly
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Storable returns whether the remote http file is a regular file (not a directory, symbolic link, block device, character device, named pipe, etc)
|
|
|
|
func (o *Object) Storable() bool {
|
2017-06-19 16:36:14 +00:00
|
|
|
return true
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Open a remote http file object for reading. Seek is supported
|
|
|
|
func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) {
|
2017-08-02 12:19:36 +00:00
|
|
|
url := o.url()
|
|
|
|
req, err := http.NewRequest("GET", url, nil)
|
2017-03-17 08:47:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Open failed")
|
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
|
|
|
|
// Add optional headers
|
|
|
|
for k, v := range fs.OpenOptionHeaders(options) {
|
|
|
|
req.Header.Add(k, v)
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
|
|
|
|
// Do the request
|
2017-03-17 08:47:23 +00:00
|
|
|
res, err := o.fs.httpClient.Do(req)
|
2017-06-19 16:36:14 +00:00
|
|
|
err = statusError(res, err)
|
2017-03-17 08:47:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Open failed")
|
|
|
|
}
|
2017-06-19 16:36:14 +00:00
|
|
|
return res.Body, nil
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 16:30:54 +00:00
|
|
|
// Hashes returns hash.HashNone to indicate remote hashing is unavailable
|
|
|
|
func (f *Fs) Hashes() hash.Set {
|
2018-01-18 20:27:52 +00:00
|
|
|
return hash.Set(hash.None)
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mkdir makes the root directory of the Fs object
|
|
|
|
func (f *Fs) Mkdir(dir string) error {
|
2017-06-19 14:05:09 +00:00
|
|
|
return errorReadOnly
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove a remote http file object
|
|
|
|
func (o *Object) Remove() error {
|
2017-06-19 14:05:09 +00:00
|
|
|
return errorReadOnly
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rmdir removes the root directory of the Fs object
|
|
|
|
func (f *Fs) Rmdir(dir string) error {
|
2017-06-19 14:05:09 +00:00
|
|
|
return errorReadOnly
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 14:05:09 +00:00
|
|
|
// Update in to the object with the modTime given of the given size
|
|
|
|
func (o *Object) Update(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error {
|
|
|
|
return errorReadOnly
|
2017-03-17 08:47:23 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 16:36:14 +00:00
|
|
|
// MimeType of an Object if known, "" otherwise
|
|
|
|
func (o *Object) MimeType() string {
|
|
|
|
return o.contentType
|
|
|
|
}
|
|
|
|
|
2017-03-17 08:47:23 +00:00
|
|
|
// Check the interfaces are satisfied
|
|
|
|
var (
|
2017-08-19 10:42:31 +00:00
|
|
|
_ fs.Fs = &Fs{}
|
|
|
|
_ fs.PutStreamer = &Fs{}
|
|
|
|
_ fs.Object = &Object{}
|
|
|
|
_ fs.MimeTyper = &Object{}
|
2017-03-17 08:47:23 +00:00
|
|
|
)
|