@@ -25,6 +25,8 @@ type Upload struct {
25
25
DestDir string `json:"dest_dir,omitempty"`
26
26
MaxFilesize int64 `json:"max_filesize,omitempty"`
27
27
ResponseTemplate string `json:"response_template,omitempty"`
28
+ NotifyURL string `json:"notify_url,omitempty"`
29
+ NotifyMethod string `json:"notify_method,omitempty"`
28
30
29
31
ctx caddy.Context
30
32
logger * zap.Logger
@@ -65,7 +67,9 @@ func (u *Upload) Provision(ctx caddy.Context) error {
65
67
u .logger .Info ("Current Config" ,
66
68
zap .String ("Destinaton Directory (dest_dir)" , u .DestDir ),
67
69
zap .Int64 ("Max filesize in bytes (max_filesize)" , u .MaxFilesize ),
68
- zap .String ("Response Template (response_template)" , u .ResponseTemplate ))
70
+ zap .String ("Response Template (response_template)" , u .ResponseTemplate ),
71
+ zap .String ("Notify URL (notify_url)" , u .NotifyURL ),
72
+ )
69
73
70
74
return nil
71
75
}
@@ -85,16 +89,20 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
85
89
if ! requuiderr {
86
90
requuid = "0"
87
91
u .logger .Error ("http.request.uuid" ,
88
- zap .Bool ("requuiderr" , requuiderr ))
92
+ zap .Bool ("requuiderr" , requuiderr ),
93
+ zap .Object ("request" , caddyhttp.LoggableHTTPRequest {Request : r }))
89
94
}
90
95
96
+ repl .Set ("http.upload.max_filesize" , u .MaxFilesize )
97
+
91
98
r .Body = http .MaxBytesReader (w , r .Body , u .MaxFilesize )
92
99
if max_size_err := r .ParseMultipartForm (u .MaxFilesize ); max_size_err != nil {
93
100
u .logger .Error ("ServeHTTP" ,
94
101
zap .String ("Request uuid" , requuid ),
95
102
zap .String ("message" , "The uploaded file is too big. Please choose an file that's less than MaxFilesize." ),
96
103
zap .Int64 ("MaxFilesize in Bytes" , u .MaxFilesize ),
97
- zap .Error (max_size_err ))
104
+ zap .Error (max_size_err ),
105
+ zap .Object ("request" , caddyhttp.LoggableHTTPRequest {Request : r }))
98
106
return caddyhttp .Error (http .StatusRequestEntityTooLarge , max_size_err )
99
107
}
100
108
@@ -106,7 +114,8 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
106
114
u .logger .Error ("FormFile Error" ,
107
115
zap .String ("Request uuid" , requuid ),
108
116
zap .String ("message" , "Error Retrieving the File" ),
109
- zap .Error (ff_err ))
117
+ zap .Error (ff_err ),
118
+ zap .Object ("request" , caddyhttp.LoggableHTTPRequest {Request : r }))
110
119
return caddyhttp .Error (http .StatusInternalServerError , ff_err )
111
120
}
112
121
defer file .Close ()
@@ -119,7 +128,8 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
119
128
u .logger .Error ("TempFile Error" ,
120
129
zap .String ("Request uuid" , requuid ),
121
130
zap .String ("message" , "Error at TempFile" ),
122
- zap .Error (tmpf_err ))
131
+ zap .Error (tmpf_err ),
132
+ zap .Object ("request" , caddyhttp.LoggableHTTPRequest {Request : r }))
123
133
return caddyhttp .Error (http .StatusInternalServerError , tmpf_err )
124
134
}
125
135
defer tempFile .Close ()
@@ -131,7 +141,8 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
131
141
u .logger .Error ("ReadAll Error" ,
132
142
zap .String ("Request uuid" , requuid ),
133
143
zap .String ("message" , "Error at ReadAll" ),
134
- zap .Error (io_err ))
144
+ zap .Error (io_err ),
145
+ zap .Object ("request" , caddyhttp.LoggableHTTPRequest {Request : r }))
135
146
return caddyhttp .Error (http .StatusInternalServerError , io_err )
136
147
}
137
148
// write this byte array to our temporary file
@@ -141,7 +152,8 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
141
152
zap .String ("Request uuid" , requuid ),
142
153
zap .String ("Uploaded File" , handler .Filename ),
143
154
zap .Int64 ("File Size" , handler .Size ),
144
- zap .Any ("MIME Header" , handler .Header ))
155
+ zap .Any ("MIME Header" , handler .Header ),
156
+ zap .Object ("request" , caddyhttp.LoggableHTTPRequest {Request : r }))
145
157
146
158
repl .Set ("http.upload.filename" , handler .Filename )
147
159
repl .Set ("http.upload.filesize" , handler .Size )
@@ -150,6 +162,9 @@ func (u Upload) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp
150
162
r .URL .Path = "/" + u .ResponseTemplate
151
163
}
152
164
165
+ if u .NotifyURL != "" {
166
+ u .SendNotify ()
167
+ }
153
168
return next .ServeHTTP (w , r )
154
169
}
155
170
0 commit comments