Skip to content

Instantly share code, notes, and snippets.

@kylelemons
Created July 18, 2011 22:08
Show Gist options
  • Save kylelemons/1090804 to your computer and use it in GitHub Desktop.
Save kylelemons/1090804 to your computer and use it in GitHub Desktop.
Potential way to prefix a path to a response by injecting an extra layer into the ResponseWriter
type SubDirResponseWriter struct {
ResponseWriter
path string
}
func (w *SubDirResponseWriter) WriteHeader(code int) {
if code/100 == 3 {
loc := w.Header().Get("Location")
if len(loc) > 0 {
url := http.ParseURLReference(loc)
url.Path = w.path + "/" + url.Path
w.Header().Set("Location", url.String())
}
}
w.ResponseWriter.WriteHeader(code)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment