From e5ca3d086867f29e77f6a1481a7aa78d4300e9e9 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Sun, 8 Jan 2017 07:40:43 +0200 Subject: [PATCH] Standby for Go v1.8. Read HISTORY.md for previous commits: iris.DestroyAllSessions/DestroySessionByID. --- response_recorder.go | 39 +++++++++++++++++++++++++++++++++++ response_writer.go | 49 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/response_recorder.go b/response_recorder.go index 43f1a84d..caa352fb 100644 --- a/response_recorder.go +++ b/response_recorder.go @@ -160,6 +160,45 @@ func (w *ResponseRecorder) Flush() { w.ResetBody() } +// NOTE: Users: Uncomment the below code if you are already using Go from master branch. +// HTTP/2 Go 1.8 Push feature, +// as described in the source code(master): +// https://github.com/golang/go/blob/master/src/net/http/http.go#L119 . +// I have already tested the feature on my machine, but +// in order to avoid breaking the users' workspace: +// Uncomment these when 1.8 released (I guess in the middle of February) +// TODO: +// +// // Push initiates an HTTP/2 server push. This constructs a synthetic +// // request using the given target and options, serializes that request +// // into a PUSH_PROMISE frame, then dispatches that request using the +// // server's request handler. If opts is nil, default options are used. +// // +// // The target must either be an absolute path (like "/path") or an absolute +// // URL that contains a valid host and the same scheme as the parent request. +// // If the target is a path, it will inherit the scheme and host of the +// // parent request. +// // +// // The HTTP/2 spec disallows recursive pushes and cross-authority pushes. +// // Push may or may not detect these invalid pushes; however, invalid +// // pushes will be detected and canceled by conforming clients. +// // +// // Handlers that wish to push URL X should call Push before sending any +// // data that may trigger a request for URL X. This avoids a race where the +// // client issues requests for X before receiving the PUSH_PROMISE for X. +// // +// // Push returns ErrNotSupported if the client has disabled push or if push +// // is not supported on the underlying connection. +// func (w *ResponseRecorder) Push(target string, opts *http.PushOptions) error { +// w.flushResponse() +// err := w.responseWriter.Push(target, opts) +// // NOTE: we have to reset them even if the push failed. +// w.ResetBody() +// w.ResetHeaders() +// +// return err +// } + // clone returns a clone of this response writer // it copies the header, status code, headers and the beforeFlush finally returns a new ResponseRecorder func (w *ResponseRecorder) clone() ResponseWriter { diff --git a/response_writer.go b/response_writer.go index 95dfd9c1..d46817f3 100644 --- a/response_writer.go +++ b/response_writer.go @@ -61,6 +61,16 @@ type ResponseWriter interface { http.Flusher http.Hijacker http.CloseNotifier + // NOTE: Users: Uncomment the below code if you are already using Go from master branch. + // HTTP/2 Go 1.8 Push feature, + // as described in the source code(master): + // https://github.com/golang/go/blob/master/src/net/http/http.go#L119 . + // I have already tested the feature on my machine, but + // in order to avoid breaking the users' workspace: + // Uncomment these when 1.8 released (I guess in the middle of February) + // TODO: + // + // http.Pusher Writef(format string, a ...interface{}) (n int, err error) WriteString(s string) (n int, err error) @@ -212,6 +222,45 @@ func (w *responseWriter) Flush() { } } +// NOTE: Users: Uncomment the below code if you are already using Go from master branch. +// HTTP/2 Go 1.8 Push feature, +// as described in the source code(master): +// https://github.com/golang/go/blob/master/src/net/http/http.go#L119 . +// I have already tested the feature on my machine, but +// in order to avoid breaking the users' workspace: +// Uncomment these when 1.8 released (I guess in the middle of February) +// TODO: +// +// +// // Push initiates an HTTP/2 server push. This constructs a synthetic +// // request using the given target and options, serializes that request +// // into a PUSH_PROMISE frame, then dispatches that request using the +// // server's request handler. If opts is nil, default options are used. +// // +// // The target must either be an absolute path (like "/path") or an absolute +// // URL that contains a valid host and the same scheme as the parent request. +// // If the target is a path, it will inherit the scheme and host of the +// // parent request. +// // +// // The HTTP/2 spec disallows recursive pushes and cross-authority pushes. +// // Push may or may not detect these invalid pushes; however, invalid +// // pushes will be detected and canceled by conforming clients. +// // +// // Handlers that wish to push URL X should call Push before sending any +// // data that may trigger a request for URL X. This avoids a race where the +// // client issues requests for X before receiving the PUSH_PROMISE for X. +// // +// // Push returns ErrNotSupported if the client has disabled push or if push +// // is not supported on the underlying connection. +// func (w *responseWriter) Push(target string, opts *http.PushOptions) error { +// +// if pusher, isPusher := w.ResponseWriter.(http.Pusher); isPusher { +// return pusher.Push(target, opts) +// } +// +// return errors.New("HTTP/2 Push feature is not supported, yet.") +// } + // CloseNotify returns a channel that receives at most a // single value (true) when the client connection has gone // away.