MCPcopy Create free account
hub / github.com/CPChain/chain / doRequest

Method doRequest

api/rpc/http.go:131–148  ·  view source on GitHub ↗
(ctx context.Context, msg interface{})

Source from the content-addressed store, hash-verified

129}
130
131func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadCloser, error) {
132 body, err := json.Marshal(msg)
133 if err != nil {
134 return nil, err
135 }
136 req := hc.req.WithContext(ctx)
137 req.Body = ioutil.NopCloser(bytes.NewReader(body))
138 req.ContentLength = int64(len(body))
139
140 resp, err := hc.client.Do(req)
141 if err != nil {
142 return nil, err
143 }
144 if resp.StatusCode < 200 || resp.StatusCode >= 300 {
145 return resp.Body, errors.New(resp.Status)
146 }
147 return resp.Body, nil
148}
149
150// httpReadWriteNopCloser wraps a io.Reader and io.Writer with a NOP Close method.
151type httpReadWriteNopCloser struct {

Callers 2

sendHTTPMethod · 0.80
sendBatchHTTPMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected