Formatting changes, added a note about context

Matt Holt 2017-05-02 23:55:00 -06:00
parent 5c462bed2e
commit 8195e6293e

@ -1,7 +1,8 @@
*Article is a WIP* *Article is a WIP*
- Use httpserver.Path to compare base paths to know if your handler should handle the request - Use `httpserver.Path` to compare base paths to know whether your handler should handle the request
- Don't touch the file system using a path from the request directly. Instead: - Don't touch the file system using a path from the request directly. Instead:
- To open a file, use http.Dir - To open a file, use `http.Dir` (standard lib)
- For anything else, use httpserver.SafePath to get a sanitized path - For anything else, use `httpserver.SafePath` to get a sanitized path
- If you need to wrap or record the response, wrap your own ResponseWriter type with httpserver.ResponseWriterWrapper so it is guaranteed to implement some crucial interfaces. - If you need to wrap or record the response, wrap your own `ResponseWriter` type with `httpserver.ResponseWriterWrapper` so it is guaranteed to implement some crucial interfaces.
- The `http.Request.URL` (especially its `.Path` value) may be changed by other "rewriting" middlewares. You can always access the original incoming URL via context: `req.Context().Value(httpserver.OriginalURLCtxKey).(url.URL)`