[
  {
    "path": ".gitignore",
    "content": "dist/\n"
  },
  {
    "path": ".goreleaser.yml",
    "content": "# This is an example .goreleaser.yml file with some sane defaults.\n# Make sure to check the documentation at http://goreleaser.com\nbefore:\n  hooks:\n    # You may remove this if you don't use go modules.\n    - go mod tidy\n    # you may remove this if you don't need go generate\n    - go generate ./...\nbuilds:\n  - env:\n      - CGO_ENABLED=0\n    goos:\n      - linux\n      - windows\n      - darwin\narchives:\n  - replacements:\n      darwin: macOS\n      linux: Linux\n      windows: Windows\n      386: i386\n      amd64: amd64\n    format: tar.gz\n    format_overrides:\n        - goos: windows\n          format: zip\nchecksum:\n  name_template: 'checksums.txt'\nsnapshot:\n  name_template: \"{{ .Tag }}-next\"\nchangelog:\n  sort: asc\n  filters:\n    exclude:\n      - '^docs:'\n      - '^test:'\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2021 Utku Sen\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# reqstress\r\n\r\nreqstress is a benchmarking&stressing tool that can send raw HTTP requests. It's written in Go and uses [fasthttp](https://github.com/valyala/fasthttp) library instead of Go's default http library, because of its lightning-fast performance.\r\n\r\n## Why Do We Need Another Benchmarking Tool?\r\n\r\nThere are really great benchmarking tools out there such as [wrk](https://github.com/wg/wrk), [bombardier](https://github.com/codesenberg/bombardier), [hey](https://github.com/rakyll/hey), [ab](https://httpd.apache.org/docs/2.4/tr/programs/ab.html). Some of them don't support sending custom requests, they are only sending a GET request to a given URL. Some of them support custom requests but it's really hard to craft one by using command line parameters. I wanted to create a tool that can read a raw HTTP request from a text file and replays it. \r\n\r\nSo, you can copy your favorite request from Burp Suite, Fiddler etc. and pass it to the reqstresser directly. It would be useful for stressing authenticated endpoints and specific requests that create a huge load.\r\n\r\n## reqstress vs. Other Tools\r\n\r\nreqstresser is not the fastest benchmarking tool, but it's not bad either. I tested couple of popular tools on a $20 Linode server with same amount of threads. Here is the result:\r\n\r\n\r\n| Tool         | Num. of Sent Requests | Duration |\r\n|--------------|-----------------------|----------|\r\n| wrk          | ~45000                 | 10s      |\r\n| bombardier   | ~41000                 | 10s      |\r\n| ab           | ~40000                 | 10s      |\r\n| reqstress    | ~39304                 | 10s      |\r\n| hey          | ~35127                 | 10s      |\r\n| goldeneye.py | ~10913                 | 10s      |\r\n\r\n\r\n# Installation\r\n\r\n## From Binary\r\n\r\nYou can download the pre-built binaries from the [releases](https://github.com/utkusen/reqstress/releases) page and run. For example:\r\n\r\n`wget https://github.com/utkusen/reqstress/releases/download/v0.1.4/reqstress_0.1.4_Linux_amd64.tar.gz`\r\n\r\n`tar xzvf reqstress_0.1.4_Linux_amd64.tar.gz`\r\n\r\n`./reqstress --help`\r\n\r\n## From Source\r\n\r\n1. Install Go on your system\r\n2. Run: `go install github.com/utkusen/reqstress@latest`\r\n\r\n# Usage\r\n\r\nreqstress requires 6 parameters to run: \r\n\r\n`-r` : Path of the request file. For example: `-r request.txt`. Request file should contain a raw HTTP request. For example:\r\n\r\n```http\r\nPOST /wp-login.php HTTP/1.1\r\nHost: 1.1.1.1\r\nContent-Length: 107\r\nCache-Control: max-age=0\r\nUpgrade-Insecure-Requests: 1\r\nOrigin: http://1.1.1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\nReferer: http://1.1.1.1/wp-login.php?redirect_to=http%3A%2F%2F1.1.1.1%2Fwp-admin%2F&reauth=1\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7\r\nCookie: wordpress_test_cookie=WP%20Cookie%20check\r\nConnection: close\r\n\r\nlog=admin&pwd=asdadsasdads\r\n\r\n```\r\n\r\n`-w` : The number of workers to run (e.g `-w 750`). The default value is 500. You can increase or decrease this by testing out the capability of your system.\r\n\r\n`-d` : Duration of the test (in seconds) (e.g `-d 60`). Default is infinite.\r\n\r\n`-https` : Target protocol. Can be `true` or `false` (e.g `-https=false`). Default is `true`\r\n\r\n`-t` : Request timeout. (e.g `-t 1`). Default is 5(seconds) \r\n"
  },
  {
    "path": "go.mod",
    "content": "module reqstress\n\ngo 1.13\n\nrequire github.com/valyala/fasthttp v1.26.0\n"
  },
  {
    "path": "go.sum",
    "content": "github.com/andybalholm/brotli v1.0.2 h1:JKnhI/XQ75uFBTiuzXpzFrUriDPiZjlOSzh6wXogP0E=\ngithub.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=\ngithub.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=\ngithub.com/klauspost/compress v1.12.2 h1:2KCfW3I9M7nSc5wOqXAlW2v2U6v+w6cbjvbfp+OykW8=\ngithub.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=\ngithub.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=\ngithub.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=\ngithub.com/valyala/fasthttp v1.26.0 h1:k5Tooi31zPG/g8yS6o2RffRO2C9B9Kah9SY8j/S7058=\ngithub.com/valyala/fasthttp v1.26.0/go.mod h1:cmWIqlu99AO/RKcp1HWaViTqc57FswJOfYYdPJBl8BA=\ngithub.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=\ngolang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=\ngolang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=\ngolang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=\ngolang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=\ngolang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=\ngolang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=\ngolang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=\n"
  },
  {
    "path": "main.go",
    "content": "package main\n\nimport (\n\t\"bufio\"\n\t\"bytes\"\n\t\"crypto/tls\"\n\t\"flag\"\n\t\"fmt\"\n\t\"io\"\n\t\"io/ioutil\"\n\t\"net/http\"\n\t\"os\"\n\t\"strings\"\n\t\"sync\"\n\t\"sync/atomic\"\n\t\"time\"\n\n\t\"github.com/valyala/fasthttp\"\n)\n\nvar averageTime time.Duration\nvar numOfSuccess int32\nvar numOfFail int32\nvar numOfnon200 int32\nvar mtx sync.Mutex\nvar urlStr string\n\nfunc sendRequest(client *fasthttp.Client, req *fasthttp.Request, wg *sync.WaitGroup, timeout int) {\n\tdefer wg.Done()\n\tfor {\n\t\tresp := fasthttp.AcquireResponse()\n\t\ttimeStart := time.Now()\n\t\terr := client.DoTimeout(req, resp, time.Duration(timeout)*time.Second)\n\t\tif err != nil {\n\t\t\tatomic.AddInt32(&numOfFail, 1)\n\t\t\tcontinue\n\t\t}\n\n\t\tgo setAvarageTime(averageTime + time.Since(timeStart))\n\t\tif resp.StatusCode() == fasthttp.StatusOK {\n\t\t\tatomic.AddInt32(&numOfSuccess, 1)\n\t\t} else {\n\t\t\tatomic.AddInt32(&numOfnon200, 1)\n\t\t}\n\t}\n}\n\nfunc setAvarageTime(newTime time.Duration) {\n\tmtx.Lock()\n\taverageTime = newTime\n\tmtx.Unlock()\n}\n\nfunc main() {\n\n\trequestFile := flag.String(\"r\", \"\", \"Path of request file\")\n\tnumWorker := flag.Int(\"w\", 500, \"Number of worker. Default: 500\")\n\tduration := flag.Int(\"d\", 0, \"Test duration. Default: infinite\")\n\ttimeout := flag.Int(\"t\", 5, \"HTTP request timeout (sec.)\")\n\thttps := flag.Bool(\"https\", true, \"Enable https protocol\")\n\tflag.Parse()\n\tif *requestFile == \"\" {\n\t\tfmt.Println(\"Please specify all arguments!\")\n\t\tflag.PrintDefaults()\n\t\tos.Exit(1) // Exit condition requires non-zero exit code\n\t}\n\tcontent, err := ioutil.ReadFile(*requestFile)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\thttpRequest, err := http.ReadRequest(bufio.NewReader(bytes.NewReader(content)))\n\tif err != nil && err != io.ErrUnexpectedEOF {\n\t\tpanic(err)\n\t}\n\n\tvar wg sync.WaitGroup\n\turlStr = \"http://\" + httpRequest.Host + httpRequest.RequestURI\n\tif *https {\n\t\turlStr = \"https://\" + httpRequest.Host + httpRequest.RequestURI\n\t}\n\n\tbodyBytes, err := ioutil.ReadAll(httpRequest.Body)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treq := fasthttp.AcquireRequest()\n\n\treq.SetRequestURI(urlStr)\n\treq.Header.SetMethod(httpRequest.Method)\n\tif httpRequest.Method == \"POST\" {\n\t\treq.SetBody(bodyBytes)\n\t}\n\tfor key, element := range httpRequest.Header {\n\t\treq.Header.Set(key, strings.Join(element, \",\"))\n\t}\n\treq.Header.Set(\"Connection\", \"keep-alive\")\n\treq.Header.Set(\"Cache-Control\", \"no-cache\")\n\treq.Header.Set(\"Content-Length\", string(rune(httpRequest.ContentLength)))\n\n\tclient := &fasthttp.Client{\n\t\tTLSConfig: &tls.Config{InsecureSkipVerify: true},\n\t}\n\n\tfmt.Println(\"Starting the action...\")\n\tfmt.Println(\"The request will be sent:\")\n\tfmt.Println(\"_________________________________\")\n\tfmt.Println(string(content))\n\tfmt.Println(\"_________________________________\")\n\tfor i := 0; i < *numWorker; i++ {\n\t\twg.Add(1)\n\t\tgo sendRequest(client, req, &wg, *timeout)\n\t}\n\n\tif *duration != 0 {\n\t\ttime.Sleep(time.Duration(*duration) * time.Second)\n\t\tfmt.Println(\"\")\n\t\tfmt.Println(\"---------Results--------------------\")\n\t\tfmt.Println(\"\")\n\t\tfmt.Println(\"Total Requests Sent:\", numOfSuccess+numOfnon200+numOfFail)\n\t\tfmt.Println(\"Number of 200OK Responses:\", numOfSuccess)\n\t\tfmt.Println(\"Number of non-200OK Responses:\", numOfnon200)\n\t\tfmt.Println(\"Number of Failed Responses:\", numOfFail)\n\t\tfmt.Println(\"Avg. Response Time:\", averageTime/time.Duration(numOfSuccess+numOfnon200+numOfFail))\n\t\tos.Exit(0) // Exit without error\n\t}\n\tfmt.Println(\"Infinite mode is active. No output will be shown..\")\n\twg.Wait()\n}\n"
  }
]