1

A user is able to upload a file. During the upload the file is scanned. If there is an issue with the file Symfony returns a Response(400) and the rest of the file is not uploaded, saving the user and the host time and bandwidth.

This is done via \Symfony\Component\HttpFoundation\Request::getContent(true)

$resource = $request->getContent(true);

The file is scanned a line at a time using:

fgets($resource);

The resource is also closed before the response is sent to the user:

fclose($resource);

However there is unexpected and strange behaviour happening for some user clients.

For example wget:

wget -4 --no-check-certificate   --method PUT   --timeout=0   --header 'Authorization: Bearer xxx'   --body-file='xxx'    'https://example.com/xxx' --content-on-error -d -O -

Response hangs:

---request begin---
PUT /xxx HTTP/1.1
User-Agent: Wget/1.20.3 (linux-gnu)
Accept: */*
Accept-Encoding: identity
Host: xxx
Connection: Keep-Alive
Content-Length: 37767602
Authorization: Bearer xxx

---request end---
[writing BODY file xxx ... 

It appears that wget does not understand the upload does not need to be completed, is this a header that php is failing to send or a flag required in the wget command?

A similar command in curl works

curl -k --location --request PUT 'https://example.com/xxx' \
--header 'Authorization: Bearer xxx' \
--data-binary '@/xxx'

Response

< Server: Apache/2.4.38 (Debian)
< Vary: Authorization
< X-Robots-Tag: noindex
< Transfer-Encoding: chunked
* HTTP error before end of send, stop sending
< 
* Closing connection 0
* TLSv1.3 (OUT), TLS alert, close notify (256):
lookbadgers
  • 988
  • 9
  • 31

0 Answers0