server_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de-de) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10
  21. Accept-Encoding: gzip
  22. Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7
  23. Cache-Control: no-cache
  24. Accept-Language: de,en;q=0.7,en-us;q=0.3
  25. `
  26. b := bufio.NewReader(strings.NewReader(rawRequest))
  27. req, err := http.ReadRequest(b)
  28. assert(err, IsNil)
  29. assert(req.Header.Get("Foo"), Equals, "foo")
  30. assert(req.Header.Get("Bar"), Equals, "bar")
  31. assert(req.Header.Get("Connection"), Equals, "keep-alive,Foo, Bar")
  32. assert(req.Header.Get("Proxy-Connection"), Equals, "keep-alive")
  33. assert(req.Header.Get("Proxy-Authenticate"), Equals, "abc")
  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. }