MCPcopy Index your code
hub / github.com/unrolled/secure / HandlerForRequestOnly

Method HandlerForRequestOnly

secure.go:219–234  ·  view source on GitHub ↗

HandlerForRequestOnly implements the http.HandlerFunc for integration with the standard net/http lib. Note that this is for requests only and will not write any headers.

(h http.Handler)

Source from the content-addressed store, hash-verified

217// HandlerForRequestOnly implements the http.HandlerFunc for integration with the standard net/http lib.
218// Note that this is for requests only and will not write any headers.
219func (s *Secure) HandlerForRequestOnly(h http.Handler) http.Handler {
220 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
221 // Let secure process the request. If it returns an error,
222 // that indicates the request should not continue.
223 responseHeader, r, err := s.processRequest(w, r)
224 if err != nil {
225 return
226 }
227
228 // Save response headers in the request context.
229 ctx := context.WithValue(r.Context(), s.ctxSecureHeaderKey, responseHeader)
230
231 // No headers will be written to the ResponseWriter.
232 h.ServeHTTP(w, r.WithContext(ctx))
233 })
234}
235
236// HandlerFuncWithNext is a special implementation for Negroni, but could be used elsewhere.
237func (s *Secure) HandlerFuncWithNext(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {

Calls 1

processRequestMethod · 0.95