summaryrefslogtreecommitdiff
path: root/service/http/response.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-02-07 15:52:57 +0300
committerValery Piashchynski <[email protected]>2020-02-07 15:52:57 +0300
commit785e58f8bea7eb9052babc1dd0e94859328728e5 (patch)
tree8e301f947211d0a515f79d2b33e85598eb11766c /service/http/response.go
parent1f9a12a7b3ab745ee39afe2bbc4a19d21fbe7d91 (diff)
Update README.md (remove travis, replace with github actions)
Fix innefectual usage of maps Update headers (canonical usage) Add golangci-lint check to github actions and go 1.13
Diffstat (limited to 'service/http/response.go')
-rw-r--r--service/http/response.go29
1 files changed, 13 insertions, 16 deletions
diff --git a/service/http/response.go b/service/http/response.go
index aafaed13..16434a7c 100644
--- a/service/http/response.go
+++ b/service/http/response.go
@@ -33,7 +33,8 @@ func NewResponse(p *roadrunner.Payload) (*Response, error) {
// Write writes response headers, status and body into ResponseWriter.
func (r *Response) Write(w http.ResponseWriter) error {
- p, h := handlePushHeaders(r.Headers)
+ // INFO map is the reference type in golang
+ p := handlePushHeaders(r.Headers)
if pusher, ok := w.(http.Pusher); ok {
for _, v := range p {
err := pusher.Push(v, nil)
@@ -43,7 +44,7 @@ func (r *Response) Write(w http.ResponseWriter) error {
}
}
- h = handleTrailers(h)
+ handleTrailers(r.Headers)
for n, h := range r.Headers {
for _, v := range h {
w.Header().Add(n, v)
@@ -68,26 +69,24 @@ func (r *Response) Write(w http.ResponseWriter) error {
return nil
}
-func handlePushHeaders(h map[string][]string) ([]string, map[string][]string) {
+func handlePushHeaders(h map[string][]string) []string {
var p []string
- pushHeader, ok := h["http2-push"]
+ pushHeader, ok := h[http2pushHeaderKey]
if !ok {
- return p, h
+ return p
}
- for _, v := range pushHeader {
- p = append(p, v)
- }
+ p = append(p, pushHeader...)
- delete(h, "http2-push")
+ delete(h, http2pushHeaderKey)
- return p, h
+ return p
}
-func handleTrailers(h map[string][]string) map[string][]string {
- trailers, ok := h["trailer"]
+func handleTrailers(h map[string][]string) {
+ trailers, ok := h[trailerHeaderKey]
if !ok {
- return h
+ return
}
for _, tr := range trailers {
@@ -101,7 +100,5 @@ func handleTrailers(h map[string][]string) map[string][]string {
}
}
- delete(h, "trailer")
-
- return h
+ delete(h, trailerHeaderKey)
}