Skip to content

Commit

Permalink
Merge pull request #221 from ddosify/develop
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 5b6991c + 219634b commit 9252ef7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
12 changes: 6 additions & 6 deletions core/report/stdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (s *stdout) printInDebugMode(input chan *types.ScenarioResult) {
color.Cyan("\n\nSTEP (%d) %-5s\n", verboseInfo.StepId, verboseInfo.StepName)
color.Cyan("-------------------------------------")
if len(verboseInfo.Envs) > 0 {
fmt.Fprintf(w, "%s\n", blue(fmt.Sprintf("- Environment Variables")))
fmt.Fprintf(w, "%s\n", blue("- Environment Variables"))
for eKey, eVal := range verboseInfo.Envs {
switch eVal.(type) {
case map[string]interface{}:
Expand All @@ -228,7 +228,7 @@ func (s *stdout) printInDebugMode(input chan *types.ScenarioResult) {
fmt.Fprintf(w, "\n")
}
if len(verboseInfo.TestData) > 0 {
fmt.Fprintf(w, "%s\n", blue(fmt.Sprintf("- Test Data")))
fmt.Fprintf(w, "%s\n", blue("- Test Data"))

for eKey, eVal := range verboseInfo.TestData {
switch eVal.(type) {
Expand Down Expand Up @@ -260,7 +260,7 @@ func (s *stdout) printInDebugMode(input chan *types.ScenarioResult) {
fmt.Fprint(out, b.String())
break
}
fmt.Fprintf(w, "%s\n", blue(fmt.Sprintf("- Request")))
fmt.Fprintf(w, "%s\n", blue("- Request"))
fmt.Fprintf(w, "\tTarget: \t%s \n", verboseInfo.Request.Url)
fmt.Fprintf(w, "\tMethod: \t%s \n", verboseInfo.Request.Method)

Expand All @@ -276,7 +276,7 @@ func (s *stdout) printInDebugMode(input chan *types.ScenarioResult) {

if verboseInfo.Error == "" {
// response
fmt.Fprintf(w, "\n%s\n", blue(fmt.Sprintf("- Response")))
fmt.Fprintf(w, "\n%s\n", blue("- Response"))
fmt.Fprintf(w, "\tStatusCode:\t%-5d \n", verboseInfo.Response.StatusCode)
fmt.Fprintf(w, "\tResponseTime:\t%-5d(ms) \n", verboseInfo.Response.ResponseTime)
fmt.Fprintf(w, "\t%s\n", "Headers: ")
Expand All @@ -291,14 +291,14 @@ func (s *stdout) printInDebugMode(input chan *types.ScenarioResult) {
}

if len(verboseInfo.FailedCaptures) > 0 {
fmt.Fprintf(w, "%s\n", yellow(fmt.Sprintf("- Failed Captures")))
fmt.Fprintf(w, "%s\n", yellow("- Failed Captures"))
for wKey, wVal := range verboseInfo.FailedCaptures {
fmt.Fprintf(w, "\t\t%s: \t%s \n", wKey, wVal)
}
}

if len(verboseInfo.FailedAssertions) > 0 {
fmt.Fprintf(w, "%s", yellow(fmt.Sprintf("- Failed Assertions")))
fmt.Fprintf(w, "%s", yellow("- Failed Assertions"))
for _, failAssertion := range verboseInfo.FailedAssertions {
fmt.Fprintf(w, "\n\t\tRule: %s\n", failAssertion.Rule)
prettyReceived, _ := json.MarshalIndent(failAssertion.Received, "\t\t", "\t")
Expand Down
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 9252ef7

Please sign in to comment.