summaryrefslogtreecommitdiff
path: root/psr7/response.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-05-31 15:19:54 +0300
committerWolfy-J <[email protected]>2018-05-31 15:19:54 +0300
commit91a081e3ec43302ca1df8d436e48c2a14d7c76b9 (patch)
tree7c644b8bccf04f1a8dd5c07314665152dbea6d63 /psr7/response.go
parent48f4f7a39a2336be24cc74b4116c02cc941dbd9a (diff)
psr7 support
Diffstat (limited to 'psr7/response.go')
-rw-r--r--psr7/response.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/psr7/response.go b/psr7/response.go
new file mode 100644
index 00000000..6c5f3e17
--- /dev/null
+++ b/psr7/response.go
@@ -0,0 +1,34 @@
+package psr7
+
+import (
+ "net/http"
+ "github.com/sirupsen/logrus"
+)
+
+type Response struct {
+ Status int `json:"status"`
+ Headers map[string][]string `json:"headers"`
+}
+
+func (r *Response) Write(w http.ResponseWriter) {
+ push := make([]string, 0)
+ for k, v := range r.Headers {
+ for _, h := range v {
+ if k == "http2-push" {
+ push = append(push, h)
+ } else {
+ w.Header().Add(k, h)
+ }
+ }
+ }
+
+ if p, ok := w.(http.Pusher); ok {
+ logrus.Info("PUSH SUPPORTED")
+ for _, f := range push {
+ logrus.Info("pushing HTTP2 file ", f)
+ p.Push(f, nil)
+ }
+ }
+
+ w.WriteHeader(r.Status)
+}