Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match replace rule #63

Merged
merged 3 commits into from
Oct 19, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"crypto/tls"
"fmt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -107,7 +108,7 @@ func (p *Proxy) OnResponse(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Res

// perform match and replace
if p.options.ResponseMatchReplaceDSL != "" {
p.MatchReplaceResponse(resp)
resp = p.MatchReplaceResponse(resp)
}

p.logger.LogResponse(resp, userdata) //nolint
Expand All @@ -134,17 +135,16 @@ func (p *Proxy) MatchReplaceRequest(req *http.Request) *http.Request {
if v, err := dsl.EvalExpr(p.options.RequestMatchReplaceDSL, m); err != nil {
return req
} else {
reqbuffer := v.(string)

reqbuffer := fmt.Sprint(v)
// lazy mode - epic level - rebuild
bf := bufio.NewReader(strings.NewReader(reqbuffer))
requestNew, err := http.ReadRequest(bf)
if err != nil {
return req
}

requestNew.RequestURI = ""
u, err := url.Parse(req.RequestURI)
fmt.Println(requestNew.RequestURI, req.RequestURI, "URI")
Mzack9999 marked this conversation as resolved.
Show resolved Hide resolved
//requestNew.RequestURI = ""
u, err := url.Parse(requestNew.RequestURI)
Mzack9999 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return req
}
Expand All @@ -171,8 +171,7 @@ func (p *Proxy) MatchReplaceResponse(resp *http.Response) *http.Response {
if v, err := dsl.EvalExpr(p.options.ResponseMatchReplaceDSL, m); err != nil {
return resp
} else {
respbuffer := v.(string)

respbuffer := fmt.Sprint(v)
// lazy mode - epic level - rebuild
bf := bufio.NewReader(strings.NewReader(respbuffer))
responseNew, err := http.ReadResponse(bf, nil)
Expand Down