// ModifyResponse deletes all response headers based on the header name. func (m *blacklistModifier) ModifyResponse(res *http.Response) error { h := proxyutil.ResponseHeader(res) for _, name := range m.names { h.Del(name) } return nil }
// RecordResponse logs an HTTP response, associating it with the previously-logged // HTTP request with the same ID. func (l *Logger) RecordResponse(id string, res *http.Response) error { hres := &Response{ HTTPVersion: res.Proto, Status: res.StatusCode, StatusText: http.StatusText(res.StatusCode), HeadersSize: -1, BodySize: res.ContentLength, Headers: headers(proxyutil.ResponseHeader(res).Map()), Cookies: cookies(res.Cookies()), } if res.StatusCode >= 300 && res.StatusCode < 400 { hres.RedirectURL = res.Header.Get("Location") } hres.Content = &Content{ Encoding: "base64", MimeType: res.Header.Get("Content-Type"), } if l.bodyLogging(res) { mv := messageview.New() if err := mv.SnapshotResponse(res); err != nil { return err } br, err := mv.BodyReader(messageview.Decode()) if err != nil { return err } body, err := ioutil.ReadAll(br) if err != nil { return err } hres.Content.Text = body hres.Content.Size = int64(len(body)) } l.mu.Lock() defer l.mu.Unlock() if e, ok := l.entries[id]; ok { e.Response = hres e.Time = time.Since(e.StartedDateTime).Nanoseconds() / 1000000 } return nil }
// ModifyResponse runs resmod iff res has a header with name matching value. func (f *Filter) ModifyResponse(res *http.Response) error { h := proxyutil.ResponseHeader(res) vs, ok := h.All(f.name) if !ok { return nil } for _, v := range vs { if v == f.value { return f.resmod.ModifyResponse(res) } } return nil }
// ModifyResponse verifies that the header for name is present in all modified // responses. If value is non-empty the value must be present in at least one // header for name. An error will be added to the contained *MultiError for // every unmatched response. func (v *verifier) ModifyResponse(res *http.Response) error { h := proxyutil.ResponseHeader(res) vs, ok := h.All(v.name) if !ok { v.reserr.Add(fmt.Errorf(headerErrFormat, "response", res.Request.URL, v.name)) return nil } for _, value := range vs { switch v.value { case "", value: return nil } } v.reserr.Add(fmt.Errorf(valueErrFormat, "response", res.Request.URL, v.name, strings.Join(vs, ", "), v.value)) return nil }
// ModifyResponse copies the header in from to the response header for to. func (m *copyModifier) ModifyResponse(res *http.Response) error { h := proxyutil.ResponseHeader(res) return h.Set(m.to, h.Get(m.from)) }
// ModifyResponse sets the header at name with value on the response. func (m *modifier) ModifyResponse(res *http.Response) error { return proxyutil.ResponseHeader(res).Set(m.name, m.value) }