1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 01:53:36 -05:00
v2fly/proxy/http/server_test.go

48 lines
1.3 KiB
Go
Raw Normal View History

2016-02-20 17:27:06 -05:00
package http_test
import (
"bufio"
"net/http"
"strings"
"testing"
2016-02-20 17:27:06 -05:00
2016-08-20 14:55:45 -04:00
. "v2ray.com/core/proxy/http"
2017-10-24 10:15:35 -04:00
. "v2ray.com/ext/assert"
2016-06-14 16:54:08 -04:00
2016-08-20 14:55:45 -04:00
_ "v2ray.com/core/transport/internet/tcp"
)
func TestHopByHopHeadersStrip(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2016-02-20 17:27:06 -05:00
2016-02-03 15:36:52 -05:00
rawRequest := `GET /pkg/net/http/ HTTP/1.1
Host: golang.org
Connection: keep-alive,Foo, Bar
Foo: foo
Bar: bar
Proxy-Connection: keep-alive
Proxy-Authenticate: abc
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
Accept-Encoding: gzip
Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7
Cache-Control: no-cache
Accept-Language: de,en;q=0.7,en-us;q=0.3
`
b := bufio.NewReader(strings.NewReader(rawRequest))
req, err := http.ReadRequest(b)
2017-10-24 10:15:35 -04:00
assert(err, IsNil)
assert(req.Header.Get("Foo"), Equals, "foo")
assert(req.Header.Get("Bar"), Equals, "bar")
assert(req.Header.Get("Connection"), Equals, "keep-alive,Foo, Bar")
assert(req.Header.Get("Proxy-Connection"), Equals, "keep-alive")
assert(req.Header.Get("Proxy-Authenticate"), Equals, "abc")
StripHopByHopHeaders(req.Header)
2017-10-24 10:15:35 -04:00
assert(req.Header.Get("Connection"), IsEmpty)
assert(req.Header.Get("Foo"), IsEmpty)
assert(req.Header.Get("Bar"), IsEmpty)
assert(req.Header.Get("Proxy-Connection"), IsEmpty)
assert(req.Header.Get("Proxy-Authenticate"), IsEmpty)
}