Feature Request: not following redirects #136
-
Hi! Sometimes, I'd want to be able to "not follow" redirects, such as I'm currently using this workaround, but it's doesn't really feel right: url := e.GET("/secure/").
Expect().
Status(http.StatusOK).
Raw().Request.URL.RequestURI()
assert.Equal(t, "/secure", url, "We are authenticated and trying to access /secure") I'd love to be able to do something like: e.GET("/secure").
NoFollow().
Expect().
Status(http.StatusOK) |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Nevermind, this can be done by changing the Client: &http.Client{
Transport: httpexpect.NewFastBinder(handler),
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
Jar: httpexpect.NewJar(),
}, I followed this Stack Overflow question, but apparently, the answers were outdated. Apologies for the fuss. |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing this. I've also seen that question. Actually, |
Beta Was this translation helpful? Give feedback.
-
I know this is old so apologies, but I do not see how to use the code @EtienneBruines posted within a test. How do I modify the underlying |
Beta Was this translation helpful? Give feedback.
-
@pas256 It's been a while, so I have no idea. But, looking at the source code of one of the tests: https://github.com/gavv/httpexpect/blob/master/e2e_redirect_test.go#L58 func TestE2ERedirectBinderStandard(t *testing.T) {
handler := createRedirectHandler()
testRedirectHandler(WithConfig(Config{
BaseURL: "http://example.com",
Reporter: NewAssertReporter(t),
Client: &http.Client{
Transport: NewBinder(handler),
},
}))
} It seems like you can use |
Beta Was this translation helpful? Give feedback.
-
Yes, you can use WithConfig or WithClient: |
Beta Was this translation helpful? Give feedback.
Nevermind, this can be done by changing the
http.Client
:I followed this Stack Overflow question, but apparently, the answers were outdated.
Apologies for the fuss.