server_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package http_test
  2. import (
  3. "bufio"
  4. "net/http"
  5. "strings"
  6. "testing"
  7. . "v2ray.com/core/proxy/http"
  8. . "v2ray.com/ext/assert"
  9. _ "v2ray.com/core/transport/internet/tcp"
  10. )
  11. func TestHopByHopHeadersStrip(t *testing.T) {
  12. assert := With(t)
  13. rawRequest := `GET /pkg/net/http/ HTTP/1.1
  14. Host: golang.org
  15. Connection: keep-alive,Foo, Bar
  16. Foo: foo
  17. Bar: bar
  18. Proxy-Connection: keep-alive
  19. Proxy-Authenticate: abc
  20. Accept-Encoding: gzip
  21. Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7
  22. Cache-Control: no-cache
  23. Accept-Language: de,en;q=0.7,en-us;q=0.3
  24. `
  25. b := bufio.NewReader(strings.NewReader(rawRequest))
  26. req, err := http.ReadRequest(b)
  27. assert(err, IsNil)
  28. assert(req.Header.Get("Foo"), Equals, "foo")
  29. assert(req.Header.Get("Bar"), Equals, "bar")
  30. assert(req.Header.Get("Connection"), Equals, "keep-alive,Foo, Bar")
  31. assert(req.Header.Get("Proxy-Connection"), Equals, "keep-alive")
  32. assert(req.Header.Get("Proxy-Authenticate"), Equals, "abc")
  33. assert(req.Header.Get("User-Agent"), IsEmpty)
  34. StripHopByHopHeaders(req.Header)
  35. assert(req.Header.Get("Connection"), IsEmpty)
  36. assert(req.Header.Get("Foo"), IsEmpty)
  37. assert(req.Header.Get("Bar"), IsEmpty)
  38. assert(req.Header.Get("Proxy-Connection"), IsEmpty)
  39. assert(req.Header.Get("Proxy-Authenticate"), IsEmpty)
  40. assert(req.Header.Get("User-Agent"), IsEmpty)
  41. }