MCPcopy
hub / github.com/grafana/dskit / ToHTTPRequest

Function ToHTTPRequest

httpgrpc/httpgrpc.go:60–70  ·  view source on GitHub ↗

ToHTTPRequest converts httpgrpc.HTTPRequest to http.Request.

(ctx context.Context, r *HTTPRequest)

Source from the content-addressed store, hash-verified

58
59// ToHTTPRequest converts httpgrpc.HTTPRequest to http.Request.
60func ToHTTPRequest(ctx context.Context, r *HTTPRequest) (*http.Request, error) {
61 req, err := http.NewRequest(r.Method, r.Url, nopCloser{Buffer: bytes.NewBuffer(r.Body)})
62 if err != nil {
63 return nil, err
64 }
65 ToHeader(r.Headers, req.Header)
66 req = req.WithContext(ctx)
67 req.RequestURI = r.Url
68 req.ContentLength = int64(len(r.Body))
69 return req, nil
70}
71
72// WriteResponse converts an httpgrpc response to an HTTP one
73func WriteResponse(w http.ResponseWriter, resp *HTTPResponse) error {

Callers 2

HandleMethod · 0.92

Calls 1

ToHeaderFunction · 0.85

Tested by

no test coverage detected