Processing multipart/form-data in Perl invokes Apache-error with Apple-devices, when a form-file-element is empty

萝らか妹 提交于 2019-12-11 09:52:03

问题


My application is written in Perl 5.14.2. I process multipart/form-data with

use CGI;
$query = new CGI;

Since a few weeks this process invokes a timeout at Apache-level on specific Apple-devices:

(70007)The timeout specified has expired: Error reading request entity data

The apple-devices that invoke the timeout-error all do have Applewebkit/605 in common. This is mostly a Safari browser version 11 on a Mac.

The formdata is send through:

var fData = new FormData($('#myForm')[0]);

jQuery.ajax({
    url: '/urladdress',
    data: fData,
    cache: false,
    dataType: 'html',
    contentType: false,
    processData: false,
    type: 'POST'
});

I found out that the problem occurs when the formdata contains elements of type 'file' that are empty (no file provided). The problem doesn't depend on the use of CGI or CGI::Simple. Even just trying to get the STDIN-buffer initiates the error.

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

The workaround is removing empty file-elements of the <form> and thus the formdata before assigning the formdata:

$('#myForm').find("input[type='file']").each(function(){
    if ($(this).get(0).files.length === 0) {$(this).remove();}
});
var fData = new FormData($('#myForm')[0]);
...

The bug seems to be known since April, 11 2018
https://bugs.webkit.org/show_bug.cgi?id=184490

And it seems it has already been reported here at Stackoverflow
Safari 11.1: ajax/XHR form submission fails when input[type=file] is empty

来源:https://stackoverflow.com/questions/50040739/processing-multipart-form-data-in-perl-invokes-apache-error-with-apple-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!