Closed donirompang closed 3 years ago
I just upgraded to v1.0.16
and I'm seeing the exact same issue. Looking at the diff it seems all calls to req.Header.Set
and req.Header.Get
have been replaced with directly modifying the header map
func (r *Request) MatchHeader(key, value string) *Request {
r.Header[key] = []string{value}. // was r.Header.Set(key, value)
return r
}
Unfortunately that doesn't match with what go is doing:
func (h Header) Set(key, value string) {
textproto.MIMEHeader(h).Set(key, value)
}
The fix for me was to modify my application code to the following, but I'll be rolling back to v1.0.15
.
// v1.0.15
req.Header.Add("content-type", "application/x-www-form-urlencoded")
req.Header.Add("content-length", strconv.Itoa(len(encoded)))
// v1.0.16
req.Header["content-type"] = []string{"application/x-www-form-urlencoded"}
req.Header["content-length"] = []string{strconv.Itoa(len(encoded))}
Yes, it should use the setter method instead. I will fix it asap, but if you can provide a PR, that will be possibly faster. Appreciated!
I have Test Code like this,
I use HeaderPresent to check wheter the header key is present or not. Previously it works fine in v1.0.15, but when I upgrade it to v1.0.16, it is not working. The value of gock.IsDone() is false, which mean the mock is not hit by the httpClient
--- FAIL: TestHitHTTP (0.00s) module_test.go:43: Error Trace: module_test.go:43 Error: Not equal: expected: true actual : false Test: TestHitHTTP FAIL