summaryrefslogtreecommitdiff
path: root/psr7/response.go
blob: 6c5f3e17d8d2a71087988385c568f7168bbde243 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)
}