diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json deleted file mode 100644 index 6eef857..0000000 --- a/Godeps/Godeps.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "ImportPath": "github.com/dimiro1/ipe", - "GoVersion": "go1.4.1", - "Deps": [ - { - "ImportPath": "github.com/goji/httpauth", - "Rev": "74459b2b27aa334fc9427c1604ee304c6da57661" - }, - { - "ImportPath": "github.com/golang/glog", - "Rev": "44145f04b68cf362d9c4df2182967c2275eaefed" - }, - { - "ImportPath": "github.com/gorilla/context", - "Rev": "215affda49addc4c8ef7e2534915df2c8c35c6cd" - }, - { - "ImportPath": "github.com/gorilla/mux", - "Rev": "e444e69cbd2e2e3e0749a2f3c717cec491552bbf" - }, - { - "ImportPath": "github.com/gorilla/websocket", - "Rev": "9007e29a7c93fc3dcebbdbf742ce0efaf19e6510" - } - ] -} diff --git a/Godeps/Readme b/Godeps/Readme deleted file mode 100644 index 4cdaa53..0000000 --- a/Godeps/Readme +++ /dev/null @@ -1,5 +0,0 @@ -This directory tree is generated automatically by godep. - -Please do not edit. - -See https://github.com/tools/godep for more information. diff --git a/Godeps/_workspace/.gitignore b/Godeps/_workspace/.gitignore deleted file mode 100644 index f037d68..0000000 --- a/Godeps/_workspace/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/pkg -/bin diff --git a/ipe/app.go b/ipe/app.go index ffe2913..12caf6b 100644 --- a/ipe/app.go +++ b/ipe/app.go @@ -10,7 +10,7 @@ import ( "fmt" "sync" - log "github.com/golang/glog" + log "github.com/dimiro1/ipe/vendor/github.com/golang/glog" ) // An App diff --git a/ipe/auth.go b/ipe/auth.go index 66094e3..a0d2b95 100644 --- a/ipe/auth.go +++ b/ipe/auth.go @@ -10,8 +10,8 @@ import ( "sort" "strings" - log "github.com/golang/glog" - "github.com/gorilla/mux" + log "github.com/dimiro1/ipe/vendor/github.com/golang/glog" + "github.com/dimiro1/ipe/vendor/github.com/gorilla/mux" "github.com/dimiro1/ipe/utils" ) diff --git a/ipe/channel.go b/ipe/channel.go index 0309da9..85c3662 100644 --- a/ipe/channel.go +++ b/ipe/channel.go @@ -11,7 +11,7 @@ import ( "sync" "time" - log "github.com/golang/glog" + log "github.com/dimiro1/ipe/vendor/github.com/golang/glog" ) // A Channel diff --git a/ipe/connection.go b/ipe/connection.go index 01a03b0..d0ef834 100644 --- a/ipe/connection.go +++ b/ipe/connection.go @@ -7,8 +7,8 @@ package ipe import ( "time" - log "github.com/golang/glog" - "github.com/gorilla/websocket" + log "github.com/dimiro1/ipe/vendor/github.com/golang/glog" + "github.com/dimiro1/ipe/vendor/github.com/gorilla/websocket" ) // An User Connection diff --git a/ipe/events.go b/ipe/events.go index 5148820..64df422 100644 --- a/ipe/events.go +++ b/ipe/events.go @@ -7,7 +7,7 @@ package ipe import ( "encoding/json" - log "github.com/golang/glog" + log "github.com/dimiro1/ipe/vendor/github.com/golang/glog" ) // { diff --git a/ipe/extra_handlers.go b/ipe/extra_handlers.go index 4bf1b5c..b3e2ac3 100644 --- a/ipe/extra_handlers.go +++ b/ipe/extra_handlers.go @@ -8,7 +8,7 @@ import ( "fmt" "net/http" - "github.com/gorilla/mux" + "github.com/dimiro1/ipe/vendor/github.com/gorilla/mux" ) // Check if the application is disabled diff --git a/ipe/rest.go b/ipe/rest.go index 80f59e3..359b00d 100644 --- a/ipe/rest.go +++ b/ipe/rest.go @@ -10,8 +10,8 @@ import ( "net/http" "strings" - log "github.com/golang/glog" - "github.com/gorilla/mux" + log "github.com/dimiro1/ipe/vendor/github.com/golang/glog" + "github.com/dimiro1/ipe/vendor/github.com/gorilla/mux" ) // An event consists of a name and data (typically JSON) which may be sent to all subscribers to a particular channel or channels. diff --git a/ipe/router.go b/ipe/router.go index 71d41b3..c240d57 100644 --- a/ipe/router.go +++ b/ipe/router.go @@ -8,8 +8,8 @@ import ( _ "expvar" "net/http" - "github.com/goji/httpauth" - "github.com/gorilla/mux" + "github.com/dimiro1/ipe/vendor/github.com/goji/httpauth" + "github.com/dimiro1/ipe/vendor/github.com/gorilla/mux" ) // NewRouter is a function that returns a new configured Router diff --git a/ipe/webhooks.go b/ipe/webhooks.go index 9cf4fc5..1e8585a 100644 --- a/ipe/webhooks.go +++ b/ipe/webhooks.go @@ -11,7 +11,7 @@ import ( "time" "github.com/dimiro1/ipe/utils" - log "github.com/golang/glog" + log "github.com/dimiro1/ipe/vendor/github.com/golang/glog" ) // A WebHook is sent as a HTTP POST request to the url which you specify. diff --git a/ipe/websockets.go b/ipe/websockets.go index c439654..2b2e63d 100644 --- a/ipe/websockets.go +++ b/ipe/websockets.go @@ -12,9 +12,9 @@ import ( "strconv" "strings" - log "github.com/golang/glog" - "github.com/gorilla/mux" - "github.com/gorilla/websocket" + log "github.com/dimiro1/ipe/vendor/github.com/golang/glog" + "github.com/dimiro1/ipe/vendor/github.com/gorilla/mux" + "github.com/dimiro1/ipe/vendor/github.com/gorilla/websocket" "github.com/dimiro1/ipe/utils" ) diff --git a/main.go b/main.go index 0fc872b..038aed5 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,7 @@ import ( "fmt" "github.com/dimiro1/ipe/ipe" - log "github.com/golang/glog" + log "github.com/dimiro1/ipe/vendor/github.com/golang/glog" ) // Main function, initialze the system diff --git a/Godeps/_workspace/src/github.com/goji/httpauth/.travis.yml b/vendor/github.com/goji/httpauth/.travis.yml similarity index 100% rename from Godeps/_workspace/src/github.com/goji/httpauth/.travis.yml rename to vendor/github.com/goji/httpauth/.travis.yml diff --git a/Godeps/_workspace/src/github.com/goji/httpauth/LICENSE b/vendor/github.com/goji/httpauth/LICENSE similarity index 100% rename from Godeps/_workspace/src/github.com/goji/httpauth/LICENSE rename to vendor/github.com/goji/httpauth/LICENSE diff --git a/Godeps/_workspace/src/github.com/goji/httpauth/README.md b/vendor/github.com/goji/httpauth/README.md similarity index 100% rename from Godeps/_workspace/src/github.com/goji/httpauth/README.md rename to vendor/github.com/goji/httpauth/README.md diff --git a/Godeps/_workspace/src/github.com/goji/httpauth/basic_auth.go b/vendor/github.com/goji/httpauth/basic_auth.go similarity index 100% rename from Godeps/_workspace/src/github.com/goji/httpauth/basic_auth.go rename to vendor/github.com/goji/httpauth/basic_auth.go diff --git a/Godeps/_workspace/src/github.com/goji/httpauth/basic_auth_test.go b/vendor/github.com/goji/httpauth/basic_auth_test.go similarity index 100% rename from Godeps/_workspace/src/github.com/goji/httpauth/basic_auth_test.go rename to vendor/github.com/goji/httpauth/basic_auth_test.go diff --git a/Godeps/_workspace/src/github.com/golang/glog/LICENSE b/vendor/github.com/golang/glog/LICENSE similarity index 100% rename from Godeps/_workspace/src/github.com/golang/glog/LICENSE rename to vendor/github.com/golang/glog/LICENSE diff --git a/Godeps/_workspace/src/github.com/golang/glog/README b/vendor/github.com/golang/glog/README similarity index 100% rename from Godeps/_workspace/src/github.com/golang/glog/README rename to vendor/github.com/golang/glog/README diff --git a/Godeps/_workspace/src/github.com/golang/glog/glog.go b/vendor/github.com/golang/glog/glog.go similarity index 100% rename from Godeps/_workspace/src/github.com/golang/glog/glog.go rename to vendor/github.com/golang/glog/glog.go diff --git a/Godeps/_workspace/src/github.com/golang/glog/glog_file.go b/vendor/github.com/golang/glog/glog_file.go similarity index 100% rename from Godeps/_workspace/src/github.com/golang/glog/glog_file.go rename to vendor/github.com/golang/glog/glog_file.go diff --git a/Godeps/_workspace/src/github.com/golang/glog/glog_test.go b/vendor/github.com/golang/glog/glog_test.go similarity index 100% rename from Godeps/_workspace/src/github.com/golang/glog/glog_test.go rename to vendor/github.com/golang/glog/glog_test.go diff --git a/Godeps/_workspace/src/github.com/gorilla/context/.travis.yml b/vendor/github.com/gorilla/context/.travis.yml similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/context/.travis.yml rename to vendor/github.com/gorilla/context/.travis.yml diff --git a/Godeps/_workspace/src/github.com/gorilla/context/LICENSE b/vendor/github.com/gorilla/context/LICENSE similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/context/LICENSE rename to vendor/github.com/gorilla/context/LICENSE diff --git a/Godeps/_workspace/src/github.com/gorilla/context/README.md b/vendor/github.com/gorilla/context/README.md similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/context/README.md rename to vendor/github.com/gorilla/context/README.md diff --git a/Godeps/_workspace/src/github.com/gorilla/context/context.go b/vendor/github.com/gorilla/context/context.go similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/context/context.go rename to vendor/github.com/gorilla/context/context.go diff --git a/Godeps/_workspace/src/github.com/gorilla/context/context_test.go b/vendor/github.com/gorilla/context/context_test.go similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/context/context_test.go rename to vendor/github.com/gorilla/context/context_test.go diff --git a/Godeps/_workspace/src/github.com/gorilla/context/doc.go b/vendor/github.com/gorilla/context/doc.go similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/context/doc.go rename to vendor/github.com/gorilla/context/doc.go diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/.travis.yml b/vendor/github.com/gorilla/mux/.travis.yml similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/mux/.travis.yml rename to vendor/github.com/gorilla/mux/.travis.yml diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/LICENSE b/vendor/github.com/gorilla/mux/LICENSE old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/mux/LICENSE rename to vendor/github.com/gorilla/mux/LICENSE diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/README.md b/vendor/github.com/gorilla/mux/README.md old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/mux/README.md rename to vendor/github.com/gorilla/mux/README.md diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/bench_test.go b/vendor/github.com/gorilla/mux/bench_test.go old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/mux/bench_test.go rename to vendor/github.com/gorilla/mux/bench_test.go diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/doc.go b/vendor/github.com/gorilla/mux/doc.go old mode 100644 new mode 100755 similarity index 96% rename from Godeps/_workspace/src/github.com/gorilla/mux/doc.go rename to vendor/github.com/gorilla/mux/doc.go index b2deed3..9a5e381 --- a/Godeps/_workspace/src/github.com/gorilla/mux/doc.go +++ b/vendor/github.com/gorilla/mux/doc.go @@ -89,7 +89,7 @@ There are several other matchers that can be added. To match path prefixes: r.MatcherFunc(func(r *http.Request, rm *RouteMatch) bool { return r.ProtoMajor == 0 - }) + }) ...and finally, it is possible to combine several matchers in a single route: @@ -164,8 +164,8 @@ This also works for host variables: // url.String() will be "http://news.domain.com/articles/technology/42" url, err := r.Get("article").URL("subdomain", "news", - "category", "technology", - "id", "42") + "category", "technology", + "id", "42") All variables defined in the route are required, and their values must conform to the corresponding patterns. These requirements guarantee that a @@ -193,7 +193,7 @@ as well: // "http://news.domain.com/articles/technology/42" url, err := r.Get("article").URL("subdomain", "news", - "category", "technology", - "id", "42") + "category", "technology", + "id", "42") */ package mux diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/mux.go b/vendor/github.com/gorilla/mux/mux.go old mode 100644 new mode 100755 similarity index 96% rename from Godeps/_workspace/src/github.com/gorilla/mux/mux.go rename to vendor/github.com/gorilla/mux/mux.go index 5b5f8e7..af31d23 --- a/Godeps/_workspace/src/github.com/gorilla/mux/mux.go +++ b/vendor/github.com/gorilla/mux/mux.go @@ -152,6 +152,13 @@ func (r *Router) getRegexpGroup() *routeRegexpGroup { return nil } +func (r *Router) buildVars(m map[string]string) map[string]string { + if r.parent != nil { + m = r.parent.buildVars(m) + } + return m +} + // ---------------------------------------------------------------------------- // Route factories // ---------------------------------------------------------------------------- @@ -224,6 +231,12 @@ func (r *Router) Schemes(schemes ...string) *Route { return r.NewRoute().Schemes(schemes...) } +// BuildVars registers a new route with a custom function for modifying +// route variables before building a URL. +func (r *Router) BuildVarsFunc(f BuildVarsFunc) *Route { + return r.NewRoute().BuildVarsFunc(f) +} + // ---------------------------------------------------------------------------- // Context // ---------------------------------------------------------------------------- diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/mux_test.go b/vendor/github.com/gorilla/mux/mux_test.go old mode 100644 new mode 100755 similarity index 92% rename from Godeps/_workspace/src/github.com/gorilla/mux/mux_test.go rename to vendor/github.com/gorilla/mux/mux_test.go index e455bce..6b2c1d2 --- a/Godeps/_workspace/src/github.com/gorilla/mux/mux_test.go +++ b/vendor/github.com/gorilla/mux/mux_test.go @@ -135,6 +135,42 @@ func TestHost(t *testing.T) { path: "", shouldMatch: false, }, + { + title: "Path route with single pattern with pipe, match", + route: new(Route).Path("/{category:a|b/c}"), + request: newRequest("GET", "http://localhost/a"), + vars: map[string]string{"category": "a"}, + host: "", + path: "/a", + shouldMatch: true, + }, + { + title: "Path route with single pattern with pipe, match", + route: new(Route).Path("/{category:a|b/c}"), + request: newRequest("GET", "http://localhost/b/c"), + vars: map[string]string{"category": "b/c"}, + host: "", + path: "/b/c", + shouldMatch: true, + }, + { + title: "Path route with multiple patterns with pipe, match", + route: new(Route).Path("/{category:a|b/c}/{product}/{id:[0-9]+}"), + request: newRequest("GET", "http://localhost/a/product_name/1"), + vars: map[string]string{"category": "a", "product": "product_name", "id": "1"}, + host: "", + path: "/a/product_name/1", + shouldMatch: true, + }, + { + title: "Path route with multiple patterns with pipe, match", + route: new(Route).Path("/{category:a|b/c}/{product}/{id:[0-9]+}"), + request: newRequest("GET", "http://localhost/b/c/product_name/1"), + vars: map[string]string{"category": "b/c", "product": "product_name", "id": "1"}, + host: "", + path: "/b/c/product_name/1", + shouldMatch: true, + }, } for _, test := range tests { testRoute(t, test) @@ -593,6 +629,39 @@ func TestMatcherFunc(t *testing.T) { } } +func TestBuildVarsFunc(t *testing.T) { + tests := []routeTest{ + { + title: "BuildVarsFunc set on route", + route: new(Route).Path(`/111/{v1:\d}{v2:.*}`).BuildVarsFunc(func(vars map[string]string) map[string]string { + vars["v1"] = "3" + vars["v2"] = "a" + return vars + }), + request: newRequest("GET", "http://localhost/111/2"), + path: "/111/3a", + shouldMatch: true, + }, + { + title: "BuildVarsFunc set on route and parent route", + route: new(Route).PathPrefix(`/{v1:\d}`).BuildVarsFunc(func(vars map[string]string) map[string]string { + vars["v1"] = "2" + return vars + }).Subrouter().Path(`/{v2:\w}`).BuildVarsFunc(func(vars map[string]string) map[string]string { + vars["v2"] = "b" + return vars + }), + request: newRequest("GET", "http://localhost/1/a"), + path: "/2/b", + shouldMatch: true, + }, + } + + for _, test := range tests { + testRoute(t, test) + } +} + func TestSubRouter(t *testing.T) { subrouter1 := new(Route).Host("{v1:[a-z]+}.google.com").Subrouter() subrouter2 := new(Route).PathPrefix("/foo/{v1}").Subrouter() diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/old_test.go b/vendor/github.com/gorilla/mux/old_test.go old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/mux/old_test.go rename to vendor/github.com/gorilla/mux/old_test.go diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/regexp.go b/vendor/github.com/gorilla/mux/regexp.go old mode 100644 new mode 100755 similarity index 98% rename from Godeps/_workspace/src/github.com/gorilla/mux/regexp.go rename to vendor/github.com/gorilla/mux/regexp.go index a630548..aa30679 --- a/Godeps/_workspace/src/github.com/gorilla/mux/regexp.go +++ b/vendor/github.com/gorilla/mux/regexp.go @@ -150,11 +150,7 @@ func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool { } // url builds a URL part using the given values. -func (r *routeRegexp) url(pairs ...string) (string, error) { - values, err := mapFromPairs(pairs...) - if err != nil { - return "", err - } +func (r *routeRegexp) url(values map[string]string) (string, error) { urlValues := make([]interface{}, len(r.varsN)) for k, v := range r.varsN { value, ok := values[v] diff --git a/Godeps/_workspace/src/github.com/gorilla/mux/route.go b/vendor/github.com/gorilla/mux/route.go old mode 100644 new mode 100755 similarity index 89% rename from Godeps/_workspace/src/github.com/gorilla/mux/route.go rename to vendor/github.com/gorilla/mux/route.go index c310e66..00d2300 --- a/Godeps/_workspace/src/github.com/gorilla/mux/route.go +++ b/vendor/github.com/gorilla/mux/route.go @@ -31,6 +31,8 @@ type Route struct { name string // Error resulted from building a route. err error + + buildVarsFunc BuildVarsFunc } // Match matches the route against the request. @@ -212,7 +214,7 @@ func (r *Route) Headers(pairs ...string) *Route { // Host adds a matcher for the URL host. // It accepts a template with zero or more URL variables enclosed by {}. -// Variables can define an optional regexp pattern to me matched: +// Variables can define an optional regexp pattern to be matched: // // - {name} matches anything until the next dot. // @@ -270,7 +272,7 @@ func (r *Route) Methods(methods ...string) *Route { // Path adds a matcher for the URL path. // It accepts a template with zero or more URL variables enclosed by {}. The // template must start with a "/". -// Variables can define an optional regexp pattern to me matched: +// Variables can define an optional regexp pattern to be matched: // // - {name} matches anything until the next slash. // @@ -321,7 +323,7 @@ func (r *Route) PathPrefix(tpl string) *Route { // // It the value is an empty string, it will match any value if the key is set. // -// Variables can define an optional regexp pattern to me matched: +// Variables can define an optional regexp pattern to be matched: // // - {name} matches anything until the next slash. // @@ -360,6 +362,19 @@ func (r *Route) Schemes(schemes ...string) *Route { return r.addMatcher(schemeMatcher(schemes)) } +// BuildVarsFunc -------------------------------------------------------------- + +// BuildVarsFunc is the function signature used by custom build variable +// functions (which can modify route variables before a route's URL is built). +type BuildVarsFunc func(map[string]string) map[string]string + +// BuildVarsFunc adds a custom function to be used to modify build variables +// before a route's URL is built. +func (r *Route) BuildVarsFunc(f BuildVarsFunc) *Route { + r.buildVarsFunc = f + return r +} + // Subrouter ------------------------------------------------------------------ // Subrouter creates a subrouter for the route. @@ -422,17 +437,20 @@ func (r *Route) URL(pairs ...string) (*url.URL, error) { if r.regexp == nil { return nil, errors.New("mux: route doesn't have a host or path") } + values, err := r.prepareVars(pairs...) + if err != nil { + return nil, err + } var scheme, host, path string - var err error if r.regexp.host != nil { // Set a default scheme. scheme = "http" - if host, err = r.regexp.host.url(pairs...); err != nil { + if host, err = r.regexp.host.url(values); err != nil { return nil, err } } if r.regexp.path != nil { - if path, err = r.regexp.path.url(pairs...); err != nil { + if path, err = r.regexp.path.url(values); err != nil { return nil, err } } @@ -453,7 +471,11 @@ func (r *Route) URLHost(pairs ...string) (*url.URL, error) { if r.regexp == nil || r.regexp.host == nil { return nil, errors.New("mux: route doesn't have a host") } - host, err := r.regexp.host.url(pairs...) + values, err := r.prepareVars(pairs...) + if err != nil { + return nil, err + } + host, err := r.regexp.host.url(values) if err != nil { return nil, err } @@ -473,7 +495,11 @@ func (r *Route) URLPath(pairs ...string) (*url.URL, error) { if r.regexp == nil || r.regexp.path == nil { return nil, errors.New("mux: route doesn't have a path") } - path, err := r.regexp.path.url(pairs...) + values, err := r.prepareVars(pairs...) + if err != nil { + return nil, err + } + path, err := r.regexp.path.url(values) if err != nil { return nil, err } @@ -482,6 +508,26 @@ func (r *Route) URLPath(pairs ...string) (*url.URL, error) { }, nil } +// prepareVars converts the route variable pairs into a map. If the route has a +// BuildVarsFunc, it is invoked. +func (r *Route) prepareVars(pairs ...string) (map[string]string, error) { + m, err := mapFromPairs(pairs...) + if err != nil { + return nil, err + } + return r.buildVars(m), nil +} + +func (r *Route) buildVars(m map[string]string) map[string]string { + if r.parent != nil { + m = r.parent.buildVars(m) + } + if r.buildVarsFunc != nil { + m = r.buildVarsFunc(m) + } + return m +} + // ---------------------------------------------------------------------------- // parentRoute // ---------------------------------------------------------------------------- @@ -490,6 +536,7 @@ func (r *Route) URLPath(pairs ...string) (*url.URL, error) { type parentRoute interface { getNamedRoutes() map[string]*Route getRegexpGroup() *routeRegexpGroup + buildVars(map[string]string) map[string]string } // getNamedRoutes returns the map where named routes are registered. diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/.gitignore b/vendor/github.com/gorilla/websocket/.gitignore similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/.gitignore rename to vendor/github.com/gorilla/websocket/.gitignore diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/.travis.yml b/vendor/github.com/gorilla/websocket/.travis.yml similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/.travis.yml rename to vendor/github.com/gorilla/websocket/.travis.yml diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/AUTHORS b/vendor/github.com/gorilla/websocket/AUTHORS old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/AUTHORS rename to vendor/github.com/gorilla/websocket/AUTHORS diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/LICENSE b/vendor/github.com/gorilla/websocket/LICENSE old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/LICENSE rename to vendor/github.com/gorilla/websocket/LICENSE diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/README.md b/vendor/github.com/gorilla/websocket/README.md old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/README.md rename to vendor/github.com/gorilla/websocket/README.md diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/bench_test.go b/vendor/github.com/gorilla/websocket/bench_test.go old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/bench_test.go rename to vendor/github.com/gorilla/websocket/bench_test.go diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/client.go b/vendor/github.com/gorilla/websocket/client.go old mode 100644 new mode 100755 similarity index 87% rename from Godeps/_workspace/src/github.com/gorilla/websocket/client.go rename to vendor/github.com/gorilla/websocket/client.go index c25d24f..93db8dd --- a/Godeps/_workspace/src/github.com/gorilla/websocket/client.go +++ b/vendor/github.com/gorilla/websocket/client.go @@ -5,8 +5,11 @@ package websocket import ( + "bytes" "crypto/tls" "errors" + "io" + "io/ioutil" "net" "net/http" "net/url" @@ -127,6 +130,11 @@ func parseURL(s string) (*url.URL, error) { u.Opaque = s[i:] } + if strings.Contains(u.Host, "@") { + // WebSocket URIs do not contain user information. + return nil, errMalformedURL + } + return &u, nil } @@ -155,7 +163,8 @@ var DefaultDialer *Dialer // // If the WebSocket handshake fails, ErrBadHandshake is returned along with a // non-nil *http.Response so that callers can handle redirects, authentication, -// etc. +// etcetera. The response body may not contain the entire response and does not +// need to be closed by the application. func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) { u, err := parseURL(urlStr) if err != nil { @@ -224,8 +233,33 @@ func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Re requestHeader = h } + if len(requestHeader["Host"]) > 0 { + // This can be used to supply a Host: header which is different from + // the dial address. + u.Host = requestHeader.Get("Host") + + // Drop "Host" header + h := http.Header{} + for k, v := range requestHeader { + if k == "Host" { + continue + } + h[k] = v + } + requestHeader = h + } + conn, resp, err := NewClient(netConn, u, requestHeader, d.ReadBufferSize, d.WriteBufferSize) + if err != nil { + if err == ErrBadHandshake { + // Before closing the network connection on return from this + // function, slurp up some of the response to aid application + // debugging. + buf := make([]byte, 1024) + n, _ := io.ReadFull(resp.Body, buf) + resp.Body = ioutil.NopCloser(bytes.NewReader(buf[:n])) + } return nil, resp, err } diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/client_server_test.go b/vendor/github.com/gorilla/websocket/client_server_test.go old mode 100644 new mode 100755 similarity index 71% rename from Godeps/_workspace/src/github.com/gorilla/websocket/client_server_test.go rename to vendor/github.com/gorilla/websocket/client_server_test.go index 8c608f6..749ef20 --- a/Godeps/_workspace/src/github.com/gorilla/websocket/client_server_test.go +++ b/vendor/github.com/gorilla/websocket/client_server_test.go @@ -8,11 +8,13 @@ import ( "crypto/tls" "crypto/x509" "io" + "io/ioutil" "net" "net/http" "net/http/httptest" "net/url" "reflect" + "strings" "testing" "time" ) @@ -34,22 +36,22 @@ var cstDialer = Dialer{ type cstHandler struct{ *testing.T } -type Server struct { +type cstServer struct { *httptest.Server URL string } -func newServer(t *testing.T) *Server { - var s Server +func newServer(t *testing.T) *cstServer { + var s cstServer s.Server = httptest.NewServer(cstHandler{t}) - s.URL = "ws" + s.Server.URL[len("http"):] + s.URL = makeWsProto(s.Server.URL) return &s } -func newTLSServer(t *testing.T) *Server { - var s Server +func newTLSServer(t *testing.T) *cstServer { + var s cstServer s.Server = httptest.NewTLSServer(cstHandler{t}) - s.URL = "ws" + s.Server.URL[len("http"):] + s.URL = makeWsProto(s.Server.URL) return &s } @@ -97,6 +99,10 @@ func (t cstHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } +func makeWsProto(s string) string { + return "ws" + strings.TrimPrefix(s, "http") +} + func sendRecv(t *testing.T, ws *Conn) { const message = "Hello World!" if err := ws.SetWriteDeadline(time.Now().Add(time.Second)); err != nil { @@ -157,6 +163,7 @@ func TestDialTLS(t *testing.T) { } func xTestDialTLSBadCert(t *testing.T) { + // This test is deactivated because of noisy logging from the net/http package. s := newTLSServer(t) defer s.Close() @@ -247,3 +254,70 @@ func TestHandshake(t *testing.T) { } sendRecv(t, ws) } + +func TestRespOnBadHandshake(t *testing.T) { + const expectedStatus = http.StatusGone + const expectedBody = "This is the response body." + + s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(expectedStatus) + io.WriteString(w, expectedBody) + })) + defer s.Close() + + ws, resp, err := cstDialer.Dial(makeWsProto(s.URL), nil) + if err == nil { + ws.Close() + t.Fatalf("Dial: nil") + } + + if resp == nil { + t.Fatalf("resp=nil, err=%v", err) + } + + if resp.StatusCode != expectedStatus { + t.Errorf("resp.StatusCode=%d, want %d", resp.StatusCode, expectedStatus) + } + + p, err := ioutil.ReadAll(resp.Body) + if err != nil { + t.Fatalf("ReadFull(resp.Body) returned error %v", err) + } + + if string(p) != expectedBody { + t.Errorf("resp.Body=%s, want %s", p, expectedBody) + } +} + +// If the Host header is specified in `Dial()`, the server must receive it as +// the `Host:` header. +func TestHostHeader(t *testing.T) { + s := newServer(t) + defer s.Close() + + specifiedHost := make(chan string, 1) + origHandler := s.Server.Config.Handler + + // Capture the request Host header. + s.Server.Config.Handler = http.HandlerFunc( + func(w http.ResponseWriter, r *http.Request) { + specifiedHost <- r.Host + origHandler.ServeHTTP(w, r) + }) + + ws, resp, err := cstDialer.Dial(s.URL, http.Header{"Host": {"testhost"}}) + if err != nil { + t.Fatalf("Dial: %v", err) + } + defer ws.Close() + + if resp.StatusCode != http.StatusSwitchingProtocols { + t.Fatalf("resp.StatusCode = %v, want http.StatusSwitchingProtocols", resp.StatusCode) + } + + if gotHost := <-specifiedHost; gotHost != "testhost" { + t.Fatalf("gotHost = %q, want \"testhost\"", gotHost) + } + + sendRecv(t, ws) +} diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/client_test.go b/vendor/github.com/gorilla/websocket/client_test.go old mode 100644 new mode 100755 similarity index 98% rename from Godeps/_workspace/src/github.com/gorilla/websocket/client_test.go rename to vendor/github.com/gorilla/websocket/client_test.go index d2f2ebd..07a9cb4 --- a/Godeps/_workspace/src/github.com/gorilla/websocket/client_test.go +++ b/vendor/github.com/gorilla/websocket/client_test.go @@ -20,6 +20,7 @@ var parseURLTests = []struct { {"wss://example.com/", &url.URL{Scheme: "wss", Host: "example.com", Opaque: "/"}}, {"wss://example.com/a/b", &url.URL{Scheme: "wss", Host: "example.com", Opaque: "/a/b"}}, {"ss://example.com/a/b", nil}, + {"ws://webmaster@example.com/", nil}, } func TestParseURL(t *testing.T) { diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/conn.go b/vendor/github.com/gorilla/websocket/conn.go old mode 100644 new mode 100755 similarity index 99% rename from Godeps/_workspace/src/github.com/gorilla/websocket/conn.go rename to vendor/github.com/gorilla/websocket/conn.go index 86c35e5..e719f1c --- a/Godeps/_workspace/src/github.com/gorilla/websocket/conn.go +++ b/vendor/github.com/gorilla/websocket/conn.go @@ -801,7 +801,7 @@ func (c *Conn) SetPingHandler(h func(string) error) { c.handlePing = h } -// SetPongHandler sets then handler for pong messages received from the peer. +// SetPongHandler sets the handler for pong messages received from the peer. // The default pong handler does nothing. func (c *Conn) SetPongHandler(h func(string) error) { if h == nil { diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/conn_test.go b/vendor/github.com/gorilla/websocket/conn_test.go old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/conn_test.go rename to vendor/github.com/gorilla/websocket/conn_test.go diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/doc.go b/vendor/github.com/gorilla/websocket/doc.go old mode 100644 new mode 100755 similarity index 98% rename from Godeps/_workspace/src/github.com/gorilla/websocket/doc.go rename to vendor/github.com/gorilla/websocket/doc.go index 0d2bd91..f52925d --- a/Godeps/_workspace/src/github.com/gorilla/websocket/doc.go +++ b/vendor/github.com/gorilla/websocket/doc.go @@ -24,7 +24,7 @@ // ... Use conn to send and receive messages. // } // -// Call the connection WriteMessage and ReadMessages methods to send and +// Call the connection's WriteMessage and ReadMessage methods to send and // receive messages as a slice of bytes. This snippet of code shows how to echo // messages using these methods: // diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/autobahn/README.md b/vendor/github.com/gorilla/websocket/examples/autobahn/README.md old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/examples/autobahn/README.md rename to vendor/github.com/gorilla/websocket/examples/autobahn/README.md diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/autobahn/fuzzingclient.json b/vendor/github.com/gorilla/websocket/examples/autobahn/fuzzingclient.json old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/examples/autobahn/fuzzingclient.json rename to vendor/github.com/gorilla/websocket/examples/autobahn/fuzzingclient.json diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/autobahn/server.go b/vendor/github.com/gorilla/websocket/examples/autobahn/server.go old mode 100644 new mode 100755 similarity index 99% rename from Godeps/_workspace/src/github.com/gorilla/websocket/examples/autobahn/server.go rename to vendor/github.com/gorilla/websocket/examples/autobahn/server.go index c483cb6..d96ac84 --- a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/autobahn/server.go +++ b/vendor/github.com/gorilla/websocket/examples/autobahn/server.go @@ -147,7 +147,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) { return } w.Header().Set("Content-Type", "text/html; charset=utf-8") - io.WriteString(w, "Echo ServerEcho Server") } var addr = flag.String("addr", ":9000", "http service address") diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/chat/README.md b/vendor/github.com/gorilla/websocket/examples/chat/README.md old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/examples/chat/README.md rename to vendor/github.com/gorilla/websocket/examples/chat/README.md diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/chat/conn.go b/vendor/github.com/gorilla/websocket/examples/chat/conn.go old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/examples/chat/conn.go rename to vendor/github.com/gorilla/websocket/examples/chat/conn.go diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/chat/home.html b/vendor/github.com/gorilla/websocket/examples/chat/home.html old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/examples/chat/home.html rename to vendor/github.com/gorilla/websocket/examples/chat/home.html diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/chat/hub.go b/vendor/github.com/gorilla/websocket/examples/chat/hub.go old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/examples/chat/hub.go rename to vendor/github.com/gorilla/websocket/examples/chat/hub.go diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/chat/main.go b/vendor/github.com/gorilla/websocket/examples/chat/main.go old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/examples/chat/main.go rename to vendor/github.com/gorilla/websocket/examples/chat/main.go diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/filewatch/README.md b/vendor/github.com/gorilla/websocket/examples/filewatch/README.md old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/examples/filewatch/README.md rename to vendor/github.com/gorilla/websocket/examples/filewatch/README.md diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/examples/filewatch/main.go b/vendor/github.com/gorilla/websocket/examples/filewatch/main.go old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/examples/filewatch/main.go rename to vendor/github.com/gorilla/websocket/examples/filewatch/main.go diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/json.go b/vendor/github.com/gorilla/websocket/json.go old mode 100644 new mode 100755 similarity index 79% rename from Godeps/_workspace/src/github.com/gorilla/websocket/json.go rename to vendor/github.com/gorilla/websocket/json.go index e0668f2..18e62f2 --- a/Godeps/_workspace/src/github.com/gorilla/websocket/json.go +++ b/vendor/github.com/gorilla/websocket/json.go @@ -6,6 +6,7 @@ package websocket import ( "encoding/json" + "io" ) // WriteJSON is deprecated, use c.WriteJSON instead. @@ -45,5 +46,12 @@ func (c *Conn) ReadJSON(v interface{}) error { if err != nil { return err } - return json.NewDecoder(r).Decode(v) + err = json.NewDecoder(r).Decode(v) + if err == io.EOF { + // Decode returns io.EOF when the message is empty or all whitespace. + // Convert to io.ErrUnexpectedEOF so that application can distinguish + // between an error reading the JSON value and the connection closing. + err = io.ErrUnexpectedEOF + } + return err } diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/json_test.go b/vendor/github.com/gorilla/websocket/json_test.go old mode 100644 new mode 100755 similarity index 55% rename from Godeps/_workspace/src/github.com/gorilla/websocket/json_test.go rename to vendor/github.com/gorilla/websocket/json_test.go index 2edb28d..1b7a5ec --- a/Godeps/_workspace/src/github.com/gorilla/websocket/json_test.go +++ b/vendor/github.com/gorilla/websocket/json_test.go @@ -6,6 +6,8 @@ package websocket import ( "bytes" + "encoding/json" + "io" "reflect" "testing" ) @@ -36,6 +38,60 @@ func TestJSON(t *testing.T) { } } +func TestPartialJsonRead(t *testing.T) { + var buf bytes.Buffer + c := fakeNetConn{&buf, &buf} + wc := newConn(c, true, 1024, 1024) + rc := newConn(c, false, 1024, 1024) + + var v struct { + A int + B string + } + v.A = 1 + v.B = "hello" + + messageCount := 0 + + // Partial JSON values. + + data, err := json.Marshal(v) + if err != nil { + t.Fatal(err) + } + for i := len(data) - 1; i >= 0; i-- { + if err := wc.WriteMessage(TextMessage, data[:i]); err != nil { + t.Fatal(err) + } + messageCount++ + } + + // Whitespace. + + if err := wc.WriteMessage(TextMessage, []byte(" ")); err != nil { + t.Fatal(err) + } + messageCount++ + + // Close. + + if err := wc.WriteMessage(CloseMessage, FormatCloseMessage(CloseNormalClosure, "")); err != nil { + t.Fatal(err) + } + + for i := 0; i < messageCount; i++ { + err := rc.ReadJSON(&v) + if err != io.ErrUnexpectedEOF { + t.Error("read", i, err) + } + } + + err = rc.ReadJSON(&v) + if err != io.EOF { + t.Error("final", err) + } +} + func TestDeprecatedJSON(t *testing.T) { var buf bytes.Buffer c := fakeNetConn{&buf, &buf} diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/server.go b/vendor/github.com/gorilla/websocket/server.go old mode 100644 new mode 100755 similarity index 98% rename from Godeps/_workspace/src/github.com/gorilla/websocket/server.go rename to vendor/github.com/gorilla/websocket/server.go index 349e5b9..e56a004 --- a/Godeps/_workspace/src/github.com/gorilla/websocket/server.go +++ b/vendor/github.com/gorilla/websocket/server.go @@ -98,11 +98,11 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade } if !tokenListContainsValue(r.Header, "Connection", "upgrade") { - return u.returnError(w, r, http.StatusBadRequest, "websocket: connection header != upgrade") + return u.returnError(w, r, http.StatusBadRequest, "websocket: could not find connection header with token 'upgrade'") } if !tokenListContainsValue(r.Header, "Upgrade", "websocket") { - return u.returnError(w, r, http.StatusBadRequest, "websocket: upgrade != websocket") + return u.returnError(w, r, http.StatusBadRequest, "websocket: could not find upgrade header with token 'websocket'") } checkOrigin := u.CheckOrigin diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/server_test.go b/vendor/github.com/gorilla/websocket/server_test.go old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/server_test.go rename to vendor/github.com/gorilla/websocket/server_test.go diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/util.go b/vendor/github.com/gorilla/websocket/util.go old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/util.go rename to vendor/github.com/gorilla/websocket/util.go diff --git a/Godeps/_workspace/src/github.com/gorilla/websocket/util_test.go b/vendor/github.com/gorilla/websocket/util_test.go old mode 100644 new mode 100755 similarity index 100% rename from Godeps/_workspace/src/github.com/gorilla/websocket/util_test.go rename to vendor/github.com/gorilla/websocket/util_test.go