Compare commits

...

3 Commits

16 changed files with 57 additions and 18 deletions

View File

@ -84,6 +84,7 @@ Send 1000 GET requests to https://example.com with 10 parallel dodos (threads),
"dodos": 10, "dodos": 10,
"requests": 1000, "requests": 1000,
"duration": "250s", "duration": "250s",
"skip_verify": false,
"params": [ "params": [
// A random value will be selected from the list for first "key1" param on each request // A random value will be selected from the list for first "key1" param on each request
@ -162,6 +163,7 @@ timeout: "800ms"
dodos: 10 dodos: 10
requests: 1000 requests: 1000
duration: "250s" duration: "250s"
skip_verify: false
params: params:
# A random value will be selected from the list for first "key1" param on each request # A random value will be selected from the list for first "key1" param on each request
@ -248,7 +250,7 @@ If `Headers`, `Params`, `Cookies`, `Body`, or `Proxy` fields have multiple value
| Parameter | config file | CLI Flag | CLI Short Flag | Type | Description | Default | | Parameter | config file | CLI Flag | CLI Short Flag | Type | Description | Default |
| --------------- | ----------- | ------------ | -------------- | ------------------------------ | ----------------------------------------------------------- | ------- | | --------------- | ----------- | ------------ | -------------- | ------------------------------ | ----------------------------------------------------------- | ------- |
| Config file | - | -config-file | -f | String | Path to local config file or http(s) URL of the config file | - | | Config file | | -config-file | -f | String | Path to local config file or http(s) URL of the config file | - |
| Yes | yes | -yes | -y | Boolean | Answer yes to all questions | false | | Yes | yes | -yes | -y | Boolean | Answer yes to all questions | false |
| URL | url | -url | -u | String | URL to send the request to | - | | URL | url | -url | -u | String | URL to send the request to | - |
| Method | method | -method | -m | String | HTTP method | GET | | Method | method | -method | -m | String | HTTP method | GET |
@ -261,3 +263,4 @@ If `Headers`, `Params`, `Cookies`, `Body`, or `Proxy` fields have multiple value
| Cookies | cookies | -cookie | -c | [{String: String OR [String]}] | Request cookies | - | | Cookies | cookies | -cookie | -c | [{String: String OR [String]}] | Request cookies | - |
| Body | body | -body | -b | String OR [String] | Request body or list of request bodies | - | | Body | body | -body | -b | String OR [String] | Request body or list of request bodies | - |
| Proxy | proxies | -proxy | -x | String OR [String] | Proxy URL or list of proxy URLs | - | | Proxy | proxies | -proxy | -x | String OR [String] | Proxy URL or list of proxy URLs | - |
| Skip Verify | skip_verify | -skip-verify | | Boolean | Skip SSL/TLS certificate verification | false |

View File

@ -20,8 +20,16 @@ vars:
tasks: tasks:
run: go run main.go run: go run main.go
ftl:
cmds:
- task: fmt
- task: tidy
- task: lint
fmt: gofmt -w -d . fmt: gofmt -w -d .
tidy: go mod tidy
lint: golangci-lint run lint: golangci-lint run
build: go build -ldflags "-s -w" -o "dodo" build: go build -ldflags "-s -w" -o "dodo"

View File

@ -6,6 +6,7 @@
"dodos": 8, "dodos": 8,
"requests": 1000, "requests": 1000,
"duration": "10s", "duration": "10s",
"skip_verify": false,
"params": [ "params": [
{ "key1": ["value1", "value2", "value3", "value4"] }, { "key1": ["value1", "value2", "value3", "value4"] },
@ -33,4 +34,4 @@
"socks5://example.com:8080", "socks5://example.com:8080",
"socks5h://example.com:8080" "socks5h://example.com:8080"
] ]
} }

View File

@ -5,6 +5,7 @@ timeout: "5s"
dodos: 8 dodos: 8
requests: 1000 requests: 1000
duration: "10s" duration: "10s"
skip_verify: false
params: params:
- key1: ["value1", "value2", "value3", "value4"] - key1: ["value1", "value2", "value3", "value4"]

View File

