You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// opts := retryablehttp.DefaultOptionsSingle // use single options for single host
20
-
client:= retryablehttp.NewClient(opts)
21
-
resp, err:= client.Get("https://example.com")
22
-
if err != nil {
23
-
panic(err)
24
-
}
25
-
defer resp.Body.Close()
26
-
27
-
data, err:= io.ReadAll(resp.Body)
28
-
if err != nil {
29
-
panic(err)
30
-
}
31
-
fmt.Printf("Data: %v\n", string(data))
32
-
}
7
+
Example of using `retryablehttp` in Go Code is available in [examples](examples/) folder
8
+
Examples of using Nuclei From Go Code to run templates on targets are provided in the examples folder.
9
+
10
+
11
+
12
+
13
+
### url encoding and parsing issues
14
+
15
+
`retryablehttp.Request` by default handles some [url encoding and parameters issues](https://github.com/projectdiscovery/utils/blob/main/url/README.md). since `http.Request` internally uses `url.Parse()` to parse url specified in request it creates some inconsistencies for below urls and other non-RFC compilant urls
16
+
17
+
```
18
+
// below urls are either normalized or returns error when used in `http.NewRequest()`
19
+
https://scanme.sh/%invalid
20
+
https://scanme.sh/w%0d%2e/
21
+
scanme.sh/with/path?some'param=`'+OR+ORDER+BY+1--
33
22
```
23
+
All above mentioned cases are handled internally in `retryablehttp`.
24
+
25
+
26
+
### request with unsafe urls
27
+
28
+
`retryablehttp` allows creating requests with unsafe urls but requires some extra steps if `path` of url contains encoded characters (ex: `/%invalid/path`).
29
+
30
+
-`Request.Prepare()` method should be called before request is executed and this applies a quick fix to avoid double url encoding (ex: `%e5` => `%25e5`)
31
+
32
+
Note: this is a optional feature and only required if we want to allow unsafe urls. If `Request.Prepare()` is not called it follows the standard behaviour.
33
+
34
+
### Note
35
+
It is not recommended to update `url.URL` instance of `Request` once a new request is created (ex `req.URL.Path = xyz`) due to internal logic or urls.
36
+
In any case if it is not possible to follow above point due to some reason helper methods are available to reflect such changes
37
+
38
+
-`Request.Update()` commits any changes made to query parameters (ex: `Request.URL.Query().Add(x,y)`)
0 commit comments