Skip to content

Commit df9fdda

Browse files
authored
Merge pull request #51 from devploit/devploit/review-project
Fix request handling and add tests
2 parents 5629009 + 037c18c commit df9fdda

6 files changed

Lines changed: 197 additions & 116 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ While nomore403 is designed for educational and ethical testing purposes, it's i
259259
260260
## License
261261
262-
nomore403 is released under the MIT License. See the [LICENSE](https://github.com/devploit/dontgo403/blob/main/LICENSE) file for details.
262+
nomore403 is released under the MIT License. See the [LICENSE](https://github.com/devploit/nomore403/blob/main/LICENSE) file for details.
263263
264264
## Acknowledgments
265265

cmd/api.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ func parseFile(filename string) ([]string, error) {
2424
return nil, err
2525
}
2626
defer func(file *os.File) {
27-
err := file.Close()
28-
if err != nil {
29-
log.Fatalf("{#err}")
27+
if err := file.Close(); err != nil {
28+
log.Printf("Error closing file: %v", err)
3029
}
3130
}(file)
3231

3332
var lines []string
3433
scanner := bufio.NewScanner(file)
3534
for scanner.Scan() {
36-
lines = append(lines, scanner.Text())
35+
line := strings.TrimRight(scanner.Text(), "\r")
36+
if line == "" {
37+
continue
38+
}
39+
lines = append(lines, line)
3740
}
3841
if err := scanner.Err(); err != nil {
3942
return nil, err
@@ -54,27 +57,30 @@ func request(method, uri string, headers []header, proxy *url.URL, rateLimit boo
5457
method = "GET"
5558
}
5659

57-
if len(proxy.Host) == 0 {
60+
if proxy == nil || len(proxy.Host) == 0 {
5861
proxy = nil
5962
}
6063

64+
timeoutDuration := time.Duration(timeout) * time.Millisecond
6165
customTransport := &http.Transport{
6266
Proxy: http.ProxyURL(proxy),
6367
TLSClientConfig: &tls.Config{
6468
InsecureSkipVerify: true,
6569
},
6670
DialContext: (&net.Dialer{
67-
Timeout: time.Duration(timeout) / 1000 * time.Second,
71+
Timeout: timeoutDuration,
6872
KeepAlive: 30 * time.Second,
6973
}).DialContext,
7074
MaxIdleConns: 100,
7175
IdleConnTimeout: 90 * time.Second,
72-
TLSHandshakeTimeout: 10 * time.Second,
76+
TLSHandshakeTimeout: timeoutDuration,
77+
ResponseHeaderTimeout: timeoutDuration,
7378
ExpectContinueTimeout: 1 * time.Second,
7479
}
7580

7681
client := &http.Client{
7782
Transport: customTransport,
83+
Timeout: timeoutDuration,
7884
}
7985

8086
if !redirect {
@@ -85,8 +91,8 @@ func request(method, uri string, headers []header, proxy *url.URL, rateLimit boo
8591

8692
// Use raw URL parser
8793
parsedURL, err := url.Parse(uri)
88-
if err != nil || parsedURL == nil {
89-
return 0, nil, nil
94+
if err != nil || parsedURL == nil || parsedURL.Scheme == "" || parsedURL.Host == "" {
95+
return 0, nil, fmt.Errorf("invalid URL: %q", uri)
9096
}
9197

9298
parsedURL.RawPath = parsedURL.EscapedPath()

0 commit comments

Comments
 (0)