Fixing full URL output with unsafe requests (#1445)

* Fixing full URL output with unsafe requests

* using request url as matched url if empty
This commit is contained in:
Mzack9999 2022-01-10 14:24:33 +01:00 committed by GitHub
parent b77723941d
commit 3748eae5fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 12 deletions

View File

@ -116,6 +116,8 @@ func Parse(request, baseURL string, unsafe bool) (*Request, error) {
if strings.HasSuffix(parsedURL.Path, "/") && strings.HasPrefix(rawRequest.Path, "/") {
parsedURL.Path = strings.TrimSuffix(parsedURL.Path, "/")
}
if !unsafe {
if parsedURL.Path != rawRequest.Path {
rawRequest.Path = fmt.Sprintf("%s%s", parsedURL.Path, rawRequest.Path)
}
@ -126,9 +128,10 @@ func Parse(request, baseURL string, unsafe bool) (*Request, error) {
// If raw request doesn't have a Host header and isn't marked unsafe,
// this will generate the Host header from the parsed baseURL
if !unsafe && rawRequest.Headers["Host"] == "" {
if rawRequest.Headers["Host"] == "" {
rawRequest.Headers["Host"] = hostURL
}
}
// Set the request body
b, err := ioutil.ReadAll(reader)

View File

@ -418,6 +418,11 @@ func (request *Request) executeRequest(reqURL string, generatedRequest *generate
}
}
// use request url as matched url if empty
if formedURL == "" {
formedURL = reqURL
}
if err != nil {
// rawhttp doesn't support draining response bodies.
if resp != nil && resp.Body != nil && generatedRequest.rawRequest == nil {