示例#1
0
// Filter out only requests with the given response status code
func StatusIs(status int) goproxy.RespCondition {
	return goproxy.RespConditionFunc(
		func(resp *http.Response, ctx *goproxy.ProxyCtx) bool {
			if resp == nil {
				return false
			}
			return resp.StatusCode == status
		})
}
示例#2
0
// True for any text/* content type except a couple
// specific exceptions that generally indicate things
// we don't care about (css/js/json)
func TextButNotCode() goproxy.RespCondition {
	return goproxy.RespConditionFunc(
		func(resp *http.Response, ctx *goproxy.ProxyCtx) bool {
			contentType := resp.Header.Get("Content-Type")
			if !strings.HasPrefix(contentType, "text/") {
				return false
			}
			r := strings.HasPrefix(contentType, "text/css") ||
				strings.HasPrefix(contentType, "text/javascript") ||
				strings.HasPrefix(contentType, "text/json")
			return !r
		})
}