setupRequestOptions configures and returns RequestOptions based on the provided parameters.
(uri, proxy, userAgent string, reqHeaders []string, bypassIP, folder, method string, verbose bool, techniques []string, banner, rateLimit bool, timeout int, redirect, randomAgent bool)
| 3814 | |
| 3815 | // setupRequestOptions configures and returns RequestOptions based on the provided parameters. |
| 3816 | func setupRequestOptions(uri, proxy, userAgent string, reqHeaders []string, bypassIP, folder, method string, verbose bool, techniques []string, banner, rateLimit bool, timeout int, redirect, randomAgent bool) RequestOptions { |
| 3817 | // Set up proxy if provided. |
| 3818 | if len(proxy) != 0 { |
| 3819 | if !strings.Contains(proxy, "http") { |
| 3820 | proxy = "http://" + proxy |
| 3821 | } |
| 3822 | } |
| 3823 | userProxy, err := url.Parse(proxy) |
| 3824 | if err != nil { |
| 3825 | log.Printf("[!] Error parsing proxy URL: %v, continuing without proxy", err) |
| 3826 | userProxy = &url.URL{} |
| 3827 | } |
| 3828 | |
| 3829 | // Check if URI has trailing slash, if not add it. |
| 3830 | x := strings.Split(uri, "/") |
| 3831 | if len(x) < 4 { |
| 3832 | uri += "/" |
| 3833 | } |
| 3834 | |
| 3835 | // Set User-Agent header. |
| 3836 | if !randomAgent { |
| 3837 | if len(userAgent) == 0 { |
| 3838 | userAgent = "nomore403" |
| 3839 | } |
| 3840 | } else { |
| 3841 | line, err := randomLine(folder + "/useragents") |
| 3842 | if err != nil { |
| 3843 | log.Printf("Error reading user agents file: %v", err) |
| 3844 | userAgent = "nomore403" |
| 3845 | } else { |
| 3846 | userAgent = line |
| 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | // Set default request method to GET. |
| 3851 | if len(method) == 0 { |
| 3852 | method = "GET" |
| 3853 | } |
| 3854 | |
| 3855 | headers := []header{ |
| 3856 | {"User-Agent", userAgent}, |
| 3857 | } |
| 3858 | |
| 3859 | // Parse custom headers from CLI arguments and add them to the headers slice. |
| 3860 | if len(reqHeaders) > 0 && reqHeaders[0] != "" { |
| 3861 | for _, _header := range reqHeaders { |
| 3862 | headerSplit := strings.SplitN(_header, ":", 2) |
| 3863 | if len(headerSplit) < 2 { |
| 3864 | log.Printf("Invalid header format: %s\n", _header) |
| 3865 | continue |
| 3866 | } |
| 3867 | headers = append(headers, header{strings.TrimSpace(headerSplit[0]), strings.TrimSpace(headerSplit[1])}) |
| 3868 | } |
| 3869 | } |
| 3870 | |
| 3871 | opts := RequestOptions{ |
| 3872 | uri: uri, |
| 3873 | headers: headers, |