Browse Source

compile all static assets into the binary so they aren't loaded from the internets. add a fix so that the TeeConn shuts down its pipe correctly so that we terminate handling responses when handling HTTP/1.0 responses with no content-length set

Alan Shreve 12 years ago
parent
commit
28cb7fb47f

+ 2 - 0
.gitignore

@@ -4,3 +4,5 @@ pkg/
 src/code.google.com
 src/code.google.com
 src/github.com
 src/github.com
 src/ngrok/client/views/web/static/*.html.go
 src/ngrok/client/views/web/static/*.html.go
+src/ngrok/client/views/web/static/*.css.go
+src/ngrok/client/views/web/static/*.js.go

+ 6 - 3
Makefile

@@ -22,10 +22,13 @@ release-server: server
 release-all: release-client release-server
 release-all: release-client release-server
 
 
 bindata:
 bindata:
-	echo $$GOPATH
 	go get github.com/inconshreveable/go-bindata
 	go get github.com/inconshreveable/go-bindata
-	./bin/go-bindata -b release -i templates/page.html -o src/ngrok/client/views/web/static/page.html.go -m -p static -f PageHtml
-	./bin/go-bindata -b release -i templates/body.html -o src/ngrok/client/views/web/static/body.html.go -m -p static -f BodyHtml
+	./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.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/jquery-1.9.1.min.js -o src/ngrok/client/views/web/static/jquery-1.9.1.js.go -m -p static -f JqueryJs
 
 
 all: client server
 all: client server
 
 

+ 0 - 0
templates/body.html → assets/body.html


File diff suppressed because it is too large
+ 872 - 0
assets/bootstrap.min.css


+ 1 - 0
assets/highlight.min.css

@@ -0,0 +1 @@
+pre code{display:block;padding:.5em;background:#f0f0f0}pre code,pre .subst,pre .tag .title,pre .lisp .title,pre .clojure .built_in,pre .nginx .title{color:black}pre .string,pre .title,pre .constant,pre .parent,pre .tag .value,pre .rules .value,pre .rules .value .number,pre .preprocessor,pre .ruby .symbol,pre .ruby .symbol .string,pre .aggregate,pre .template_tag,pre .django .variable,pre .smalltalk .class,pre .addition,pre .flow,pre .stream,pre .bash .variable,pre .apache .tag,pre .apache .cbracket,pre .tex .command,pre .tex .special,pre .erlang_repl .function_or_atom,pre .markdown .header{color:#800}pre .comment,pre .annotation,pre .template_comment,pre .diff .header,pre .chunk,pre .markdown .blockquote{color:#888}pre .number,pre .date,pre .regexp,pre .literal,pre .smalltalk .symbol,pre .smalltalk .char,pre .go .constant,pre .change,pre .markdown .bullet,pre .markdown .link_url{color:#080}pre .label,pre .javadoc,pre .ruby .string,pre .decorator,pre .filter .argument,pre .localvars,pre .array,pre .attr_selector,pre .important,pre .pseudo,pre .pi,pre .doctype,pre .deletion,pre .envvar,pre .shebang,pre .apache .sqbracket,pre .nginx .built_in,pre .tex .formula,pre .erlang_repl .reserved,pre .prompt,pre .markdown .link_label,pre .vhdl .attribute,pre .clojure .attribute,pre .coffeescript .property{color:#88F}pre .keyword,pre .id,pre .phpdoc,pre .title,pre .built_in,pre .aggregate,pre .css .tag,pre .javadoctag,pre .phpdoc,pre .yardoctag,pre .smalltalk .class,pre .winutils,pre .bash .variable,pre .apache .tag,pre .go .typename,pre .tex .command,pre .markdown .strong,pre .request,pre .status{font-weight:bold}pre .markdown .emphasis{font-style:italic}pre .nginx .built_in{font-weight:normal}pre .coffeescript .javascript,pre .javascript .xml,pre .tex .formula,pre .xml .javascript,pre .xml .vbscript,pre .xml .css,pre .xml .cdata{opacity:.5}

File diff suppressed because it is too large
+ 0 - 0
assets/highlight.min.js


File diff suppressed because it is too large
+ 2 - 0
assets/jquery-1.9.1.min.js


+ 4 - 4
templates/page.html → assets/page.html

@@ -1,10 +1,10 @@
 <html>
 <html>
     <head>
     <head>
         <title>ngrok</title>
         <title>ngrok</title>
-        <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
-        <link rel="stylesheet" href="http://yandex.st/highlightjs/7.3/styles/default.min.css">
-        <script src="http://yandex.st/highlightjs/7.3/highlight.min.js"></script>
-        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
+        <link href="/static/bootstrap.min.css" rel="stylesheet">
+        <link href="/static/highlight.min.css" rel="stylesheet">
+        <script src="/static/highlight.min.js"></script>
+        <script src="/static/jquery-1.9.1.min.js"></script>
         <script>hljs.initHighlightingOnLoad();</script>
         <script>hljs.initHighlightingOnLoad();</script>
         <script type="text/javascript">
         <script type="text/javascript">
             $(function() {
             $(function() {

+ 4 - 4
src/ngrok/client/ui/command.go

@@ -3,11 +3,11 @@ package ui
 type Command interface{}
 type Command interface{}
 
 
 type CmdQuit struct {
 type CmdQuit struct {
-    // display this message after quit
-    Message string
+	// display this message after quit
+	Message string
 }
 }
 
 
 type CmdRequest struct {
 type CmdRequest struct {
-    // the bytes of the request to issue
-    Payload []byte
+	// the bytes of the request to issue
+	Payload []byte
 }
 }

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

@@ -14,5 +14,9 @@ func ReadFileOrPanic(path string) []byte {
 	return bytes
 	return bytes
 }
 }
 
 
-func BodyHtml() []byte { return ReadFileOrPanic("templates/body.html") }
-func PageHtml() []byte { return ReadFileOrPanic("templates/page.html") }
+func BodyHtml() []byte     { return ReadFileOrPanic("assets/body.html") }
+func PageHtml() []byte     { return ReadFileOrPanic("assets/page.html") }
+func HighlightJs() []byte  { return ReadFileOrPanic("assets/highlight.min.js") }
+func HighlightCss() []byte { return ReadFileOrPanic("assets/highlight.min.css") }
+func BootstrapCss() []byte { return ReadFileOrPanic("assets/bootstrap.min.css") }
+func JqueryJs() []byte     { return ReadFileOrPanic("assets/jquery-1.9.1.min.js") }

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

@@ -0,0 +1,8 @@
+package static
+
+var AssetMap = map[string]func() []byte{
+	"jquery-1.9.1.min.js": JqueryJs,
+	"bootstrap.min.css":   BootstrapCss,
+	"highlight.min.css":   HighlightCss,
+	"highlight.min.js":    HighlightJs,
+}

+ 13 - 0
src/ngrok/client/views/web/view.go

@@ -5,7 +5,9 @@ import (
 	"fmt"
 	"fmt"
 	"net/http"
 	"net/http"
 	"ngrok/client/ui"
 	"ngrok/client/ui"
+	"ngrok/client/views/web/static"
 	"ngrok/proto"
 	"ngrok/proto"
+	"strings"
 )
 )
 
 
 type WebView struct{}
 type WebView struct{}
@@ -22,6 +24,17 @@ func NewWebView(ctl *ui.Controller, state ui.State, port int) *WebView {
 		http.Redirect(w, r, "/http/in", 302)
 		http.Redirect(w, r, "/http/in", 302)
 	})
 	})
 
 
+	http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
+		parts := strings.Split(r.URL.Path, "/")
+		name := parts[len(parts)-1]
+		fn, ok := static.AssetMap[name]
+		if !ok {
+			http.NotFound(w, r)
+			return
+		}
+		w.Write(fn())
+	})
+
 	go http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
 	go http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
 	return w
 	return w
 }
 }

+ 6 - 6
src/ngrok/conn/conn.go

@@ -25,8 +25,8 @@ type tcpConn struct {
 }
 }
 
 
 type Listener struct {
 type Listener struct {
-        *net.TCPAddr
-        Conns chan Conn
+	*net.TCPAddr
+	Conns chan Conn
 }
 }
 
 
 func wrapTcpConn(conn net.Conn, typ string) *tcpConn {
 func wrapTcpConn(conn net.Conn, typ string) *tcpConn {
@@ -43,9 +43,9 @@ func Listen(addr *net.TCPAddr, typ string) (l *Listener, err error) {
 	}
 	}
 
 
 	l = &Listener{
 	l = &Listener{
-            TCPAddr: listener.Addr().(*net.TCPAddr),
-            Conns: make(chan Conn),
-        }
+		TCPAddr: listener.Addr().(*net.TCPAddr),
+		Conns:   make(chan Conn),
+	}
 
 
 	go func() {
 	go func() {
 		for {
 		for {
@@ -59,7 +59,7 @@ func Listen(addr *net.TCPAddr, typ string) (l *Listener, err error) {
 			l.Conns <- c
 			l.Conns <- c
 		}
 		}
 	}()
 	}()
-        return
+	return
 }
 }
 
 
 func Wrap(conn net.Conn, typ string) *tcpConn {
 func Wrap(conn net.Conn, typ string) *tcpConn {

+ 15 - 3
src/ngrok/conn/tee.go

@@ -59,13 +59,25 @@ func (c *Tee) WriteBuffer() *bufio.Reader {
 }
 }
 
 
 func (c *Tee) Read(b []byte) (n int, err error) {
 func (c *Tee) Read(b []byte) (n int, err error) {
-	return c.rd.Read(b)
+	n, err = c.rd.Read(b)
+	if err != nil {
+		c.readPipe.wr.Close()
+	}
+	return
 }
 }
 
 
 func (c *Tee) ReadFrom(r io.Reader) (n int64, err error) {
 func (c *Tee) ReadFrom(r io.Reader) (n int64, err error) {
-	return io.Copy(c.wr, r)
+	n, err = io.Copy(c.wr, r)
+	if err != nil {
+		c.writePipe.wr.Close()
+	}
+	return
 }
 }
 
 
 func (c *Tee) Write(b []byte) (n int, err error) {
 func (c *Tee) Write(b []byte) (n int, err error) {
-	return c.wr.Write(b)
+	n, err = c.wr.Write(b)
+	if err != nil {
+		c.writePipe.wr.Close()
+	}
+	return
 }
 }

+ 4 - 4
src/ngrok/server/http.go

@@ -2,8 +2,8 @@ package server
 
 
 import (
 import (
 	log "code.google.com/p/log4go"
 	log "code.google.com/p/log4go"
+	"fmt"
 	"net"
 	"net"
-        "fmt"
 	"ngrok/conn"
 	"ngrok/conn"
 )
 )
 
 
@@ -15,7 +15,7 @@ Content-Length: 23
 Authorization required
 Authorization required
 `
 `
 
 
-        NotFound = `HTTP/1.0 404 Not Found
+	NotFound = `HTTP/1.0 404 Not Found
 Content-Length: %d
 Content-Length: %d
 
 
 Tunnel %s not found
 Tunnel %s not found
@@ -27,7 +27,7 @@ Tunnel %s not found
  */
  */
 func httpListener(addr *net.TCPAddr) {
 func httpListener(addr *net.TCPAddr) {
 	// bind/listen for incoming connections
 	// bind/listen for incoming connections
-        listener, err := conn.Listen(addr, "pub")
+	listener, err := conn.Listen(addr, "pub")
 	if err != nil {
 	if err != nil {
 		panic(err)
 		panic(err)
 	}
 	}
@@ -64,7 +64,7 @@ func httpHandler(tcpConn net.Conn) {
 	tunnel := tunnels.Get("http://" + req.Host)
 	tunnel := tunnels.Get("http://" + req.Host)
 	if tunnel == nil {
 	if tunnel == nil {
 		conn.Info("No tunnel found for hostname %s", req.Host)
 		conn.Info("No tunnel found for hostname %s", req.Host)
-                conn.Write([]byte(fmt.Sprintf(NotFound, len(req.Host) + 18, req.Host)))
+		conn.Write([]byte(fmt.Sprintf(NotFound, len(req.Host)+18, req.Host)))
 		return
 		return
 	}
 	}
 
 

Some files were not shown because too many files changed in this diff