Browse Source

go fmt, remove reference to bodyhtml, syntax highlight real-time requests

Alan Shreve 12 years ago
parent
commit
72898512cb

+ 0 - 1
Makefile

@@ -27,7 +27,6 @@ release-all: release-client release-server
 bindata:
 bindata:
 	go get github.com/inconshreveable/go-bindata
 	go get github.com/inconshreveable/go-bindata
 	./bin/go-bindata -b release -i assets/page.html -o src/ngrok/client/views/web/static/page.html.go -m -p static -f PageHtml
 	./bin/go-bindata -b release -i assets/page.html -o src/ngrok/client/views/web/static/page.html.go -m -p static -f PageHtml
-	./bin/go-bindata -b release -i assets/body.html -o src/ngrok/client/views/web/static/body.html.go -m -p static -f BodyHtml
 	./bin/go-bindata -b release -i assets/highlight.min.css -o src/ngrok/client/views/web/static/highlight.css.go -m -p static -f HighlightCss
 	./bin/go-bindata -b release -i assets/highlight.min.css -o src/ngrok/client/views/web/static/highlight.css.go -m -p static -f HighlightCss
 	./bin/go-bindata -b release -i assets/highlight.min.js -o src/ngrok/client/views/web/static/highlight.js.go -m -p static -f HighlightJs
 	./bin/go-bindata -b release -i assets/highlight.min.js -o src/ngrok/client/views/web/static/highlight.js.go -m -p static -f HighlightJs
 	./bin/go-bindata -b release -i assets/bootstrap.min.css -o src/ngrok/client/views/web/static/bootstrap.css.go -m -p static -f BootstrapCss
 	./bin/go-bindata -b release -i assets/bootstrap.min.css -o src/ngrok/client/views/web/static/bootstrap.css.go -m -p static -f BootstrapCss

+ 38 - 1
assets/ngrok.js

@@ -54,7 +54,7 @@ ngrok.directive({
         };
         };
     },
     },
 
 
-    "body": function() {
+    "body": function($timeout) {
         return {
         return {
             scope: {
             scope: {
                 "body": "="
                 "body": "="
@@ -104,6 +104,43 @@ ngrok.directive({
                 }
                 }
 
 
                 $scope.Body = body;
                 $scope.Body = body;
+            },
+
+            link: function($scope, $elem) {
+                $timeout(function() {
+                    $code = $elem.find("code").get(0);
+                    hljs.highlightBlock($code);
+
+                    if ($scope.Body.ErrorOffset > -1) {
+                        var offset = $scope.Body.ErrorOffset;
+
+                        function textNodes(node) {
+                            var textNodes = [];
+
+                            function getTextNodes(node) {
+                                if (node.nodeType == 3) {
+                                    textNodes.push(node);
+                                } else {
+                                    for (var i = 0, len = node.childNodes.length; i < len; ++i) {
+                                        getTextNodes(node.childNodes[i]);
+                                    }
+                                }
+                            }
+
+                            getTextNodes(node);
+                            return textNodes;
+                        }
+
+                        var tNodes = textNodes($elem.find("code").get(0));
+                        for (var i=0; i<tNodes.length; i++) {
+                            offset -= tNodes[i].nodeValue.length;
+                            if (offset < 0) {
+                                $(tNodes[i]).parent().css("background-color", "orange");
+                                break;
+                            }
+                        }
+                    }
+                });
             }
             }
         };
         };
     }
     }

+ 1 - 1
assets/page.html

