ModifyRequest
(req *http.Request)
| 200 | |
| 201 | // ModifyRequest |
| 202 | func (p *Proxy) ModifyRequest(req *http.Request) error { |
| 203 | // // Set Content-Length to zero to allow automatic calculation |
| 204 | req.ContentLength = -1 |
| 205 | |
| 206 | ctx := martian.NewContext(req) |
| 207 | // disable upgrading http connections to https by default |
| 208 | ctx.Session().MarkInsecure() |
| 209 | // setup passthrought and hijack here |
| 210 | userData := types.UserData{ |
| 211 | ID: ctx.ID(), |
| 212 | Host: req.Host, |
| 213 | } |
| 214 | |
| 215 | if stringsutil.EqualFoldAny(req.Host, "proxify", "proxify:443", "proxify:80", p.listenAddr) { |
| 216 | // hijack if this is true |
| 217 | return p.hijackNServe(req, ctx) |
| 218 | } |
| 219 | |
| 220 | // If callbacks are given use them (for library use cases) |
| 221 | if p.options.OnRequestCallback != nil { |
| 222 | return p.options.OnRequestCallback(req, ctx) |
| 223 | } |
| 224 | |
| 225 | boolSlice := []bool{} |
| 226 | for _, expr := range p.options.RequestDSL { |
| 227 | m, _ := util.HTTPRequestToMap(req) |
| 228 | v, err := dsl.EvalExpr(expr, m) |
| 229 | if err != nil { |
| 230 | gologger.Warning().Msgf("Could not evaluate request dsl: %s\n", err) |
| 231 | } |
| 232 | boolSlice = append(boolSlice, err == nil && v.(bool)) |
| 233 | } |
| 234 | // evaluate bool array to get match status |
| 235 | if len(boolSlice) > 0 { |
| 236 | tmp := util.EvalBoolSlice(boolSlice) |
| 237 | userData.Match = &tmp |
| 238 | } |
| 239 | |
| 240 | ctx.Set("user-data", userData) |
| 241 | |
| 242 | // perform match and replace |
| 243 | if len(p.options.RequestMatchReplaceDSL) != 0 { |
| 244 | _ = p.MatchReplaceRequest(req) |
| 245 | } |
| 246 | p.removeBrEncoding(req) |
| 247 | _ = p.logger.LogRequest(req, userData) |
| 248 | return nil |
| 249 | } |
| 250 | |
| 251 | func (*Proxy) removeBrEncoding(req *http.Request) { |
| 252 | encodings := strings.Split(strings.ReplaceAll(req.Header.Get("Accept-Encoding"), " ", ""), ",") |
nothing calls this directly
no test coverage detected