Add a RequestPath() function #106
-
Hi, I've recently been working with toxiproxy to simulate failures and high latency for upstream systems. In order to make that work, I had to change the var response map[string]Episode
requestBuilder := requests.URL(c.baseURL).
Path("/episodes").
Param("ids", strings.Join(ids, ",")).
Client(c.httpClient).
Headers(c.headers).
ToJSON(&response)
request, err := requestBuilder.Request(timeoutCtx)
if err != nil {
return response, err
}
request.Host = c.host
err = requestBuilder.Do(request) What do you think about adding a E.g: var response map[string]Episode
err := requests.URL(c.baseURL).
Path("/episodes").
Param("ids", strings.Join(ids, ",")).
Headers(c.headers).
ToJSON(&response).
RequestHost(c.host).
Fetch(ctx) I tried using the current Thank you for creating this library it's great! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I think the workaround for now would be to make a custom transport like func WithHost(rt requests.Transport, s string) requests.Transport {
return requests.RoundTripFunc(func(req *http.Request) (res *http.Response, err error) {
rt = cmp.Or(rt, http.DefaultTransport)
req2 := *req
req2.Host = s
return rt.RoundTrip(&req2)
})
} |
Beta Was this translation helpful? Give feedback.
.Host
sets the host on the URL, which in turns gets passed into the Request. Is there a reason you need the host to be only on the request and not the URL? I know there's an option for that in curl, but I've only ever needed it because I was testing whether a server would work even if it got a bad host in.I think the workaround for now would be to make a custom transport like