diff --git a/transport/internet/authenticators/http/http.go b/transport/internet/authenticators/http/http.go index 767a7215..07cfae00 100644 --- a/transport/internet/authenticators/http/http.go +++ b/transport/internet/authenticators/http/http.go @@ -41,6 +41,12 @@ type HeaderWriter struct { header *alloc.Buffer } +func NewHeaderWriter(header *alloc.Buffer) *HeaderWriter { + return &HeaderWriter{ + header: header, + } +} + func (this *HeaderWriter) Write(writer io.Writer) error { if this.header == nil { return nil diff --git a/transport/internet/authenticators/http/http_test.go b/transport/internet/authenticators/http/http_test.go new file mode 100644 index 00000000..021c0e36 --- /dev/null +++ b/transport/internet/authenticators/http/http_test.go @@ -0,0 +1,23 @@ +package http_test + +import ( + "testing" + + "v2ray.com/core/common/alloc" + "v2ray.com/core/testing/assert" + . "v2ray.com/core/transport/internet/authenticators/http" +) + +func TestReaderWriter(t *testing.T) { + assert := assert.On(t) + + cache := alloc.NewBuffer() + writer := NewHeaderWriter(alloc.NewLocalBuffer(256).Clear().AppendString("abcd" + ENDING)) + writer.Write(cache) + cache.Write([]byte{'e', 'f', 'g'}) + + reader := &HeaderReader{} + buffer, err := reader.Read(cache) + assert.Error(err).IsNil() + assert.Bytes(buffer.Value).Equals([]byte{'e', 'f', 'g'}) +}