@@ -15,7 +15,7 @@
         <style type="text/css">
         <style type="text/css">
             body { margin-top: 50px; }
             body { margin-top: 50px; }
             ul.history > li { none; margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid #ccc; }
             ul.history > li { none; margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid #ccc; }
-            table.params { font-family: Courier, monospace; }
+            table.params { font-size: 12px; font-family: Courier, monospace; }
         </style>
         </style>
     </head>
     </head>
 
 

+ 59 - 74
src/ngrok/client/views/web/http.go

@@ -30,7 +30,7 @@ type SerializedBody struct {
 	Length         int
 	Length         int
 	Error          string
 	Error          string
 	ErrorOffset    int
 	ErrorOffset    int
-        Form   url.Values
+	Form           url.Values
 }
 }
 
 
 type SerializedRequest struct {
 type SerializedRequest struct {
@@ -125,68 +125,65 @@ func (whv *WebHttpView) update() {
 	// open channels for incoming http state changes
 	// open channels for incoming http state changes
 	// and broadbasts
 	// and broadbasts
 	txnUpdates := whv.httpProto.Txns.Reg()
 	txnUpdates := whv.httpProto.Txns.Reg()
-	for {
-		select {
-		case txn := <-txnUpdates:
-			// XXX: it's not safe for proto.Http and this code
-			// to be accessing txn and txn.(req/resp) without synchronization
-			htxn := txn.(*proto.HttpTxn)
-
-                        // we haven't processed this transaction yet if we haven't set the
-                        // user data
-			if htxn.UserData == nil {
-				id, err := util.RandId(8)
-				if err != nil {
-					log.Error("Failed to generate txn identifier for web storage: %v", err)
-					continue
-				}
-
-				rawReq, err := httputil.DumpRequestOut(htxn.Req.Request, true)
-				if err != nil {
-					log.Error("Failed to dump request: %v", err)
-					continue
-				}
-
-				body := makeBody(htxn.Req.Header, htxn.Req.BodyBytes)
-				whtxn := &SerializedTxn{
-					Id:      id,
-					HttpTxn: htxn,
-					Req: SerializedRequest{
-						MethodPath: htxn.Req.Method + " " + htxn.Req.URL.Path,
-						Raw:        string(rawReq),
-						Params:     htxn.Req.URL.Query(),
-						Header:     htxn.Req.Header,
-						Body:       body,
-					},
-				}
-
-				htxn.UserData = whtxn
-				// XXX: unsafe map access from multiple go routines
-				whv.idToTxn[whtxn.Id] = whtxn
-				// XXX: use return value to delete from map so we don't leak memory
-				whv.HttpRequests.Add(whtxn)
-                        } else {
-				rawResp, err := httputil.DumpResponse(htxn.Resp.Response, true)
-				if err != nil {
-					log.Error("Failed to dump response: %v", err)
-					continue
-				}
-
-				txn := htxn.UserData.(*SerializedTxn)
-				body := makeBody(htxn.Resp.Header, htxn.Resp.BodyBytes)
-				txn.Resp = SerializedResponse{
-					Status: htxn.Resp.Status,
-					Raw:    string(rawResp),
-					Header: htxn.Resp.Header,
-					Body:   body,
-				}
-
-				payload, err := json.Marshal(txn)
-				if err != nil {
-					log.Error("Failed to serialized txn payload for websocket: %v", err)
-				}
-				whv.webview.wsMessages.In() <- payload
+	for txn := range txnUpdates {
+		// XXX: it's not safe for proto.Http and this code
+		// to be accessing txn and txn.(req/resp) without synchronization
+		htxn := txn.(*proto.HttpTxn)
+
+		// we haven't processed this transaction yet if we haven't set the
+		// user data
+		if htxn.UserData == nil {
+			id, err := util.RandId(8)
+			if err != nil {
+				log.Error("Failed to generate txn identifier for web storage: %v", err)
+				continue
+			}
+
+			rawReq, err := httputil.DumpRequestOut(htxn.Req.Request, true)
+			if err != nil {
+				log.Error("Failed to dump request: %v", err)
+				continue
+			}
+
+			body := makeBody(htxn.Req.Header, htxn.Req.BodyBytes)
+			whtxn := &SerializedTxn{
+				Id:      id,
+				HttpTxn: htxn,
+				Req: SerializedRequest{
+					MethodPath: htxn.Req.Method + " " + htxn.Req.URL.Path,
+					Raw:        string(rawReq),
+					Params:     htxn.Req.URL.Query(),
+					Header:     htxn.Req.Header,
+					Body:       body,
+				},
 			}
 			}
+
+			htxn.UserData = whtxn
+			// XXX: unsafe map access from multiple go routines
+			whv.idToTxn[whtxn.Id] = whtxn
+			// XXX: use return value to delete from map so we don't leak memory
+			whv.HttpRequests.Add(whtxn)
+		} else {
+			rawResp, err := httputil.DumpResponse(htxn.Resp.Response, true)
+			if err != nil {
+				log.Error("Failed to dump response: %v", err)
+				continue
+			}
+
+			txn := htxn.UserData.(*SerializedTxn)
+			body := makeBody(htxn.Resp.Header, htxn.Resp.BodyBytes)
+			txn.Resp = SerializedResponse{
+				Status: htxn.Resp.Status,
+				Raw:    string(rawResp),
+				Header: htxn.Resp.Header,
+				Body:   body,
+			}
+
+			payload, err := json.Marshal(txn)
+			if err != nil {
+				log.Error("Failed to serialized txn payload for websocket: %v", err)
+			}
+			whv.webview.wsMessages.In() <- payload
 		}
 		}
 	}
 	}
 }
 }
@@ -209,18 +206,6 @@ func (h *WebHttpView) register() {
 	})
 	})
 
 
 	http.HandleFunc("/http/in", func(w http.ResponseWriter, r *http.Request) {
 	http.HandleFunc("/http/in", func(w http.ResponseWriter, r *http.Request) {
-		/*
-			funcMap := template.FuncMap{
-				"handleForm": func(b []byte, h http.Header) (values interface{}, err error) {
-
-					if b != nil {
-						values, err = url.ParseQuery(string(b))
-					}
-					return
-				},
-			}
-		*/
-
 		tmpl := template.Must(template.New("page.html").Delims("{%", "%}").Parse(string(static.PageHtml())))
 		tmpl := template.Must(template.New("page.html").Delims("{%", "%}").Parse(string(static.PageHtml())))
 
 
 		payload, err := json.Marshal(h.HttpRequests.Slice())
 		payload, err := json.Marshal(h.HttpRequests.Slice())

+ 4 - 4
src/ngrok/client/views/web/static/debug.go

@@ -31,13 +31,14 @@ func init() {
 
 
 	// call all the functions on startup to make sure the files exist
 	// call all the functions on startup to make sure the files exist
 	fns := []func() []byte{
 	fns := []func() []byte{
-		BodyHtml,
 		PageHtml,
 		PageHtml,
 		HighlightJs,
 		HighlightJs,
 		HighlightCss,
 		HighlightCss,
 		BootstrapCss,
 		BootstrapCss,
 		JqueryJs,
 		JqueryJs,
 		VkBeautifyJs,
 		VkBeautifyJs,
+		AngularJs,
+		NgrokJs,
 	}
 	}
 	for _, f := range fns {
 	for _, f := range fns {
 		f()
 		f()
@@ -52,12 +53,11 @@ func ReadFileOrPanic(p string) []byte {
 	return bytes
 	return bytes
 }
 }
 
 
-func BodyHtml() []byte     { return ReadFileOrPanic("body.html") }
 func PageHtml() []byte     { return ReadFileOrPanic("page.html") }
 func PageHtml() []byte     { return ReadFileOrPanic("page.html") }
 func HighlightJs() []byte  { return ReadFileOrPanic("highlight.min.js") }
 func HighlightJs() []byte  { return ReadFileOrPanic("highlight.min.js") }
 func HighlightCss() []byte { return ReadFileOrPanic("highlight.min.css") }
 func HighlightCss() []byte { return ReadFileOrPanic("highlight.min.css") }
 func BootstrapCss() []byte { return ReadFileOrPanic("bootstrap.min.css") }
 func BootstrapCss() []byte { return ReadFileOrPanic("bootstrap.min.css") }
 func JqueryJs() []byte     { return ReadFileOrPanic("jquery-1.9.1.min.js") }
 func JqueryJs() []byte     { return ReadFileOrPanic("jquery-1.9.1.min.js") }
 func VkBeautifyJs() []byte { return ReadFileOrPanic("vkbeautify.js") }
 func VkBeautifyJs() []byte { return ReadFileOrPanic("vkbeautify.js") }
-func AngularJs() []byte { return ReadFileOrPanic("angular.js") }
-func NgrokJs() []byte { return ReadFileOrPanic("ngrok.js") }
+func AngularJs() []byte    { return ReadFileOrPanic("angular.js") }
+func NgrokJs() []byte      { return ReadFileOrPanic("ngrok.js") }

+ 2 - 2
src/ngrok/client/views/web/static/map.go

@@ -6,6 +6,6 @@ var AssetMap = map[string]func() []byte{
 	"highlight.min.css":   HighlightCss,
 	"highlight.min.css":   HighlightCss,
 	"highlight.min.js":    HighlightJs,
 	"highlight.min.js":    HighlightJs,
 	"vkbeautify.js":       VkBeautifyJs,
 	"vkbeautify.js":       VkBeautifyJs,
-	"angular.js":       AngularJs,
-	"ngrok.js":       NgrokJs,
+	"angular.js":          AngularJs,
+	"ngrok.js":            NgrokJs,
 }
 }