Created
July 18, 2011 22:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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