예제 #1
0
// ModifyRequest deletes all request headers based on the header name.
func (m *blacklistModifier) ModifyRequest(req *http.Request) error {
	h := proxyutil.RequestHeader(req)

	for _, name := range m.names {
		h.Del(name)
	}

	return nil
}
예제 #2
0
// ModifyRequest runs reqmod iff req has a header with name matching value.
func (f *Filter) ModifyRequest(req *http.Request) error {
	h := proxyutil.RequestHeader(req)

	vs, ok := h.All(f.name)
	if !ok {
		return nil
	}

	for _, v := range vs {
		if v == f.value {
			return f.reqmod.ModifyRequest(req)
		}
	}

	return nil
}
예제 #3
0
파일: har.go 프로젝트: brunoqc/martian
// LogRequest logs the HTTP request with the given ID. The ID should be unique
// per request/response pair.
func (l *Logger) LogRequest(id string, req *http.Request) error {
	hreq := &Request{
		Method:      req.Method,
		URL:         req.URL.String(),
		HTTPVersion: req.Proto,
		HeadersSize: -1,
		BodySize:    req.ContentLength,
		QueryString: []QueryString{},
	}

	hreq.Headers = headers(proxyutil.RequestHeader(req).Map())
	hreq.Cookies = cookies(req.Cookies())

	for n, vs := range req.URL.Query() {
		for _, v := range vs {
			hreq.QueryString = append(hreq.QueryString, QueryString{
				Name:  n,
				Value: v,
			})
		}
	}

	pd, err := postData(req)
	if err != nil {
		return err
	}
	hreq.PostData = pd

	l.mu.Lock()
	defer l.mu.Unlock()

	l.entries[id] = &Entry{
		ID:              id,
		StartedDateTime: time.Now().UTC(),
		Request:         hreq,
		Cache:           &Cache{},
		Timings:         &Timings{},
	}

	return nil
}
예제 #4
0
// ModifyRequest verifies that the header for name is present in all modified
// requests. 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 request.
func (v *verifier) ModifyRequest(req *http.Request) error {
	h := proxyutil.RequestHeader(req)

	vs, ok := h.All(v.name)
	if !ok {
		v.reqerr.Add(fmt.Errorf(headerErrFormat, "request", req.URL, v.name))
		return nil
	}

	for _, value := range vs {
		switch v.value {
		case "", value:
			return nil
		}
	}

	v.reqerr.Add(fmt.Errorf(valueErrFormat, "request", req.URL, v.name,
		strings.Join(vs, ", "), v.value))

	return nil
}
예제 #5
0
// ModifyRequest copies the header in from to the request header for to.
func (m *copyModifier) ModifyRequest(req *http.Request) error {
	h := proxyutil.RequestHeader(req)

	return h.Set(m.to, h.Get(m.from))
}
예제 #6
0
// ModifyRequest sets the header at name with value on the request.
func (m *modifier) ModifyRequest(req *http.Request) error {
	return proxyutil.RequestHeader(req).Set(m.name, m.value)
}