webhelp.v1: gopkg.in/webhelp.v1/whcompat Index | Files

package whcompat

import "gopkg.in/webhelp.v1/whcompat"

Package whcompat provides webhelp compatibility across different Go releases.

The webhelp suite depends heavily on Go 1.7 style http.Request contexts, which aren't available in earlier Go releases. This package backports all of the functionality in a forwards-compatible way. You can use this package to get the desired behavior for all Go releases.

Index

Package Files

close18.go compat17.go pkg.go

func CloseNotify Uses

func CloseNotify(h http.Handler) http.Handler

CloseNotify causes a handler to have its request.Context() canceled the second the client TCP connection goes away by hooking the http.CloseNotifier logic into the context. Prior to Go 1.8, this costs an extra goroutine in a read loop. Go 1.8 and on, this behavior happens automatically with or without this wrapper.

func Context Uses

func Context(r *http.Request) context.Context

Context is a light wrapper around the behavior of Go 1.7's (*http.Request).Context method, except this version works with earlier Go releases, too. In Go 1.7 and on, this simply calls r.Context(). See the note for WithContext for how this works on previous Go releases. If building with the appengine tag, when needed, fresh contexts will be generated with appengine.NewContext().

func DoneNotify Uses

func DoneNotify(h http.Handler) http.Handler

DoneNotify cancels request contexts when the http.Handler returns in Go releases prior to Go 1.7. In Go 1.7 and forward, this is a no-op. You get this behavior for free if you use whlog.ListenAndServe.

func WithContext Uses

func WithContext(r *http.Request, ctx context.Context) *http.Request

WithContext is a light wrapper around the behavior of Go 1.7's (*http.Request).WithContext method, except this version works with earlier Go releases, too. IMPORTANT CAVEAT: to get this to work for Go 1.6 and earlier, a few tricks are pulled, such as expecting the returned r.URL to never change what object it points to, and a finalizer is set on the returned request.

Package whcompat imports 2 packages (graph) and is imported by 13 packages. Updated 2017-06-02. Refresh now. Tools for package owners.