Symfony Request::getContent(true)在wget中异常但curl正常的问题
问题:WGET上传文件时收到400响应仍挂起,CURL却能正常终止上传?
背景
用Symfony实现文件上传功能,逻辑是上传时逐行扫描文件,一旦检测到文件存在问题,立即返回Response(400)并终止剩余文件上传,以此节省双方时间和带宽。该逻辑通过\Symfony\Component\HttpFoundation\Request::getContent(true)实现:
$resource = $request->getContent(true);
之后用fgets($resource)逐行扫描文件,在返回响应前会执行fclose($resource)关闭资源。
异常现象
部分客户端使用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 -
对应的响应状态日志:
---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 ...
WGET似乎没有识别到无需继续完成剩余上传,一直处于挂起状态。
正常情况
使用CURL执行类似上传命令时则能正常工作,命令如下:
curl -k --location --request PUT 'https://example.com/xxx' \ --header 'Authorization: Bearer xxx' \ --data-binary '@/xxx'
对应的响应信息:
< 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):
疑问
请问这种情况是PHP未及时发送响应头导致的,还是WGET需要添加特定参数才能识别并终止上传?
内容的提问来源于stack exchange,提问作者lookbadgers
相关产品推荐
相关产品推荐

