HTTP/2 push support (golang 1.8) (#1215)

* WIP

* HTTP2/Push for golang 1.8

* Push plugin completed for review

* Correct build tag

* Move push plugin position

* Add build tags to tests

* Gofmt that code

* Add header/method validations

* Load push plugin

* Fixes for wrapping writers

* Push after delivering file

* Fixes, review changes

* Remove build tags, support new syntax

* Fix spelling

* gofmt -s -w .

* Gogland time

* Add interface guards

* gofmt

* After review fixes
This commit is contained in:
Mateusz Gajewski
2017-02-17 17:25:22 +01:00
committed by Matt Holt
parent 579007822f
commit cdf7cf5c3f
12 changed files with 882 additions and 12 deletions

View File

@ -459,6 +459,7 @@ var directives = []string{
"proxy",
"fastcgi",
"cgi", // github.com/jung-kurt/caddy-cgi
"push",
"websocket",
"filemanager", // github.com/hacdias/caddy-filemanager
"markdown",

View File

@ -2,6 +2,7 @@ package httpserver
import (
"bufio"
"errors"
"net"
"net/http"
"time"
@ -95,3 +96,18 @@ func (r *ResponseRecorder) CloseNotify() <-chan bool {
}
panic(NonCloseNotifierError{Underlying: r.ResponseWriter})
}
// Push resource to client
func (r *ResponseRecorder) Push(target string, opts *http.PushOptions) error {
if pusher, hasPusher := r.ResponseWriter.(http.Pusher); hasPusher {
return pusher.Push(target, opts)
}
return errors.New("push is unavailable (probably chained http.ResponseWriter does not implement http.Pusher)")
}
// Interface guards
var _ http.Pusher = (*ResponseRecorder)(nil)
var _ http.Flusher = (*ResponseRecorder)(nil)
var _ http.CloseNotifier = (*ResponseRecorder)(nil)
var _ http.Hijacker = (*ResponseRecorder)(nil)

View File

@ -45,6 +45,7 @@ func NewServer(addr string, group []*SiteConfig) (*Server, error) {
sites: group,
connTimeout: GracefulTimeout,
}
s.Server.Handler = s // this is weird, but whatever
// Disable HTTP/2 if desired