forked from quic-go/quic-go
add a HTTP integration test that sets and gets request headers
This commit is contained in:
@@ -59,14 +59,33 @@ var _ = Describe("HTTP tests", func() {
|
||||
Expect(string(body)).To(Equal("Hello, World!\n"))
|
||||
})
|
||||
|
||||
It("sets and gets request headers", func() {
|
||||
handlerCalled := make(chan struct{})
|
||||
http.HandleFunc("/headers/request", func(w http.ResponseWriter, r *http.Request) {
|
||||
defer GinkgoRecover()
|
||||
Expect(r.Header.Get("foo")).To(Equal("bar"))
|
||||
Expect(r.Header.Get("lorem")).To(Equal("ipsum"))
|
||||
close(handlerCalled)
|
||||
})
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, "https://localhost:"+testserver.Port()+"/headers/request", nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
req.Header.Set("foo", "bar")
|
||||
req.Header.Set("lorem", "ipsum")
|
||||
resp, err := client.Do(req)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(resp.StatusCode).To(Equal(200))
|
||||
Eventually(handlerCalled).Should(BeClosed())
|
||||
})
|
||||
|
||||
It("sets and gets response headers", func() {
|
||||
http.HandleFunc("/headers", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.HandleFunc("/headers/response", func(w http.ResponseWriter, r *http.Request) {
|
||||
defer GinkgoRecover()
|
||||
w.Header().Set("foo", "bar")
|
||||
w.Header().Set("lorem", "ipsum")
|
||||
})
|
||||
|
||||
resp, err := client.Get("https://localhost:" + testserver.Port() + "/headers")
|
||||
resp, err := client.Get("https://localhost:" + testserver.Port() + "/headers/response")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(resp.StatusCode).To(Equal(200))
|
||||
Expect(resp.Header.Get("foo")).To(Equal("bar"))
|
||||
|
||||
Reference in New Issue
Block a user