@ -31,7 +31,7 @@ Usage with all flags:
-p "param1=value1" -param "param2=value2" \ -p "param1=value1" -param "param2=value2" \
-c "cookie1=value1" -cookie "cookie2=value2" \ -c "cookie1=value1" -cookie "cookie2=value2" \
-x "http://proxy.example.com:8080" -proxy "socks5://proxy2.example.com:8080" \ -x "http://proxy.example.com:8080" -proxy "socks5://proxy2.example.com:8080" \
-y -skip-verify -y
Flags: Flags:
-h, -help help for dodo -h, -help help for dodo
@ -48,7 +48,8 @@ Flags:
-p, -param [string] Parameter for the request (e.g. "key1=value1") -p, -param [string] Parameter for the request (e.g. "key1=value1")
-H, -header [string] Header for the request (e.g. "key1:value1") -H, -header [string] Header for the request (e.g. "key1:value1")
-c, -cookie [string] Cookie for the request (e.g. "key1=value1") -c, -cookie [string] Cookie for the request (e.g. "key1=value1")
-x, -proxy [string] Proxy for the request (e.g. "http://proxy.example.com:8080")` -x, -proxy [string] Proxy for the request (e.g. "http://proxy.example.com:8080")
-skip-verify bool Skip SSL/TLS certificate verification (default %v)`
func (config *Config) ReadCLI() (types.ConfigFile, error) { func (config *Config) ReadCLI() (types.ConfigFile, error) {
flag.Usage = func() { flag.Usage = func() {
@ -58,6 +59,7 @@ func (config *Config) ReadCLI() (types.ConfigFile, error) {
DefaultDodosCount, DefaultDodosCount,
DefaultTimeout, DefaultTimeout,
DefaultMethod, DefaultMethod,
DefaultSkipVerify,
) )
} }
@ -65,6 +67,7 @@ func (config *Config) ReadCLI() (types.ConfigFile, error) {
version = false version = false
configFile = "" configFile = ""
yes = false yes = false
skipVerify = false
method = "" method = ""
url types.RequestURL url types.RequestURL
dodosCount = uint(0) dodosCount = uint(0)
@ -83,6 +86,8 @@ func (config *Config) ReadCLI() (types.ConfigFile, error) {
flag.BoolVar(&yes, "yes", false, "Answer yes to all questions") flag.BoolVar(&yes, "yes", false, "Answer yes to all questions")
flag.BoolVar(&yes, "y", false, "Answer yes to all questions") flag.BoolVar(&yes, "y", false, "Answer yes to all questions")
flag.BoolVar(&skipVerify, "skip-verify", false, "Skip SSL/TLS certificate verification")
flag.StringVar(&method, "method", "", "HTTP Method") flag.StringVar(&method, "method", "", "HTTP Method")
flag.StringVar(&method, "m", "", "HTTP Method") flag.StringVar(&method, "m", "", "HTTP Method")
@ -149,6 +154,8 @@ func (config *Config) ReadCLI() (types.ConfigFile, error) {
config.Timeout = &types.Timeout{Duration: timeout} config.Timeout = &types.Timeout{Duration: timeout}
case "yes", "y": case "yes", "y":
config.Yes = utils.ToPtr(yes) config.Yes = utils.ToPtr(yes)
case "skip-verify":
config.SkipVerify = utils.ToPtr(skipVerify)
} }
}) })

View File

