소스 검색

Fix HTTP serialization

Darien Raymond 9 년 전
부모
커밋
b0d009664a
2개의 변경된 파일25개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      transport/internet/authenticators/http/http.go
  2. 23 0
      transport/internet/authenticators/http/http_test.go

+ 2 - 2
transport/internet/authenticators/http/http.go

@@ -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)
 

+ 23 - 0
transport/internet/authenticators/http/http_test.go

@@ -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")
+}