MCPcopy
hub / github.com/go-task/task / ReadContext

Method ReadContext

taskfile/node_http.go:108–140  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

106}
107
108func (node *HTTPNode) ReadContext(ctx context.Context) ([]byte, error) {
109 url, err := RemoteExists(ctx, *node.url, node.client)
110 if err != nil {
111 return nil, err
112 }
113 req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
114 if err != nil {
115 return nil, errors.TaskfileFetchFailedError{URI: node.Location()}
116 }
117
118 resp, err := node.client.Do(req.WithContext(ctx))
119 if err != nil {
120 if ctx.Err() != nil {
121 return nil, err
122 }
123 return nil, errors.TaskfileFetchFailedError{URI: node.Location()}
124 }
125 defer resp.Body.Close()
126 if resp.StatusCode != http.StatusOK {
127 return nil, errors.TaskfileFetchFailedError{
128 URI: node.Location(),
129 HTTPStatusCode: resp.StatusCode,
130 }
131 }
132
133 // Read the entire response body
134 b, err := io.ReadAll(resp.Body)
135 if err != nil {
136 return nil, err
137 }
138
139 return b, nil
140}
141
142func (node *HTTPNode) ResolveEntrypoint(entrypoint string) (string, error) {
143 ref, err := url.Parse(entrypoint)

Callers 1

ReadMethod · 0.95

Calls 5

LocationMethod · 0.95
RemoteExistsFunction · 0.85
ErrMethod · 0.80
CloseMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected