Skip to content

Commit

Permalink
Merge pull request #219 from ddosify/fix/host-override
Browse files Browse the repository at this point in the history
override req host from header
  • Loading branch information
fatihbaltaci authored Jul 17, 2023
2 parents c0503ac + 68ed906 commit 7335ce7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit 7335ce7

Please sign in to comment.