diff --git a/Makefile b/Makefile index 6b265dd55369aff73fafaad3906305c4694d4e4a..43e8449851b85c53adbee6bdcc7d125a736349d9 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ dist/go-httpbin: assets cmd/go-httpbin/*.go httpbin/*.go go build -o dist/go-httpbin ./cmd/go-httpbin assets: httpbin/assets/* - go-bindata -o httpbin/assets.go -pkg=httpbin -prefix=httpbin/assets httpbin/assets + go-bindata -o httpbin/assets/assets.go -pkg=assets -prefix=static static test: assets go test ./... diff --git a/httpbin/assets.go b/httpbin/assets/assets.go similarity index 99% rename from httpbin/assets.go rename to httpbin/assets/assets.go index 2fdbf5776bc8274b2914004f5f1a3faae96df885..63cc21e50a34e6e0e62948d9ffc84c5ee4b81e91 100644 --- a/httpbin/assets.go +++ b/httpbin/assets/assets.go @@ -1,17 +1,17 @@ // Code generated by go-bindata. // sources: -// httpbin/assets/forms-post.html -// httpbin/assets/image.jpeg -// httpbin/assets/image.png -// httpbin/assets/image.svg -// httpbin/assets/image.webp -// httpbin/assets/index.html -// httpbin/assets/moby.html -// httpbin/assets/sample.xml -// httpbin/assets/utf8.html +// static/forms-post.html +// static/image.jpeg +// static/image.png +// static/image.svg +// static/image.webp +// static/index.html +// static/moby.html +// static/sample.xml +// static/utf8.html // DO NOT EDIT! -package httpbin +package assets import ( "bytes" @@ -309,14 +309,14 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ "forms-post.html": formsPostHtml, - "image.jpeg": imageJpeg, - "image.png": imagePng, - "image.svg": imageSvg, - "image.webp": imageWebp, - "index.html": indexHtml, - "moby.html": mobyHtml, - "sample.xml": sampleXml, - "utf8.html": utf8Html, + "image.jpeg": imageJpeg, + "image.png": imagePng, + "image.svg": imageSvg, + "image.webp": imageWebp, + "index.html": indexHtml, + "moby.html": mobyHtml, + "sample.xml": sampleXml, + "utf8.html": utf8Html, } // AssetDir returns the file names below a certain @@ -358,16 +358,17 @@ type bintree struct { Func func() (*asset, error) Children map[string]*bintree } + var _bintree = &bintree{nil, map[string]*bintree{ "forms-post.html": &bintree{formsPostHtml, map[string]*bintree{}}, - "image.jpeg": &bintree{imageJpeg, map[string]*bintree{}}, - "image.png": &bintree{imagePng, map[string]*bintree{}}, - "image.svg": &bintree{imageSvg, map[string]*bintree{}}, - "image.webp": &bintree{imageWebp, map[string]*bintree{}}, - "index.html": &bintree{indexHtml, map[string]*bintree{}}, - "moby.html": &bintree{mobyHtml, map[string]*bintree{}}, - "sample.xml": &bintree{sampleXml, map[string]*bintree{}}, - "utf8.html": &bintree{utf8Html, map[string]*bintree{}}, + "image.jpeg": &bintree{imageJpeg, map[string]*bintree{}}, + "image.png": &bintree{imagePng, map[string]*bintree{}}, + "image.svg": &bintree{imageSvg, map[string]*bintree{}}, + "image.webp": &bintree{imageWebp, map[string]*bintree{}}, + "index.html": &bintree{indexHtml, map[string]*bintree{}}, + "moby.html": &bintree{mobyHtml, map[string]*bintree{}}, + "sample.xml": &bintree{sampleXml, map[string]*bintree{}}, + "utf8.html": &bintree{utf8Html, map[string]*bintree{}}, }} // RestoreAsset restores an asset under the given directory @@ -416,4 +417,3 @@ func _filePath(dir, name string) string { cannonicalName := strings.Replace(name, "\\", "/", -1) return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) } - diff --git a/httpbin/handlers.go b/httpbin/handlers.go index d987dbbaf8c84b502094c36898e8f2f480b9e8c4..42faa1c8d5ff67cceddfba73204b7f3fb446391c 100644 --- a/httpbin/handlers.go +++ b/httpbin/handlers.go @@ -12,6 +12,7 @@ import ( "strings" "time" + "github.com/mccutchen/go-httpbin/httpbin/assets" "github.com/mccutchen/go-httpbin/httpbin/digest" ) @@ -29,17 +30,17 @@ func (h *HTTPBin) Index(w http.ResponseWriter, r *http.Request) { http.Error(w, "Not Found", http.StatusNotFound) return } - writeHTML(w, MustAsset("index.html"), http.StatusOK) + writeHTML(w, assets.MustAsset("index.html"), http.StatusOK) } // FormsPost renders an HTML form that submits a request to the /post endpoint func (h *HTTPBin) FormsPost(w http.ResponseWriter, r *http.Request) { - writeHTML(w, MustAsset("forms-post.html"), http.StatusOK) + writeHTML(w, assets.MustAsset("forms-post.html"), http.StatusOK) } // UTF8 renders an HTML encoding stress test func (h *HTTPBin) UTF8(w http.ResponseWriter, r *http.Request) { - writeHTML(w, MustAsset("utf8.html"), http.StatusOK) + writeHTML(w, assets.MustAsset("utf8.html"), http.StatusOK) } // Get handles HTTP GET requests @@ -568,7 +569,7 @@ func (h *HTTPBin) Range(w http.ResponseWriter, r *http.Request) { // HTML renders a basic HTML page func (h *HTTPBin) HTML(w http.ResponseWriter, r *http.Request) { - writeHTML(w, MustAsset("moby.html"), http.StatusOK) + writeHTML(w, assets.MustAsset("moby.html"), http.StatusOK) } // Robots renders a basic robots.txt file @@ -811,7 +812,7 @@ func (h *HTTPBin) Image(w http.ResponseWriter, r *http.Request) { // doImage responds with a specific kind of image, if there is an image asset // of the given kind. func doImage(w http.ResponseWriter, kind string) { - img, err := Asset("image." + kind) + img, err := assets.Asset("image." + kind) if err != nil { http.Error(w, "Not Found", http.StatusNotFound) } @@ -824,10 +825,11 @@ func doImage(w http.ResponseWriter, kind string) { // XML responds with an XML document func (h *HTTPBin) XML(w http.ResponseWriter, r *http.Request) { - writeResponse(w, http.StatusOK, "application/xml", MustAsset("sample.xml")) + writeResponse(w, http.StatusOK, "application/xml", assets.MustAsset("sample.xml")) } -// DigestAuth blah +// DigestAuth handles a simple implementation of HTTP Digest Authentication, +// which supports the "auth" QOP and the MD5 and SHA-256 crypto algorithms. // // /digest-auth/<qop>/<user>/<passwd> // /digest-auth/<qop>/<user>/<passwd>/<algorithm> diff --git a/httpbin/assets/forms-post.html b/static/forms-post.html similarity index 100% rename from httpbin/assets/forms-post.html rename to static/forms-post.html diff --git a/httpbin/assets/image.jpeg b/static/image.jpeg similarity index 100% rename from httpbin/assets/image.jpeg rename to static/image.jpeg diff --git a/httpbin/assets/image.png b/static/image.png similarity index 100% rename from httpbin/assets/image.png rename to static/image.png diff --git a/httpbin/assets/image.svg b/static/image.svg similarity index 100% rename from httpbin/assets/image.svg rename to static/image.svg diff --git a/httpbin/assets/image.webp b/static/image.webp similarity index 100% rename from httpbin/assets/image.webp rename to static/image.webp diff --git a/httpbin/assets/index.html b/static/index.html similarity index 100% rename from httpbin/assets/index.html rename to static/index.html diff --git a/httpbin/assets/moby.html b/static/moby.html similarity index 100% rename from httpbin/assets/moby.html rename to static/moby.html diff --git a/httpbin/assets/sample.xml b/static/sample.xml similarity index 100% rename from httpbin/assets/sample.xml rename to static/sample.xml diff --git a/httpbin/assets/utf8.html b/static/utf8.html similarity index 100% rename from httpbin/assets/utf8.html rename to static/utf8.html