Description
I ran across this strange thing with the latest build.
xcaddy and go versions:
v0.3.2 h1:Y1QPKq97GrSG6ryMhGTw1g9GHH8wRmwnCzOcN+f+gCY=
go version go1.20.1 linux/amd64
This is the test Caddyfile I am using:
{
http_port 9000
https_port 9001
admin off
order upload before file_server
}
localhost:9000 {
root .
file_server browse
templates
@mypost method POST
upload @mypost {
dest_dir .
max_filesize 15G
max_form_buffer 100MB
file_field_name myFile
response_template upload-resp-template.txt
}
log {
output file access.log
}
}
When I upload something, the file gets uploaded but I get error 405 Method Not Allowed returned:
user@654567547:/test$ curl -kv --form [email protected] http://localhost:9000/upload-template.htm
* Trying 127.0.0.1:9000...
* Connected to localhost (127.0.0.1) port 9000 (#0)
> POST /upload-template.htm HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.87.0
> Accept: */*
> Content-Length: 6607691
> Content-Type: multipart/form-data; boundary=------------------------f2ff797d6214e625
> Expect: 100-continue
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 405 Method Not Allowed
< Allow: GET, HEAD
< Server: Caddy
< Date: Wed, 22 Feb 2023 09:56:31 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact
This ends up in the access.log:
2023/02/22 09:56:31.049 error http.log.access.log0 handled request {"request": {"remote_ip": "127.0.0.1", "remote_port": "12854", "proto": "HTTP/1.1", "method": "POST", "host": "localhost:9000", "uri": "/upload-template.htm", "headers": {"User-Agent": ["curl/7.87.0"], "Accept": ["*/*"], "Content-Length": ["6607691"], "Content-Type": ["multipart/form-data; boundary=------------------------f2ff797d6214e625"], "Expect": ["100-continue"]}}, "user_id": "", "duration": 0.025178922, "size": 0, "status": 405, "resp_headers": {"Server": ["Caddy"], "Allow": ["GET, HEAD"]}}
When I use my previous caddy all seems to be fine and I get 200 OK:
user@654567547:/test$ curl -kv --form [email protected] http://localhost:9000/upload-template.htm
* Trying 127.0.0.1:9000...
* Connected to localhost (127.0.0.1) port 9000 (#0)
> POST /upload-template.htm HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.87.0
> Accept: */*
> Content-Length: 6607691
> Content-Type: multipart/form-data; boundary=------------------------15c7d37773cc1a35
> Expect: 100-continue
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Length: 197
< Content-Type: text/plain; charset=utf-8
< Server: Caddy
< Date: Wed, 22 Feb 2023 09:58:58 GMT
<
http.request.uri.path: /upload-resp-template.txt
http.request.uuid c92559ee-4533-417a-831e-825627512927
http.request.host localhost
http.upload.filename: chm.pdf
http.upload.filesize: 6607499
* Connection #0 to host localhost left intact
access.log:
2023/02/22 09:58:58.127 info http.log.access.log0 handled request {"request": {"remote_ip": "127.0.0.1", "remote_port": "38812", "proto": "HTTP/1.1", "method": "POST", "host": "localhost:9000", "uri": "/upload-template.htm", "headers": {"User-Agent": ["curl/7.87.0"], "Accept": ["*/*"], "Content-Length": ["6607691"], "Content-Type": ["multipart/form-data; boundary=------------------------15c7d37773cc1a35"], "Expect": ["100-continue"]}}, "user_id": "", "duration": 0.023929111, "size": 197, "status": 200, "resp_headers": {"Server": ["Caddy"], "Content-Type": ["text/plain; charset=utf-8"], "Content-Length": ["197"]}}
It seems to me in the new build something hardcodes the Allow methods to GET, HEAD as seen in both the access.log and the curl output which is rather strange. If I edit the Caddyfile like so:
{
http_port 9000
https_port 9001
admin off
order upload before file_server
}
localhost:9000 {
root .
header Allow "GET, POST, HEAD"
file_server browse
templates
@mypost method POST
upload @mypost {
dest_dir .
max_filesize 15G
max_form_buffer 100MB
file_field_name myFile
response_template upload-resp-template.txt
}
log {
output file access.log
}
}
In vain attempt to override it this is what I get:
user@654567547:/test$ curl -kv --form [email protected] http://localhost:9000/upload-template.htm
* Trying 127.0.0.1:9000...
* Connected to localhost (127.0.0.1) port 9000 (#0)
> POST /upload-template.htm HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.87.0
> Accept: */*
> Content-Length: 6607691
> Content-Type: multipart/form-data; boundary=------------------------6e97f114df50b981
> Expect: 100-continue
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 405 Method Not Allowed
< Allow: GET, POST, HEAD
< Allow: GET, HEAD
< Server: Caddy
< Date: Wed, 22 Feb 2023 10:07:50 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact
access.log:
2023/02/22 10:07:50.407 error http.log.access.log0 handled request {"request": {"remote_ip": "127.0.0.1", "remote_port": "19878", "proto": "HTTP/1.1", "method": "POST", "host": "localhost:9000", "uri": "/upload-template.htm", "headers": {"Content-Type": ["multipart/form-data; boundary=------------------------6e97f114df50b981"], "Expect": ["100-continue"], "User-Agent": ["curl/7.87.0"], "Accept": ["*/*"], "Content-Length": ["6607691"]}}, "user_id": "", "duration": 0.022846431, "size": 0, "status": 405, "resp_headers": {"Server": ["Caddy"], "Allow": ["GET, POST, HEAD", "GET, HEAD"]}}
Quite strange tbh. File gets uploaded in all cases but the return code is different and this header business puzzles me the most.
Shall I post this in https://github.com/caddyserver/caddy as an issue since I don't really think it is upload handler's fault as there weren't any underlining code changes ?