fix plain http request. fixes #1066

pull/1086/head
Darien Raymond 7 years ago
parent 3997d13b97
commit 93d095c766
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -104,7 +104,9 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn internet
reader := bufio.NewReaderSize(readerOnly{conn}, buf.Size) reader := bufio.NewReaderSize(readerOnly{conn}, buf.Size)
Start: Start:
conn.SetReadDeadline(time.Now().Add(s.policy().Timeouts.Handshake)) if err := conn.SetReadDeadline(time.Now().Add(s.policy().Timeouts.Handshake)); err != nil {
newError("failed to set read deadline").Base(err).WithContext(ctx).WriteToLog()
}
request, err := http.ReadRequest(reader) request, err := http.ReadRequest(reader)
if err != nil { if err != nil {
@ -123,7 +125,9 @@ Start:
} }
newError("request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]").WithContext(ctx).WriteToLog() newError("request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]").WithContext(ctx).WriteToLog()
conn.SetReadDeadline(time.Time{}) if err := conn.SetReadDeadline(time.Time{}); err != nil {
newError("failed to clear read deadline").Base(err).WithContext(ctx).WriteToLog()
}
defaultPort := net.Port(80) defaultPort := net.Port(80)
if strings.ToLower(request.URL.Scheme) == "https" { if strings.ToLower(request.URL.Scheme) == "https" {
@ -248,10 +252,11 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
return err return err
} }
// Plain HTTP request is not a stream. The request always finishes before response. Hense request has to be closed later.
defer common.Close(link.Writer)
var result error = errWaitAnother var result error = errWaitAnother
requestDone := func() error { requestDone := func() error {
defer common.Close(link.Writer)
request.Header.Set("Connection", "close") request.Header.Set("Connection", "close")
requestWriter := buf.NewBufferedWriter(link.Writer) requestWriter := buf.NewBufferedWriter(link.Writer)

Loading…
Cancel
Save