Browse Source

fix introspection and replay to properly include all necessary headers

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

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

@@ -160,7 +160,7 @@ func (whv *WebHttpView) updateHttp() {
 				continue
 			}
 
-			rawReq, err := httputil.DumpRequest(htxn.Req.Request, true)
+			rawReq, err := httputil.DumpRequestOut(htxn.Req.Request, true)
 			if err != nil {
 				log.Error("Failed to dump request: %v", err)
 				continue
@@ -230,11 +230,11 @@ func (h *WebHttpView) register() {
 		r.ParseForm()
 		txnid := r.Form.Get("txnid")
 		if txn, ok := h.idToTxn[txnid]; ok {
-			bodyBytes, err := httputil.DumpRequest(txn.HttpTxn.Req.Request, true)
+			reqBytes, err := base64.StdEncoding.DecodeString(txn.Req.Raw)
 			if err != nil {
 				panic(err)
 			}
-			h.ctl.Cmds <- ui.CmdRequest{Payload: bodyBytes}
+			h.ctl.Cmds <- ui.CmdRequest{Payload: reqBytes}
 			w.Write([]byte(http.StatusText(200)))
 		} else {
 			// XXX: 400

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

@@ -80,6 +80,10 @@ func (h *Http) readRequests(tee *conn.Tee, lastTxn chan *HttpTxn) {
 			tee.Warn("Failed to extract request body: %v", err)
 		}
 
+		// golang's ReadRequest/DumpRequestOut is broken. Fix up the request so it works later
+		req.URL.Scheme = "http"
+		req.URL.Host = req.Host
+
 		txn := &HttpTxn{Start: time.Now()}
 		txn.Req = &HttpRequest{Request: req}
 		txn.Req.BodyBytes, txn.Req.Body, err = extractBody(req.Body)