Skip to content

Commit 229dfcb

Browse files
authored
feat: add pass_thru mode to continue to next handler instead of replying directly (#23)
Thank you @adrienyhuel for contributing. Merged now
1 parent 256822c commit 229dfcb

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

README.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ The default size is **1G**.
102102
|**dest_dir_field_name**
103103
|If set, the dest_dir will be set from the specified form value.
104104

105+
|**pass_thru**
106+
|If set to `true`, enables pass-thru mode, which continues to the next HTTP handler in the route instead of responding directly.
107+
105108
|===
106109

107110
=== Caddy Variables

caddyfile.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ func (u *Upload) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
107107
if !d.Args(&u.DestDirFieldName) {
108108
return d.ArgErr()
109109
}
110+
case "pass_thru":
111+
var passThruStr string
112+
if !d.AllArgs(&passThruStr) {
113+
return d.ArgErr()
114+
}
115+
passThruBool, err := strconv.ParseBool(passThruStr)
116+
if err != nil {
117+
return d.Errf("parsing pass_thru: %v", err)
118+
}
119+
u.PassThru = passThruBool
110120
default:
111121
return d.Errf("unrecognized servers option '%s'", d.Val())
112122
}

upload.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Upload struct {
4040
NotifyMethod string `json:"notify_method,omitempty"`
4141
CreateUuidDir bool `json:"create_uuid_dir,omitempty"`
4242
DestDirFieldName string `json:"dest_dir_field_name,omitempty"`
43+
PassThru bool `json:"pass_thru,omitempty"`
4344

4445
MyTlsSetting struct {
4546
InsecureSkipVerify bool `json:"insecure,omitempty"`
@@ -173,6 +174,7 @@ func (u *Upload) Provision(ctx caddy.Context) error {
173174
zap.String("capath", u.MyTlsSetting.CAPath),
174175
zap.Bool("insecure", u.MyTlsSetting.InsecureSkipVerify),
175176
zap.String("dest_dir_field_name", u.DestDirFieldName),
177+
zap.Bool("pass_thru", u.PassThru),
176178
)
177179

178180
return nil
@@ -326,6 +328,10 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
326328
}
327329
}
328330

331+
if u.PassThru {
332+
return next.ServeHTTP(w, r)
333+
}
334+
329335
if u.ResponseTemplate != "" {
330336

331337
fileRespTemplate, fRTErr := os.Open(caddyhttp.SanitizedPathJoin(u.RootDir, u.ResponseTemplate))

0 commit comments

Comments
 (0)