func (w *jsonpResponseWriter) Write(b []byte) (int, error) {
	if !w.wroteHeader {
		w.WriteHeader(http.StatusOK)
	}
	writer := w.ResponseWriter.(http.ResponseWriter)
	return writer.Write(b)
}
Make sure the local WriteHeader is called.
Provided in order to implement the http.ResponseWriter interface.
package rest
import (
	"bufio"
	"net"
	"net/http"
)
type JsonpMiddleware struct {
	CallbackNameKey string
}
func (mw *JsonpMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc {
	if mw.CallbackNameKey == "" {
		mw.CallbackNameKey = "callback"
	}
	return func(w ResponseWriter, r *Request) {
		callbackName := r.URL.Query().Get(mw.CallbackNameKey)
		if callbackName != "" {
			writer := &jsonpResponseWriter{w, false, callbackName}
			h(writer, r)
		} else {
			h(w, r)
		}
	}
}
type jsonpResponseWriter struct {
	ResponseWriter
	wroteHeader  bool
	callbackName string
}
func (w *jsonpResponseWriter) WriteHeader(code int) {
	w.Header().Set("Content-Type", "text/javascript")
	w.ResponseWriter.WriteHeader(code)
	w.wroteHeader = true
}
func (w *jsonpResponseWriter) WriteJson(v interface{}) error {
	b, err := w.EncodeJson(v)
	if err != nil {
		return err
	}
	w.Header().Set("Content-Disposition", "filename=f.txt")
	w.Header().Set("X-Content-Type-Options", "nosniff")
	w.Write([]byte("/**/" + w.callbackName + "("))
	w.Write(b)
	w.Write([]byte(")"))
	return nil
}
func (w *jsonpResponseWriter) Flush() {
	if !w.wroteHeader {
		w.WriteHeader(http.StatusOK)
	}
	flusher := w.ResponseWriter.(http.Flusher)
	flusher.Flush()
}
func (w *jsonpResponseWriter) CloseNotify() <-chan bool {
	notifier := w.ResponseWriter.(http.CloseNotifier)
	return notifier.CloseNotify()
}
func (w *jsonpResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
	hijacker := w.ResponseWriter.(http.Hijacker)
	return hijacker.Hijack()
}