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

override req host from header #219

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 11 additions & 3 deletions core/scenario/requester/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,12 @@ func (h *HttpRequester) prepareReq(envs map[string]interface{}, trace *httptrace
if errURL != nil {
return nil, errURL
}
httpReq.Host = httpReq.URL.Host

// If Host is not given in the header, set it from the original URL
// Note that a temporary url used in initRequest
if httpReq.Header.Get("Host") == "" {
httpReq.Host = httpReq.URL.Host
}

// header
if h.containsDynamicField["header"] {
Expand Down Expand Up @@ -619,10 +624,13 @@ func (h *HttpRequester) initRequestInstance() (err error) {
// Headers
header := make(http.Header)
for k, v := range h.packet.Headers {
header.Set(k, v)
// Since we use a temp url, we need to override the request.Host either
// it will be app.ddosify.com
// or it will be the host from the headers
// later on prepareReq, we will override the host if it is set in the headers
if strings.EqualFold(k, "Host") {
h.request.Host = v
} else {
header.Set(k, v)
}
}

Expand Down
1 change: 1 addition & 0 deletions core/scenario/requester/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func TestInitRequest(t *testing.T) {
expectedWithHeaders.Header.Set("Header1", "Value1")
expectedWithHeaders.Header.Set("Header2", "Value2")
expectedWithHeaders.Header.Set("User-Agent", "Firefox")
expectedWithHeaders.Header.Set("Host", "test.com")
expectedWithHeaders.Host = "test.com"
expectedWithHeaders.SetBasicAuth(sWithHeaders.Auth.Username, sWithHeaders.Auth.Password)

Expand Down
Loading