MCPcopy
hub / github.com/rclone/rclone / Open

Method Open

backend/http/http.go:758–781  ·  view source on GitHub ↗

Open a remote http file object for reading. Seek is supported

(ctx context.Context, options ...fs.OpenOption)

Source from the content-addressed store, hash-verified

756
757// Open a remote http file object for reading. Seek is supported
758func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.ReadCloser, err error) {
759 url := o.url()
760 req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
761 if err != nil {
762 return nil, fmt.Errorf("Open failed: %w", err)
763 }
764
765 // Add optional headers
766 for k, v := range fs.OpenOptionHeaders(options) {
767 req.Header.Add(k, v)
768 }
769 o.fs.addHeaders(req)
770
771 // Do the request
772 res, err := o.fs.httpClient.Do(req)
773 err = statusError(res, err)
774 if err != nil {
775 return nil, fmt.Errorf("Open failed: %w", err)
776 }
777 if err = o.decodeMetadata(ctx, res); err != nil {
778 return nil, fmt.Errorf("decodeMetadata failed: %w", err)
779 }
780 return res.Body, nil
781}
782
783// Hashes returns hash.HashNone to indicate remote hashing is unavailable
784func (f *Fs) Hashes() hash.Set {

Callers 1

TestOpenFunction · 0.95

Calls 8

urlMethod · 0.95
decodeMetadataMethod · 0.95
OpenOptionHeadersFunction · 0.92
statusErrorFunction · 0.85
AddMethod · 0.65
DoMethod · 0.65
ErrorfMethod · 0.45
addHeadersMethod · 0.45

Tested by 1

TestOpenFunction · 0.76