logging variables -- $bytes_sent .. where is $bytes_read ?

jb justinbeech at gmail.com
Sat Apr 18 00:24:17 UTC 2015


And maybe I am approaching this the wrong way? can you comment..

I want an nginx upload target for POST that reads the content, discards it,
and reports the amount read. This is what I have in essence:

location ~* "/upload" {
  limit_except POST OPTIONS { deny all; }
  client_max_body_size 0;
  add_header Cache-Control "max-age=0, no-cache, no-store, must-revalidate";
  keepalive_timeout 0;
  add_header Content-Type 'text/html';
  return 200 '$content_length bytes';
}

The uploads are being done with XHR on the browser side. It works, however
randomly (less than 1% of cases), browsers fail during the POST: they
return xhr with readyState 4 but status 0, and only a partial upload
progress recorded.
On the server side, no error is generated in error_log, and access_log
reports status 200.

$request_length is very short, just the header of the upload.

I am wondering if this is mis-use of upload handling by nginx. However I do
not want to setup an upstream server to receive the POST content, it is to
be discarded anyway.

Is there a more correct way to handle POST within nginx, with a response
after all data is read, but without an upstream server?

thanks.


On Sat, Apr 18, 2015 at 10:08 AM, jb <justinbeech at gmail.com> wrote:

> thanks and this is a popular answer on stack exchange but no, it does not
> work, because aborted requests have read less bytes -- $request_length
> reports how many bytes SHOULD have been read, but in the case of any
> problem, abort by client, or whatever, this is not how many bytes were
> actually read..
>
> For accounting purposes, I'd want an exact mirror to $bytes_sent ...
> otherwise math does not add up :( I think there should be a $bytes_recd ..
>
> On Sat, Apr 18, 2015 at 9:47 AM, Valentin V. Bartenev <vbart at nginx.com>
> wrote:
>
>> On Saturday 18 April 2015 08:23:37 jb wrote:
>> > Is there a variable for bytes read ?
>> >
>> > $content_length is what should be read, but if the request is terminated
>> > early, it is wrong.
>> > $request_length is not right either, it is logging 459 bytes on a 9mb
>> > upload.
>> >
>>
>> $request_length should work.
>>
>>   wbr, Valentin V. Bartenev
>>
>> _______________________________________________
>> nginx mailing list
>> nginx at nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20150418/0e52515e/attachment.html>


More information about the nginx mailing list