1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

Fix HTTP serialization

This commit is contained in:
Darien Raymond 2016-11-07 10:47:30 +01:00
parent 3d2431d21c
commit b0d009664a
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 25 additions and 2 deletions

View File

@ -138,7 +138,7 @@ type HttpAuthenticator struct {
}
func (this HttpAuthenticator) GetClientWriter() *HeaderWriter {
header := alloc.NewLocalBuffer(2048)
header := alloc.NewLocalBuffer(2048).Clear()
config := this.config.Request
header.AppendString(config.Method.GetValue()).AppendString(" ").AppendString(config.PickUri()).AppendString(" ").AppendString(config.GetFullVersion()).AppendString(CRLF)
@ -153,7 +153,7 @@ func (this HttpAuthenticator) GetClientWriter() *HeaderWriter {
}
func (this HttpAuthenticator) GetServerWriter() *HeaderWriter {
header := alloc.NewLocalBuffer(2048)
header := alloc.NewLocalBuffer(2048).Clear()
config := this.config.Response
header.AppendString(config.GetFullVersion()).AppendString(" ").AppendString(config.Status.GetCode()).AppendString(" ").AppendString(config.Status.GetReason()).AppendString(CRLF)

View File

@ -21,3 +21,26 @@ func TestReaderWriter(t *testing.T) {
assert.Error(err).IsNil()
assert.Bytes(buffer.Value).Equals([]byte{'e', 'f', 'g'})
}
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)
cache := alloc.NewBuffer().Clear()
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")
}