Commit 92e88955 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Simplify WriteHeader in senddata

parent 28c9928c
...@@ -42,26 +42,27 @@ func (s *sendDataResponseWriter) WriteHeader(status int) { ...@@ -42,26 +42,27 @@ func (s *sendDataResponseWriter) WriteHeader(status int) {
if s.status != 0 { if s.status != 0 {
return return
} }
s.status = status s.status = status
if s.status != http.StatusOK {
s.rw.WriteHeader(s.status) if s.status == http.StatusOK && s.tryInject() {
return return
} }
s.rw.WriteHeader(s.status)
}
func (s *sendDataResponseWriter) tryInject() bool {
if header := s.Header().Get(HeaderKey); header != "" { if header := s.Header().Get(HeaderKey); header != "" {
s.Header().Del(HeaderKey) s.Header().Del(HeaderKey)
for _, injecter := range s.injecters { for _, injecter := range s.injecters {
if injecter.Match(header) { if injecter.Match(header) {
s.hijacked = true s.hijacked = true
injecter.Inject(s.rw, s.req, header) injecter.Inject(s.rw, s.req, header)
return return true
} }
} }
} }
return false
s.rw.WriteHeader(s.status)
return
} }
func (s *sendDataResponseWriter) Flush() { func (s *sendDataResponseWriter) Flush() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment