Skip to content

Commit b6c96cf

Browse files
authored
Merge pull request #28 from dclaisse/master
HTTP mirroring: add an option to follow HTTP redirections
2 parents 83aa285 + 5741fe5 commit b6c96cf

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ or
128128
{
129129
"type": "sink.http",
130130
"config": {
131+
"follow_redirects": true,
131132
"timeout": "1s",
132133
"target_url": "{req.meta.target.string}"
133134
}
@@ -136,11 +137,12 @@ or
136137

137138

138139

139-
| Param | Value |
140-
| ------------ | ----------------------------------------------------------- |
141-
| `target_url` | URL to send the requests to. The path in the URL is ignored |
142-
| `timeout` | Requests timeout. Ex: `1s`, `200ms`, `1m30s` |
143-
| `parallel` | How many requests to send in parallel. Default: 10 |
140+
| Param | Value |
141+
| ------------------ | ----------------------------------------------------------- |
142+
| `target_url` | URL to send the requests to. The path in the URL is ignored |
143+
| `timeout` | Requests timeout. Ex: `1s`, `200ms`, `1m30s` |
144+
| `parallel` | How many requests to send in parallel. Default: 10 |
145+
| `follow_redirects` | Follow HTTP redirections. Default: False |
144146

145147
#### sink.file
146148

mirror/modules/sink/http.go

+19-13
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ func init() {
4242
}
4343

4444
type HTTPConfig struct {
45-
TargetURL *expr.StringExpr `json:"target_url,omitempty"`
46-
Timeout string `json:"timeout,omitempty"`
47-
Parallel int `json:"parallel"`
45+
FollowRedirects bool `json:"follow_redirects,omitempty"`
46+
TargetURL *expr.StringExpr `json:"target_url,omitempty"`
47+
Timeout string `json:"timeout,omitempty"`
48+
Parallel int `json:"parallel"`
4849
}
4950

5051
type HTTP struct {
@@ -77,17 +78,22 @@ func NewHTTP(ctx *mirror.ModuleContext, cfg []byte) (mirror.Module, error) {
7778
maxWorkers = c.Parallel
7879
}
7980

81+
httpClient := &http.Client{
82+
Timeout: timeout,
83+
}
84+
85+
if !c.FollowRedirects {
86+
httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
87+
return http.ErrUseLastResponse
88+
}
89+
}
90+
8091
mod := &HTTP{
81-
ctx: ctx,
82-
cfg: c,
83-
out: make(chan mirror.Request),
84-
tasks: make(chan mirror.Request),
85-
client: &http.Client{
86-
CheckRedirect: func(req *http.Request, via []*http.Request) error {
87-
return http.ErrUseLastResponse
88-
},
89-
Timeout: timeout,
90-
},
92+
ctx: ctx,
93+
cfg: c,
94+
out: make(chan mirror.Request),
95+
tasks: make(chan mirror.Request),
96+
client: httpClient,
9197
maxWorkers: maxWorkers,
9298
}
9399
return mod, nil

0 commit comments

Comments
 (0)