@ -15,7 +15,7 @@ import (
) )
const ( const (
VERSION string = "0.6.4" VERSION string = "0.6.5"
DefaultUserAgent string = "Dodo/" + VERSION DefaultUserAgent string = "Dodo/" + VERSION
DefaultMethod string = "GET" DefaultMethod string = "GET"
DefaultTimeout time.Duration = time.Second * 10 DefaultTimeout time.Duration = time.Second * 10
@ -23,6 +23,7 @@ const (
DefaultRequestCount uint = 0 DefaultRequestCount uint = 0
DefaultDuration time.Duration = 0 DefaultDuration time.Duration = 0
DefaultYes bool = false DefaultYes bool = false
DefaultSkipVerify bool = false
) )
var SupportedProxySchemes []string = []string{"http", "socks5", "socks5h"} var SupportedProxySchemes []string = []string{"http", "socks5", "socks5h"}
@ -35,6 +36,7 @@ type RequestConfig struct {
RequestCount uint RequestCount uint
Duration time.Duration Duration time.Duration
Yes bool Yes bool
SkipVerify bool
Params types.Params Params types.Params
Headers types.Headers Headers types.Headers
Cookies types.Cookies Cookies types.Cookies
@ -51,6 +53,7 @@ func NewRequestConfig(conf *Config) *RequestConfig {
RequestCount: *conf.RequestCount, RequestCount: *conf.RequestCount,
Duration: conf.Duration.Duration, Duration: conf.Duration.Duration,
Yes: *conf.Yes, Yes: *conf.Yes,
SkipVerify: *conf.SkipVerify,
Params: conf.Params, Params: conf.Params,
Headers: conf.Headers, Headers: conf.Headers,
Cookies: conf.Cookies, Cookies: conf.Cookies,
@ -122,6 +125,8 @@ func (rc *RequestConfig) Print() {
t.AppendRow(table.Row{"Proxy", rc.Proxies.String()}) t.AppendRow(table.Row{"Proxy", rc.Proxies.String()})
t.AppendSeparator() t.AppendSeparator()
t.AppendRow(table.Row{"Body", rc.Body.String()}) t.AppendRow(table.Row{"Body", rc.Body.String()})
t.AppendSeparator()
t.AppendRow(table.Row{"Skip Verify", rc.SkipVerify})
t.Render() t.Render()
} }
@ -134,6 +139,7 @@ type Config struct {
RequestCount *uint `json:"requests" yaml:"requests"` RequestCount *uint `json:"requests" yaml:"requests"`
Duration *types.Duration `json:"duration" yaml:"duration"` Duration *types.Duration `json:"duration" yaml:"duration"`
Yes *bool `json:"yes" yaml:"yes"` Yes *bool `json:"yes" yaml:"yes"`
SkipVerify *bool `json:"skip_verify" yaml:"skip_verify"`
Params types.Params `json:"params" yaml:"params"` Params types.Params `json:"params" yaml:"params"`
Headers types.Headers `json:"headers" yaml:"headers"` Headers types.Headers `json:"headers" yaml:"headers"`
Cookies types.Cookies `json:"cookies" yaml:"cookies"` Cookies types.Cookies `json:"cookies" yaml:"cookies"`
@ -220,6 +226,9 @@ func (config *Config) MergeConfig(newConfig *Config) {
if newConfig.Yes != nil { if newConfig.Yes != nil {
config.Yes = newConfig.Yes config.Yes = newConfig.Yes
} }
if newConfig.SkipVerify != nil {
config.SkipVerify = newConfig.SkipVerify
}
if len(newConfig.Params) != 0 { if len(newConfig.Params) != 0 {
config.Params = newConfig.Params config.Params = newConfig.Params
} }
@ -256,5 +265,8 @@ func (config *Config) SetDefaults() {
if config.Yes == nil { if config.Yes == nil {
config.Yes = utils.ToPtr(DefaultYes) config.Yes = utils.ToPtr(DefaultYes)
} }
if config.SkipVerify == nil {
config.SkipVerify = utils.ToPtr(DefaultSkipVerify)
}
config.Headers.SetIfNotExists("User-Agent", DefaultUserAgent) config.Headers.SetIfNotExists("User-Agent", DefaultUserAgent)
} }

View File

@ -18,11 +18,12 @@ type ClientGeneratorFunc func() *fasthttp.HostClient
// getClients initializes and returns a slice of fasthttp.HostClient based on the provided parameters. // getClients initializes and returns a slice of fasthttp.HostClient based on the provided parameters.
// It can either return clients with proxies or a single client without proxies. // It can either return clients with proxies or a single client without proxies.
func getClients( func getClients(
ctx context.Context, _ context.Context,
timeout time.Duration, timeout time.Duration,
proxies []url.URL, proxies []url.URL,
maxConns uint, maxConns uint,
URL url.URL, URL url.URL,
skipVerify bool,
) []*fasthttp.HostClient { ) []*fasthttp.HostClient {
isTLS := URL.Scheme == "https" isTLS := URL.Scheme == "https"
@ -43,7 +44,7 @@ func getClients(
MaxConns: int(maxConns), MaxConns: int(maxConns),
IsTLS: isTLS, IsTLS: isTLS,
TLSConfig: &tls.Config{ TLSConfig: &tls.Config{
InsecureSkipVerify: true, InsecureSkipVerify: skipVerify,
}, },
Addr: addr, Addr: addr,
Dial: dialFunc, Dial: dialFunc,
@ -58,10 +59,10 @@ func getClients(
} }
client := &fasthttp.HostClient{ client := &fasthttp.HostClient{
MaxConns: int(maxConns), MaxConns: int(maxConns),
IsTLS: isTLS, IsTLS: isTLS,
TLSConfig: &tls.Config{ TLSConfig: &tls.Config{
InsecureSkipVerify: true, InsecureSkipVerify: skipVerify,
}, },
Addr: URL.Host, Addr: URL.Host,
MaxIdleConnDuration: timeout, MaxIdleConnDuration: timeout,
@ -87,6 +88,11 @@ func getDialFunc(proxy *url.URL, timeout time.Duration) (fasthttp.DialFunc, erro
default: default:
return nil, errors.New("unsupported proxy scheme") return nil, errors.New("unsupported proxy scheme")
} }
if dialer == nil {
return nil, errors.New("internal error: proxy dialer is nil")
}
return dialer, nil return dialer, nil
} }

View File

@ -32,6 +32,7 @@ func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, e
requestConfig.Proxies, requestConfig.Proxies,
requestConfig.GetMaxConns(fasthttp.DefaultMaxConnsPerHost), requestConfig.GetMaxConns(fasthttp.DefaultMaxConnsPerHost),
requestConfig.URL, requestConfig.URL,
requestConfig.SkipVerify,
) )
if clients == nil { if clients == nil {
return nil, types.ErrInterrupt return nil, types.ErrInterrupt

View File

@ -66,7 +66,7 @@ func (body *Body) UnmarshalJSON(b []byte) error {
return nil return nil
} }
func (body *Body) UnmarshalYAML(unmarshal func(interface{}) error) error { func (body *Body) UnmarshalYAML(unmarshal func(any) error) error {
var data any var data any
if err := unmarshal(&data); err != nil { if err := unmarshal(&data); err != nil {
return err return err

View File

@ -99,7 +99,7 @@ func (cookies *Cookies) UnmarshalJSON(b []byte) error {
return nil return nil
} }
func (cookies *Cookies) UnmarshalYAML(unmarshal func(interface{}) error) error { func (cookies *Cookies) UnmarshalYAML(unmarshal func(any) error) error {
var raw []map[string]any var raw []map[string]any
if err := unmarshal(&raw); err != nil { if err := unmarshal(&raw); err != nil {
return err return err

View File

@ -35,7 +35,7 @@ func (duration Duration) MarshalJSON() ([]byte, error) {
return json.Marshal(duration.String()) return json.Marshal(duration.String())
} }
func (duration *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error { func (duration *Duration) UnmarshalYAML(unmarshal func(any) error) error {
var v any var v any
if err := unmarshal(&v); err != nil { if err := unmarshal(&v); err != nil {
return err return err

View File

@ -108,7 +108,7 @@ func (headers *Headers) UnmarshalJSON(b []byte) error {
return nil return nil
} }
func (headers *Headers) UnmarshalYAML(unmarshal func(interface{}) error) error { func (headers *Headers) UnmarshalYAML(unmarshal func(any) error) error {
var raw []map[string]any var raw []map[string]any
if err := unmarshal(&raw); err != nil { if err := unmarshal(&raw); err != nil {
return err return err

View File

@ -99,7 +99,7 @@ func (params *Params) UnmarshalJSON(b []byte) error {
return nil return nil
} }
func (params *Params) UnmarshalYAML(unmarshal func(interface{}) error) error { func (params *Params) UnmarshalYAML(unmarshal func(any) error) error {
var raw []map[string]any var raw []map[string]any
if err := unmarshal(&raw); err != nil { if err := unmarshal(&raw); err != nil {
return err return err

View File

@ -75,7 +75,7 @@ func (proxies *Proxies) UnmarshalJSON(b []byte) error {
return nil return nil
} }
func (proxies *Proxies) UnmarshalYAML(unmarshal func(interface{}) error) error { func (proxies *Proxies) UnmarshalYAML(unmarshal func(any) error) error {
var data any var data any
if err := unmarshal(&data); err != nil { if err := unmarshal(&data); err != nil {
return err return err

View File

@ -25,7 +25,7 @@ func (requestURL *RequestURL) UnmarshalJSON(data []byte) error {
return nil return nil
} }
func (requestURL *RequestURL) UnmarshalYAML(unmarshal func(interface{}) error) error { func (requestURL *RequestURL) UnmarshalYAML(unmarshal func(any) error) error {
var urlStr string var urlStr string
if err := unmarshal(&urlStr); err != nil { if err := unmarshal(&urlStr); err != nil {
return err return err

View File

@ -35,7 +35,7 @@ func (timeout Timeout) MarshalJSON() ([]byte, error) {
return json.Marshal(timeout.String()) return json.Marshal(timeout.String())
} }
func (timeout *Timeout) UnmarshalYAML(unmarshal func(interface{}) error) error { func (timeout *Timeout) UnmarshalYAML(unmarshal func(any) error) error {
var v any var v any
if err := unmarshal(&v); err != nil { if err := unmarshal(&v); err != nil {
return err return err