feat(plugins): add NoFollowRedirects option to HTTPRequest

Allow plugins to opt out of automatic redirect following on a per-request
basis. When set to true, the response returns the redirect status code and
Location header directly instead of following to the final destination.
This commit is contained in:
Deluan
2026-03-20 18:16:07 -04:00
parent 5cd1fcb492
commit 03844a9a36
6 changed files with 54 additions and 15 deletions
+20
View File
@@ -311,6 +311,26 @@ var _ = Describe("httpServiceImpl", func() {
Expect(err.Error()).To(ContainSubstring("context canceled"))
})
It("should not follow redirects when NoFollowRedirects is true", func() {
dest := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("final"))
}))
defer dest.Close()
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, dest.URL, http.StatusFound)
}))
resp, err := svc.Send(context.Background(), host.HTTPRequest{
Method: "GET",
URL: ts.URL,
TimeoutMs: 1000,
NoFollowRedirects: true,
})
Expect(err).ToNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(int32(302)))
Expect(resp.Headers["Location"]).To(Equal(dest.URL))
Expect(string(resp.Body)).ToNot(Equal("final"))
})
It("should send request headers", func() {
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(r.Header.Get("X-Custom")))