Skip to content
This repository has been archived by the owner on Apr 24, 2018. It is now read-only.

ResponseWriter now implements CloseNotifier interface #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (m *RouteMux) AddRoute(method string, pattern string, handler http.HandlerF
if strings.HasPrefix(part, ":") {
expr := "([^/]+)"
//a user may choose to override the defult expression
// similar to expressjs: ‘/user/:id([0-9]+)’
// similar to expressjs: ‘/user/:id([0-9]+)’
if index := strings.Index(part, "("); index != -1 {
expr = part[index:]
part = part[:index]
Expand Down Expand Up @@ -138,13 +138,15 @@ func (m *RouteMux) Filter(filter http.HandlerFunc) {

// FilterParam adds the middleware filter iff the REST URL parameter exists.
func (m *RouteMux) FilterParam(param string, filter http.HandlerFunc) {
if !strings.HasPrefix(param,":") {
param = ":"+param
if !strings.HasPrefix(param, ":") {
param = ":" + param
}

m.Filter(func(w http.ResponseWriter, r *http.Request) {
p := r.URL.Query().Get(param)
if len(p) > 0 { filter(w, r) }
if len(p) > 0 {
filter(w, r)
}
})
}

Expand Down Expand Up @@ -243,6 +245,12 @@ func (w *responseWriter) WriteHeader(code int) {
w.writer.WriteHeader(code)
}

// CloseNotify implements the CloseNotifier interface which allows
// detecting when the underlying connection has gone away
func (w *responseWriter) CloseNotify() <-chan bool {
return w.writer.(http.CloseNotifier).CloseNotify()
}

// -----------------------------------------------------------------------------
// Below are helper functions to replace boilerplate
// code that serializes resources and writes to the
Expand Down