mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-20 11:11:26 +00:00
✨ Added 'no-proxy-check' parameter
This commit is contained in:
parent
9cfae3bdc1
commit
011c7a7774
@ -37,6 +37,7 @@ type RequestConfig struct {
|
|||||||
Proxies []Proxy
|
Proxies []Proxy
|
||||||
Body []string
|
Body []string
|
||||||
Yes bool
|
Yes bool
|
||||||
|
NoProxyCheck bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *RequestConfig) Print() {
|
func (config *RequestConfig) Print() {
|
||||||
@ -66,6 +67,8 @@ func (config *RequestConfig) Print() {
|
|||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
t.AppendRow(table.Row{"Proxies Count", len(config.Proxies)})
|
t.AppendRow(table.Row{"Proxies Count", len(config.Proxies)})
|
||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
|
t.AppendRow(table.Row{"Proxy Check", !config.NoProxyCheck})
|
||||||
|
t.AppendSeparator()
|
||||||
t.AppendRow(table.Row{"Body", utils.MarshalJSON(config.Body, 3)})
|
t.AppendRow(table.Row{"Body", utils.MarshalJSON(config.Body, 3)})
|
||||||
|
|
||||||
t.Render()
|
t.Render()
|
||||||
@ -92,6 +95,7 @@ type Config struct {
|
|||||||
Timeout uint32 `json:"timeout" validate:"gte=1,lte=100000"`
|
Timeout uint32 `json:"timeout" validate:"gte=1,lte=100000"`
|
||||||
DodosCount uint `json:"dodos_count" validate:"gte=1"`
|
DodosCount uint `json:"dodos_count" validate:"gte=1"`
|
||||||
RequestCount uint `json:"request_count" validation_name:"request-count" validate:"gte=1"`
|
RequestCount uint `json:"request_count" validation_name:"request-count" validate:"gte=1"`
|
||||||
|
NoProxyCheck utils.Option[bool] `json:"no_proxy_check"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) MergeConfigs(newConfig *Config) {
|
func (config *Config) MergeConfigs(newConfig *Config) {
|
||||||
@ -110,6 +114,9 @@ func (config *Config) MergeConfigs(newConfig *Config) {
|
|||||||
if newConfig.RequestCount != 0 {
|
if newConfig.RequestCount != 0 {
|
||||||
config.RequestCount = newConfig.RequestCount
|
config.RequestCount = newConfig.RequestCount
|
||||||
}
|
}
|
||||||
|
if !newConfig.NoProxyCheck.IsNone() {
|
||||||
|
config.NoProxyCheck = newConfig.NoProxyCheck
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) SetDefaults() {
|
func (config *Config) SetDefaults() {
|
||||||
@ -125,6 +132,9 @@ func (config *Config) SetDefaults() {
|
|||||||
if config.RequestCount == 0 {
|
if config.RequestCount == 0 {
|
||||||
config.RequestCount = DefaultRequestCount
|
config.RequestCount = DefaultRequestCount
|
||||||
}
|
}
|
||||||
|
if config.NoProxyCheck.IsNone() {
|
||||||
|
config.NoProxyCheck = utils.NewOption(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Proxy struct {
|
type Proxy struct {
|
||||||
|
1
main.go
1
main.go
@ -81,6 +81,7 @@ func main() {
|
|||||||
Proxies: jsonConf.Proxies,
|
Proxies: jsonConf.Proxies,
|
||||||
Body: jsonConf.Body,
|
Body: jsonConf.Body,
|
||||||
Yes: cliConf.Yes,
|
Yes: cliConf.Yes,
|
||||||
|
NoProxyCheck: *conf.NoProxyCheck.ValueOrPanic(),
|
||||||
}
|
}
|
||||||
requestConf.Print()
|
requestConf.Print()
|
||||||
if !cliConf.Yes {
|
if !cliConf.Yes {
|
||||||
|
@ -13,10 +13,15 @@ import (
|
|||||||
func CLIConfigReader() (*config.CLIConfig, error) {
|
func CLIConfigReader() (*config.CLIConfig, error) {
|
||||||
var (
|
var (
|
||||||
returnNil = false
|
returnNil = false
|
||||||
cliConfig = &config.CLIConfig{}
|
cliConfig = &config.CLIConfig{
|
||||||
|
Config: config.Config{
|
||||||
|
NoProxyCheck: utils.NewNoneOption[bool](),
|
||||||
|
},
|
||||||
|
}
|
||||||
dodosCount uint
|
dodosCount uint
|
||||||
requestCount uint
|
requestCount uint
|
||||||
timeout uint32
|
timeout uint32
|
||||||
|
noProxyCheck bool
|
||||||
rootCmd = &cobra.Command{
|
rootCmd = &cobra.Command{
|
||||||
Use: "dodo [flags]",
|
Use: "dodo [flags]",
|
||||||
Example: ` Simple usage only with URL:
|
Example: ` Simple usage only with URL:
|
||||||
@ -51,6 +56,7 @@ func CLIConfigReader() (*config.CLIConfig, error) {
|
|||||||
rootCmd.Flags().UintVarP(&dodosCount, "dodos-count", "d", config.DefaultDodosCount, "Number of dodos(threads)")
|
rootCmd.Flags().UintVarP(&dodosCount, "dodos-count", "d", config.DefaultDodosCount, "Number of dodos(threads)")
|
||||||
rootCmd.Flags().UintVarP(&requestCount, "request-count", "r", config.DefaultRequestCount, "Number of total requests")
|
rootCmd.Flags().UintVarP(&requestCount, "request-count", "r", config.DefaultRequestCount, "Number of total requests")
|
||||||
rootCmd.Flags().Uint32VarP(&timeout, "timeout", "t", config.DefaultTimeout, "Timeout for each request in milliseconds")
|
rootCmd.Flags().Uint32VarP(&timeout, "timeout", "t", config.DefaultTimeout, "Timeout for each request in milliseconds")
|
||||||
|
rootCmd.Flags().BoolVarP(&noProxyCheck, "no-proxy-check", "n", false, "Do not check for proxy")
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
utils.PrintErr(err)
|
utils.PrintErr(err)
|
||||||
rootCmd.Println(rootCmd.UsageString())
|
rootCmd.Println(rootCmd.UsageString())
|
||||||
@ -68,6 +74,8 @@ func CLIConfigReader() (*config.CLIConfig, error) {
|
|||||||
cliConfig.RequestCount = requestCount
|
cliConfig.RequestCount = requestCount
|
||||||
case "timeout":
|
case "timeout":
|
||||||
cliConfig.Timeout = timeout
|
cliConfig.Timeout = timeout
|
||||||
|
case "no-proxy-check":
|
||||||
|
cliConfig.NoProxyCheck = utils.NewOption(noProxyCheck)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if returnNil {
|
if returnNil {
|
||||||
|
@ -5,7 +5,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/aykhans/dodo/config"
|
"github.com/aykhans/dodo/config"
|
||||||
"github.com/aykhans/dodo/custom_errors"
|
customerrors "github.com/aykhans/dodo/custom_errors"
|
||||||
|
"github.com/aykhans/dodo/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func JSONConfigReader(filePath string) (*config.JSONConfig, error) {
|
func JSONConfigReader(filePath string) (*config.JSONConfig, error) {
|
||||||
@ -13,7 +14,11 @@ func JSONConfigReader(filePath string) (*config.JSONConfig, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, customerrors.OSErrorFormater(err)
|
return nil, customerrors.OSErrorFormater(err)
|
||||||
}
|
}
|
||||||
jsonConf := &config.JSONConfig{}
|
jsonConf := &config.JSONConfig{
|
||||||
|
Config: config.Config{
|
||||||
|
NoProxyCheck: utils.NewNoneOption[bool](),
|
||||||
|
},
|
||||||
|
}
|
||||||
err = json.Unmarshal(data, &jsonConf)
|
err = json.Unmarshal(data, &jsonConf)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -26,11 +26,42 @@ func getClients(
|
|||||||
dodosCount uint,
|
dodosCount uint,
|
||||||
maxConns uint,
|
maxConns uint,
|
||||||
yes bool,
|
yes bool,
|
||||||
|
noProxyCheck bool,
|
||||||
URL *url.URL,
|
URL *url.URL,
|
||||||
) []*fasthttp.HostClient {
|
) []*fasthttp.HostClient {
|
||||||
isTLS := URL.Scheme == "https"
|
isTLS := URL.Scheme == "https"
|
||||||
|
|
||||||
if len(proxies) > 0 {
|
if proxiesLen := len(proxies); proxiesLen > 0 {
|
||||||
|
// If noProxyCheck is true, we will return the clients without checking the proxies.
|
||||||
|
if noProxyCheck {
|
||||||
|
clients := make([]*fasthttp.HostClient, 0, proxiesLen)
|
||||||
|
addr := URL.Host
|
||||||
|
if isTLS && URL.Port() == "" {
|
||||||
|
addr += ":443"
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, proxy := range proxies {
|
||||||
|
dialFunc, err := getDialFunc(&proxy, timeout)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
clients = append(clients, &fasthttp.HostClient{
|
||||||
|
MaxConns: int(maxConns),
|
||||||
|
IsTLS: isTLS,
|
||||||
|
Addr: addr,
|
||||||
|
Dial: dialFunc,
|
||||||
|
MaxIdleConnDuration: timeout,
|
||||||
|
MaxConnDuration: timeout,
|
||||||
|
WriteTimeout: timeout,
|
||||||
|
ReadTimeout: timeout,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return clients
|
||||||
|
}
|
||||||
|
|
||||||
|
// Else, we will check the proxies and return the active ones.
|
||||||
activeProxyClients := getActiveProxyClients(
|
activeProxyClients := getActiveProxyClients(
|
||||||
ctx, proxies, timeout, dodosCount, maxConns, URL,
|
ctx, proxies, timeout, dodosCount, maxConns, URL,
|
||||||
)
|
)
|
||||||
|
@ -2,6 +2,7 @@ package requests
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -24,6 +25,8 @@ import (
|
|||||||
// - Responses: A collection of responses from the executed requests.
|
// - Responses: A collection of responses from the executed requests.
|
||||||
// - error: An error if the operation fails, such as no internet connection or an interrupt.
|
// - error: An error if the operation fails, such as no internet connection or an interrupt.
|
||||||
func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, error) {
|
func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, error) {
|
||||||
|
fmt.Println("No Proxy Check:", requestConfig.NoProxyCheck)
|
||||||
|
|
||||||
checkConnectionCtx, checkConnectionCtxCancel := context.WithTimeout(ctx, 8*time.Second)
|
checkConnectionCtx, checkConnectionCtxCancel := context.WithTimeout(ctx, 8*time.Second)
|
||||||
if !checkConnection(checkConnectionCtx) {
|
if !checkConnection(checkConnectionCtx) {
|
||||||
checkConnectionCtxCancel()
|
checkConnectionCtxCancel()
|
||||||
@ -38,6 +41,7 @@ func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, e
|
|||||||
requestConfig.GetValidDodosCountForProxies(),
|
requestConfig.GetValidDodosCountForProxies(),
|
||||||
requestConfig.GetMaxConns(fasthttp.DefaultMaxConnsPerHost),
|
requestConfig.GetMaxConns(fasthttp.DefaultMaxConnsPerHost),
|
||||||
requestConfig.Yes,
|
requestConfig.Yes,
|
||||||
|
requestConfig.NoProxyCheck,
|
||||||
requestConfig.URL,
|
requestConfig.URL,
|
||||||
)
|
)
|
||||||
if clients == nil {
|
if clients == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user