2016-11-04 16:59:19 -04:00
|
|
|
package http_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"v2ray.com/core/common/alloc"
|
2016-12-06 05:03:42 -05:00
|
|
|
"v2ray.com/core/common/serial"
|
2016-11-04 16:59:19 -04:00
|
|
|
"v2ray.com/core/testing/assert"
|
2016-12-08 10:27:41 -05:00
|
|
|
. "v2ray.com/core/transport/internet/headers/http"
|
2016-11-04 16:59:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestReaderWriter(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
2016-12-06 05:03:42 -05:00
|
|
|
cache := alloc.NewBuffer()
|
|
|
|
b := alloc.NewLocalBuffer(256)
|
|
|
|
b.AppendFunc(serial.WriteString("abcd" + ENDING))
|
|
|
|
writer := NewHeaderWriter(b)
|
2016-11-04 16:59:19 -04:00
|
|
|
writer.Write(cache)
|
|
|
|
cache.Write([]byte{'e', 'f', 'g'})
|
|
|
|
|
|
|
|
reader := &HeaderReader{}
|
|
|
|
buffer, err := reader.Read(cache)
|
|
|
|
assert.Error(err).IsNil()
|
2016-12-06 05:03:42 -05:00
|
|
|
assert.Bytes(buffer.Bytes()).Equals([]byte{'e', 'f', 'g'})
|
2016-11-04 16:59:19 -04:00
|
|
|
}
|
2016-11-07 04:47:30 -05:00
|
|
|
|
|
|
|
func TestRequestHeader(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
|
|
|
factory := HttpAuthenticatorFactory{}
|
|
|
|
auth := factory.Create(&Config{
|
|
|
|
Request: &RequestConfig{
|
|
|
|
Uri: []string{"/"},
|
|
|
|
Header: []*Header{
|
|
|
|
{
|
|
|
|
Name: "Test",
|
|
|
|
Value: []string{"Value"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).(HttpAuthenticator)
|
|
|
|
|
2016-12-06 05:03:42 -05:00
|
|
|
cache := alloc.NewBuffer()
|
2016-11-07 04:47:30 -05:00
|
|
|
err := auth.GetClientWriter().Write(cache)
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
|
|
|
|
assert.String(cache.String()).Equals("GET / HTTP/1.1\r\nTest: Value\r\n\r\n")
|
|
|
|
}
|