Skip to content

Commit 039e91e

Browse files
authored
Merge pull request #42 from slicingmelon/proper-raw-urls
added raw urls support - on parsing and sending sending requests
2 parents a47e83b + ad5cdcb commit 039e91e

5 files changed

Lines changed: 53 additions & 27 deletions

File tree

cmd/api.go

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"os"
1313
"strings"
1414
"time"
15+
16+
"github.com/slicingmelon/go-rawurlparser"
1517
)
1618

1719
// parseFile reads a file given its filename and returns a list containing each of its lines.
@@ -46,7 +48,6 @@ type header struct {
4648
}
4749

4850
// request makes an HTTP request using headers `headers` and proxy `proxy`.
49-
//
5051
// If `method` is empty, it defaults to "GET".
5152
func request(method, uri string, headers []header, proxy *url.URL, rateLimit bool, timeout int, redirect bool) (int, []byte, error) {
5253
if method == "" {
@@ -57,21 +58,23 @@ func request(method, uri string, headers []header, proxy *url.URL, rateLimit boo
5758
proxy = nil
5859
}
5960

60-
client := &http.Client{
61-
Transport: &http.Transport{
62-
Proxy: http.ProxyURL(proxy),
63-
TLSClientConfig: &tls.Config{
64-
InsecureSkipVerify: true,
65-
},
66-
DialContext: (&net.Dialer{
67-
Timeout: time.Duration(timeout) / 1000 * time.Second,
68-
KeepAlive: 30 * time.Second,
69-
}).DialContext,
70-
MaxIdleConns: 100,
71-
IdleConnTimeout: 90 * time.Second,
72-
TLSHandshakeTimeout: 10 * time.Second,
73-
ExpectContinueTimeout: 1 * time.Second,
61+
customTransport := &http.Transport{
62+
Proxy: http.ProxyURL(proxy),
63+
TLSClientConfig: &tls.Config{
64+
InsecureSkipVerify: true,
7465
},
66+
DialContext: (&net.Dialer{
67+
Timeout: time.Duration(timeout) / 1000 * time.Second,
68+
KeepAlive: 30 * time.Second,
69+
}).DialContext,
70+
MaxIdleConns: 100,
71+
IdleConnTimeout: 90 * time.Second,
72+
TLSHandshakeTimeout: 10 * time.Second,
73+
ExpectContinueTimeout: 1 * time.Second,
74+
}
75+
76+
client := &http.Client{
77+
Transport: customTransport,
7578
}
7679

7780
if !redirect {
@@ -80,11 +83,30 @@ func request(method, uri string, headers []header, proxy *url.URL, rateLimit boo
8083
}
8184
}
8285

83-
req, err := http.NewRequest(method, uri, nil)
84-
if err != nil {
85-
return 0, nil, nil
86-
}
87-
req.Close = true
86+
// Use raw URL parser instead
87+
parsedURL := rawurlparser.RawURLParse(uri)
88+
89+
// Create new request
90+
req := &http.Request{
91+
Method: method,
92+
URL: &url.URL{
93+
Scheme: parsedURL.Scheme,
94+
Host: parsedURL.Host,
95+
Opaque: parsedURL.Path, // Use Opaque to prevent path normalization
96+
},
97+
Header: make(http.Header),
98+
Close: true,
99+
}
100+
101+
//log.Printf("Debug - Raw URL parsed: %s", uri)
102+
// Don't use URL.String() for debugging, as it will perform encodings and normalization
103+
// log.Printf("Debug - Request Components - Scheme: %s, Host: %s, Path: %s, RawPath: %s, Opaque: %s",
104+
// req.URL.Scheme,
105+
// req.URL.Host,
106+
// req.URL.Path,
107+
// req.URL.RawPath,
108+
// req.URL.Opaque,
109+
// )
88110

89111
for _, header := range headers {
90112
req.Header.Add(header.key, header.value)

cmd/requester.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"unicode"
1616

1717
"github.com/fatih/color"
18+
"github.com/slicingmelon/go-rawurlparser"
1819
"github.com/zenthangplus/goccm"
1920
)
2021

@@ -377,7 +378,7 @@ func requestMidPaths(options RequestOptions) {
377378
x := strings.Split(options.uri, "/")
378379
var uripath string
379380

380-
parsedURL, err := url.Parse(options.uri)
381+
parsedURL := rawurlparser.RawURLParse(options.uri)
381382
if err != nil {
382383
log.Println(err)
383384
}
@@ -481,11 +482,11 @@ func parseCurlOutput(output string, httpVersion string) Result {
481482
func requestPathCaseSwitching(options RequestOptions) {
482483
color.Cyan("\n━━━━━━━━━━━━ PATH CASE SWITCHING ━━━━━━━━━━━━━")
483484

484-
parsedURL, err := url.Parse(options.uri)
485-
if err != nil {
486-
log.Println(err)
487-
return
488-
}
485+
parsedURL := rawurlparser.RawURLParse(options.uri)
486+
// if err != nil {
487+
// log.Println(err)
488+
// return
489+
// }
489490

490491
baseuri := parsedURL.Scheme + "://" + parsedURL.Host
491492
uripath := strings.Trim(parsedURL.Path, "/")

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module nomore403
22

3-
go 1.19
3+
go 1.23.1
44

55
require (
66
github.com/fatih/color v1.13.0
@@ -19,6 +19,7 @@ require (
1919
github.com/mitchellh/mapstructure v1.5.0 // indirect
2020
github.com/pelletier/go-toml v1.9.5 // indirect
2121
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
22+
github.com/slicingmelon/go-rawurlparser v0.0.0-20241101212355-a74dbff109f7 // indirect
2223
github.com/spf13/afero v1.8.2 // indirect
2324
github.com/spf13/cast v1.5.0 // indirect
2425
github.com/spf13/jwalterweatherman v1.1.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
159159
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
160160
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
161161
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
162+
github.com/slicingmelon/go-rawurlparser v0.0.0-20241101212355-a74dbff109f7 h1:6xhzr51FYZpfVeGHp8M15WuIF+MbyN5ZcnoQRBEAX2A=
163+
github.com/slicingmelon/go-rawurlparser v0.0.0-20241101212355-a74dbff109f7/go.mod h1:xUf2JAg8Wkk4L26ByKhkAcqBeHzDdQ+m2QPZAY+g7y4=
162164
github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo=
163165
github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo=
164166
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=

nomore403.exe

12.5 MB
Binary file not shown.

0 commit comments

Comments
 (0)