1

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

0 Answers0