Browse Source

fix crash when there is no body.

Alan Shreve 10 years ago
parent
commit
d79f119547
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/ngrok/proto/http.go

+ 8 - 2
src/ngrok/proto/http.go

@@ -3,7 +3,6 @@ package proto
 import (
 	"bufio"
 	"bytes"
-	metrics "github.com/rcrowley/go-metrics"
 	"io"
 	"io/ioutil"
 	"net"
@@ -15,6 +14,8 @@ import (
 	"strings"
 	"sync"
 	"time"
+
+	metrics "github.com/rcrowley/go-metrics"
 )
 
 type HttpRequest struct {
@@ -93,7 +94,12 @@ func (h *Http) readRequests(tee *conn.Tee, lastTxn chan *HttpTxn, connCtx interf
 
 		txn := &HttpTxn{Start: time.Now(), ConnUserCtx: connCtx}
 		txn.Req = &HttpRequest{Request: req}
-		txn.Req.BodyBytes, txn.Req.Body, err = extractBody(req.Body)
+		if req.Body != nil {
+			txn.Req.BodyBytes, txn.Req.Body, err = extractBody(req.Body)
+			if err != nil {
+				tee.Warn("Failed to extract request body: %v", err)
+			}
+		}
 
 		lastTxn <- txn
 		h.Txns.In() <- txn