Browse Source

Fix: Content-Length needs to be set explicitly

Rod Hynes 8 years ago
parent
commit
d045cec14c
1 changed files with 8 additions and 0 deletions
  1. 8 0
      psiphon/meekConn.go

+ 8 - 0
psiphon/meekConn.go

@@ -690,9 +690,11 @@ func (meek *MeekConn) roundTrip(sendBuffer *bytes.Buffer) (int64, error) {
 
 		var signaller *readCloseSignaller
 		var requestBody io.ReadCloser
+		contentLength := 0
 		if !serverAcknowledgedRequestPayload && sendBuffer != nil {
 			signaller = NewReadCloseSignaller(bytes.NewReader(sendBuffer.Bytes()))
 			requestBody = signaller
+			contentLength = sendBuffer.Len()
 		}
 
 		var request *http.Request
@@ -702,6 +704,12 @@ func (meek *MeekConn) roundTrip(sendBuffer *bytes.Buffer) (int64, error) {
 			return 0, common.ContextError(err)
 		}
 
+		// Content-Length won't be set automatically due to the underlying
+		// type of requestBody.
+		if contentLength > 0 {
+			request.ContentLength = int64(contentLength)
+		}
+
 		// Note: meek.stopRunning() will abort a round trip in flight
 		request = request.WithContext(meek.runContext)