diff --git a/modules/http_proxy_js_request.go b/modules/http_proxy_js_request.go index f389db29..f87ede18 100644 --- a/modules/http_proxy_js_request.go +++ b/modules/http_proxy_js_request.go @@ -88,6 +88,16 @@ func (j *JSRequest) WasModified() bool { return false } +func (j *JSRequest) Header(name, deflt string) string { + name = strings.ToLower(name) + for _, h := range j.Headers { + if name == strings.ToLower(h.Name) { + return h.Value + } + } + return deflt +} + func (j *JSRequest) ReadBody() string { raw, err := ioutil.ReadAll(j.req.Body) if err != nil { diff --git a/modules/http_proxy_js_response.go b/modules/http_proxy_js_response.go index c393e82e..43034158 100644 --- a/modules/http_proxy_js_response.go +++ b/modules/http_proxy_js_response.go @@ -73,6 +73,17 @@ func (j *JSResponse) WasModified() bool { return false } +func (j *JSResponse) Header(name, deflt string) string { + name = strings.ToLower(name) + for _, header := range strings.Split(j.Headers, "\n") { + parts := strings.SplitN(core.Trim(header), ":", 2) + if len(parts) == 2 && strings.ToLower(parts[0]) == name { + return parts[1] + } + } + return deflt +} + func (j *JSResponse) ToResponse(req *http.Request) (resp *http.Response) { resp = goproxy.NewResponse(req, j.ContentType, j.Status, j.Body) if j.Headers != "" {