diff --git a/src/app/spreed-speakfreely-server/rooms.go b/src/app/spreed-speakfreely-server/rooms.go index 32655e90..24693de9 100644 --- a/src/app/spreed-speakfreely-server/rooms.go +++ b/src/app/spreed-speakfreely-server/rooms.go @@ -24,7 +24,6 @@ package main import ( "fmt" "net/http" - "net/url" ) type Room struct { @@ -35,7 +34,7 @@ type Room struct { type Rooms struct { } -func (rooms *Rooms) Post(values url.Values, headers http.Header) (int, interface{}, http.Header) { +func (rooms *Rooms) Post(request *http.Request) (int, interface{}, http.Header) { name := NewRandomString(11) return 200, &Room{name, fmt.Sprintf("/%s", name)}, http.Header{"Content-Type": {"application/json"}} diff --git a/src/app/spreed-speakfreely-server/sleepy/core.go b/src/app/spreed-speakfreely-server/sleepy/core.go index b5d726c7..6bf03cf0 100644 --- a/src/app/spreed-speakfreely-server/sleepy/core.go +++ b/src/app/spreed-speakfreely-server/sleepy/core.go @@ -35,7 +35,6 @@ import ( "fmt" "github.com/gorilla/mux" "net/http" - "net/url" ) const ( @@ -43,30 +42,44 @@ const ( POST = "POST" PUT = "PUT" DELETE = "DELETE" + HEAD = "HEAD" + PATCH = "PATCH" ) // GetSupported is the interface that provides the Get // method a resource must support to receive HTTP GETs. type GetSupported interface { - Get(url.Values, http.Header) (int, interface{}, http.Header) + Get(*http.Request) (int, interface{}, http.Header) } // PostSupported is the interface that provides the Post // method a resource must support to receive HTTP POSTs. type PostSupported interface { - Post(url.Values, http.Header) (int, interface{}, http.Header) + Post(*http.Request) (int, interface{}, http.Header) } // PutSupported is the interface that provides the Put // method a resource must support to receive HTTP PUTs. type PutSupported interface { - Put(url.Values, http.Header) (int, interface{}, http.Header) + Put(*http.Request) (int, interface{}, http.Header) } // DeleteSupported is the interface that provides the Delete // method a resource must support to receive HTTP DELETEs. type DeleteSupported interface { - Delete(url.Values, http.Header) (int, interface{}, http.Header) + Delete(*http.Request) (int, interface{}, http.Header) +} + +// HeadSupported is the interface that provides the Head +// method a resource must support to receive HTTP HEADs. +type HeadSupported interface { + Head(*http.Request) (int, interface{}, http.Header) +} + +// PatchSupported is the interface that provides the Patch +// method a resource must support to receive HTTP PATCHs. +type PatchSupported interface { + Patch(*http.Request) (int, interface{}, http.Header) } // Interface for arbitrary muxer support (like http.ServeMux). @@ -99,7 +112,7 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc { return } - var handler func(url.Values, http.Header) (int, interface{}, http.Header) + var handler func(*http.Request) (int, interface{}, http.Header) switch request.Method { case GET: @@ -118,6 +131,14 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc { if resource, ok := resource.(DeleteSupported); ok { handler = resource.Delete } + case HEAD: + if resource, ok := resource.(HeadSupported); ok { + handler = resource.Head + } + case PATCH: + if resource, ok := resource.(PatchSupported); ok { + handler = resource.Patch + } } if handler == nil { @@ -125,7 +146,7 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc { return } - code, data, header := handler(request.Form, request.Header) + code, data, header := handler(request) content, err := json.MarshalIndent(data, "", " ") if err != nil { diff --git a/src/app/spreed-speakfreely-server/stats.go b/src/app/spreed-speakfreely-server/stats.go index 5111afee..ff79138a 100644 --- a/src/app/spreed-speakfreely-server/stats.go +++ b/src/app/spreed-speakfreely-server/stats.go @@ -23,7 +23,6 @@ package main import ( "net/http" - "net/url" "runtime" "time" ) @@ -73,9 +72,9 @@ type Stats struct { hub *Hub } -func (stats *Stats) Get(values url.Values, headers http.Header) (int, interface{}, http.Header) { +func (stats *Stats) Get(request *http.Request) (int, interface{}, http.Header) { - details := values.Get("details") == "1" + details := request.Form.Get("details") == "1" return 200, NewStat(details, stats.hub), http.Header{"Content-Type": {"application/json; charset=utf-8"}, "Access-Control-Allow-Origin": {"*"}} } diff --git a/src/app/spreed-speakfreely-server/tokens.go b/src/app/spreed-speakfreely-server/tokens.go index 7f3f550b..78550446 100644 --- a/src/app/spreed-speakfreely-server/tokens.go +++ b/src/app/spreed-speakfreely-server/tokens.go @@ -24,7 +24,6 @@ package main import ( "log" "net/http" - "net/url" "strings" ) @@ -37,9 +36,9 @@ type Tokens struct { provider TokenProvider } -func (tokens Tokens) Post(values url.Values, headers http.Header) (int, interface{}, http.Header) { +func (tokens Tokens) Post(request *http.Request) (int, interface{}, http.Header) { - auth := values.Get("a") + auth := request.Form.Get("a") if len(auth) > 100 { return 413, NewApiError("auth_too_large", "Auth too large"), nil