Browse Source

populate req.URL so that it can be safely passed to go 1.1's DumpRequestOut later, fixes https://github.com/inconshreveable/ngrok/issues/3

Alan Shreve 12 years ago
parent
commit
72d9d87bf3
2 changed files with 7 additions and 3 deletions
  1. 0 3
      src/ngrok/client/views/web/http.go
  2. 7 0
      src/ngrok/proto/http.go

+ 0 - 3
src/ngrok/client/views/web/http.go

@@ -62,9 +62,6 @@ func (whv *WebHttpView) update() {
 			// to be accessing txn and txn.(req/resp) without synchronization
 			htxn := txn.(*proto.HttpTxn)
 
-			// XXX: golang, why do I have to do this to make DumpRequestOut work later?
-			htxn.Req.URL.Scheme = "http"
-
 			if htxn.Resp == nil {
 				id, err := util.RandId(8)
 				if err != nil {

+ 7 - 0
src/ngrok/proto/http.go

@@ -7,6 +7,7 @@ import (
 	"io/ioutil"
 	"net/http"
 	"net/http/httputil"
+	"net/url"
 	"ngrok/conn"
 	"ngrok/util"
 	"time"
@@ -78,6 +79,12 @@ func (h *Http) readRequests(tee *conn.Tee, lastTxn chan *HttpTxn) {
 			tee.Warn("Failed to extract request body: %v", err)
 		}
 
+		// net/http's ReadRequest doesn't properly create the req.URL
+		// structure, which is needed to properly DumpRequest() later
+		req.URL, err = url.Parse(req.RequestURI)
+		req.URL.Host = req.Host
+		req.URL.Scheme = "http"
+
 		txn := &HttpTxn{Start: time.Now()}
 		txn.Req = &HttpRequest{Request: req}
 		txn.Req.BodyBytes, txn.Req.Body, err = extractBody(req.Body)