From c631e86b9aa7c867274cc6c430baaf4c77364460 Mon Sep 17 00:00:00 2001 From: mxd Date: Sun, 17 May 2026 11:46:42 +0800 Subject: [PATCH] add ngx_http_uploadprogress_module --- README.md | 22 + ngx_http_uploadprogress_module/CHANGES | 115 ++ ngx_http_uploadprogress_module/LICENSE | 25 + ngx_http_uploadprogress_module/Makefile | 8 + ngx_http_uploadprogress_module/README | 329 +++ ngx_http_uploadprogress_module/config | 11 + .../ngx_http_uploadprogress_module.c | 1772 +++++++++++++++++ ngx_http_uploadprogress_module/test/100 | Bin 0 -> 102400 bytes ngx_http_uploadprogress_module/test/client.sh | 8 + ngx_http_uploadprogress_module/test/stress.sh | 41 + 10 files changed, 2331 insertions(+) create mode 100644 ngx_http_uploadprogress_module/CHANGES create mode 100644 ngx_http_uploadprogress_module/LICENSE create mode 100644 ngx_http_uploadprogress_module/Makefile create mode 100644 ngx_http_uploadprogress_module/README create mode 100644 ngx_http_uploadprogress_module/config create mode 100644 ngx_http_uploadprogress_module/ngx_http_uploadprogress_module.c create mode 100644 ngx_http_uploadprogress_module/test/100 create mode 100644 ngx_http_uploadprogress_module/test/client.sh create mode 100644 ngx_http_uploadprogress_module/test/stress.sh diff --git a/README.md b/README.md index 493e14e..bc80102 100644 --- a/README.md +++ b/README.md @@ -155,4 +155,26 @@ This module is recommended to be built statically because it interacts closely w ### License +BSD 2-Clause License. + +--- + +## ngx_http_uploadprogress_module + +nginx_uploadprogress_module is an implementation of an upload progress system, that monitors +RFC1867 POST upload as they are transmitted to upstream servers. + +### Build + +```bash +./configure \ + --add-dynamic-module=/path/to/ngx_http_uploadprogress_module +``` + +### Notes + +when compiled with --with-debug, this module will produce high number of log messages. + +### License + BSD 2-Clause License. \ No newline at end of file diff --git a/ngx_http_uploadprogress_module/CHANGES b/ngx_http_uploadprogress_module/CHANGES new file mode 100644 index 0000000..ca2dc25 --- /dev/null +++ b/ngx_http_uploadprogress_module/CHANGES @@ -0,0 +1,115 @@ +nginx_upload_progress release 0.9.3 29 Jun 2024 + +* Allow to build with recent nginx versions + +nginx_upload_progress release 0.9.2 03 Aug 2016 + + * Allow to build as an externally loadable module (thanks to Peter Tonoli). + +nginx_upload_progress release 0.9.0 06 Apr 2012 + + * INCOMPATIBLE CHANGE: JSONP is now the default output for nginx upload + progress module. To restore the old behavior, add: + upload_progress_java_output + to your nginx configuration (thanks to drewbuschhorn for this work). + + * Add instructions in the README on how to use this module with JQuery + AJAX. + +nginx_upload_progress release 0.8.4 24 Feb 2012 + + * Fix compatibility with nginx 1.1.15 + +nginx_upload_progress release 0.8.3 11 Sep 2011 + + * HTTP redirects (ie 3xx range) shouldn't be reported as an error (thanks to + Pierre-Yves Kerembellec) + + * Fix a double remove in the rb tree due to an uninitialized flag (thanks to + Theo Cushion) + +nginx_upload_progress release 0.8.2 07 Nov 2010 + + * Session ID query string parameter name is now configurable (thanks to + Pierre-Yves Kerembellec) + +nginx_upload_progress release 0.8.1 27 Feb 2010 + + * Fixed find_node so that it can find correctly nodes when there is an + hash collision (thanks to Markus Doppelbauer for his detailed bug report + and test case). + +nginx_upload_progress release 0.8 19 Dec 2009 + + * fixed segfault at start on some platforms (reported by Vladimir + Getmanshchuk and Denis Denisenko) + + * implemented JSONP output (thanks to Bruno Deferrari) + + * X-Progress-ID can now be the last parameter in the request (thanks to + Bruno Deferrari) + +nginx_upload_progress release 0.7 21 Nov 2009 + + * fixed segfault when uploads are aborted (thanks to Markus Doppelbauer for + his bug report) + + * session ID header name is now configurable (thanks to Valery Kholodkov) + + * Added directive to format output as pure json (thanks to Valery Kholodkov) + + * Added directive to format output with configurable template (thanks to + Valery Kholodkov) + + * Added directive to set a probe response content-type (thanks to Valery + Kholodkov) + + * Added upload status variables (needs a status patch) (thanks to Valery + Kholodkov) + +nginx_upload_progress release 0.6 12 Sep 2009 + + * fixed node corruption when cleaning uploads (thanks to Vladimir + Getmanshchuk for his detailed report) + +nginx_upload_progress release 0.5 28 Jun 2008 + + * fixed progress probes returning "done" when upload was still in progress + (thanks to Alexandr Kutuzov for his detailed report) + + * fixed stuck worker process because of rescheduled timer when issuing a + reload or graceful quit (thanks to Alexandr Kutuzov for his detailed + report) + +nginx_upload_progress release 0.4 18 May 2008 + + * Incompatible change: track_uploads MUST be the last directive of a location + it also must be in a proxy_pass or fastcgi_pass location. + + * fixed multiple worker_process issue + + * fixed several crash conditions + +nginx_upload_progress release 0.3 06 May 2008 + + * fixed crash if the upload was denied by nginx because of any error + condition (thanks to Michal Drapiewski for his detailed report) + + * report original upload error condition to client in the upload progress + probe + + * case-insensitive checking of the X-Progress-ID header to overcome Internet + Explorer XMLHttpRequest issue. + +nginx_upload_progress release 0.2 10 Oct 2007 + + * the system now remembers old active uploads for 1 minute to be + able to send back either error status or done status to upload + progress probes. + + * track of HTTP error 413 (request entity too large) is implemented + and the error status '413' is returned. + +nginx_upload_progress release 0.1 3 Oct 2007 + + * public release diff --git a/ngx_http_uploadprogress_module/LICENSE b/ngx_http_uploadprogress_module/LICENSE new file mode 100644 index 0000000..9dd8c0d --- /dev/null +++ b/ngx_http_uploadprogress_module/LICENSE @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2007 Brice FIGUREAU + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ diff --git a/ngx_http_uploadprogress_module/Makefile b/ngx_http_uploadprogress_module/Makefile new file mode 100644 index 0000000..96730d9 --- /dev/null +++ b/ngx_http_uploadprogress_module/Makefile @@ -0,0 +1,8 @@ +dist: CHANGES README LICENSE config ngx_http_uploadprogress_module.c + tar czvf ../nginx_uploadprogress_module-0.7.tar.gz \ + ../nginx_uploadprogress_module/CHANGES \ + ../nginx_uploadprogress_module/README \ + ../nginx_uploadprogress_module/LICENSE \ + ../nginx_uploadprogress_module/config \ + ../nginx_uploadprogress_module/ngx_http_uploadprogress_module.c + diff --git a/ngx_http_uploadprogress_module/README b/ngx_http_uploadprogress_module/README new file mode 100644 index 0000000..addd6cc --- /dev/null +++ b/ngx_http_uploadprogress_module/README @@ -0,0 +1,329 @@ +Nginx Upload Progress Module +============================ + +Introduction +============ + +nginx_uploadprogress_module is an implementation of an upload progress system, that monitors +RFC1867 POST upload as they are transmitted to upstream servers. + +It works by tracking the uploads proxied by Nginx to upstream servers without +analysing the uploaded content and offers a web API to report upload progress in Javscript, Json or any +other format (through the help of templates). + +It works because Nginx acts as an accelerator of an upstream server, storing uploaded POST content +on disk, before transmitting it to the upstream server. Each individual POST upload request +should contain a progress unique identifier. + +This module is Copyright (c) 2007-2012 Brice Figureau, and is licensed under the BSD license (see LICENSE). + * rbtree and shm_zone code is based on Igor Sysoev limit_zone Nginx module. + * expire header code is based on Igor Sysoev header_filter Nginx module. + +The JSON idea and the mechanism idea are based on Lighttpd mod_uploadprogress: +http://blog.lighttpd.net/articles/2006/08/01/mod_uploadprogress-is-back + + +WARNING: + * when compiled with --with-debug, this module will produce high number of log messages. + +INCOMPATIBLE CHANGES +==================== + +v0.9.0: + +JSONP is now the default output of the progress probes. If you rely on this module serving +the deprecated java output use: + upload_progress_java_output +in the progress probe location. + + +Installation +============ + +nginx_uploadprogress_module has been tested with Nginx 0.6.x, 0.7.x, 0.8.x and 1.0.x. + +Download the Nginx sources from http://nginx.net/ and unpack it. + +To build Nginx, change to the directory which contains the Nginx +sources, and run the configuration script making sure to add the path +to the nginx_uploadprogress_module sources using the --add-module option: :: + + $ ./configure --add-module=/path/to/nginx_uploadprogress_module/ + +Now you can build and install the software: + + $ make + +and as root: + + $ make install + + +Configuration +============= + +Each upload request should be assigned a unique identifier. This unique identifier will be used +to store the request and reference it to report. +This identifier can be transmitted either as a GET argument or as an HTTP header whose name is X-Progress-ID. + +upload_progress ++++++++++++++++ + :Syntax: upload_progress + :Default: none + :Context: http + :Description: + This directive enables the upload progress module and reserve bytes to the which + will be used to store the per-connection tracking information. + +track_uploads ++++++++++++++ + :Syntax: track_uploads + :Default: none + :Context: location + :Description: + This directive enables tracking uploads for the current location. Each POST landing in this location will register + the request in the upload progress tracker. + Since Nginx doesn't support yet RFC 1867 upload, the location must be a proxy_pass or fastcgi location. + The POST _must_ have a query parameter called X-Progress-ID (or an HTTP header of the same name) whose value is the + unique identifier used to get progress information. If the POST has no such information, the upload will not be tracked. + The tracked connections are kept at most seconds after they have been finished to be able to serve + useful information to upload progress probes. + WARNING: this directive must be the last directive of the location. It must be in a proxy_pass or + fastcgi_pass location. + +report_uploads +++++++++++++++ + :Syntax: report_uploads + :Default: none + :Context: location + :Description: + This directive allows a location to report the upload progress that is tracked by track_uploads for . + The returned document is a Javascript text with the possible 4 results by default: + * the upload request hasn't been registered yet or is unknown: + new Object({ 'state' : 'starting' }) + + * the upload request has ended: + new Object({ 'state' : 'done' }) + + * the upload request generated an HTTP error + new Object({ 'state' : 'error', 'status' : }) + one error code that can be of use to track for the client is 413 (request entity too large). + + * the upload request is in progress: + new Object({ 'state' : 'uploading', 'received' : , 'size' : }) + + It is possible to return pure json instead of this javascript (see upload_progress_json_output). + It is also possible to configure completely the response format with the directive: + upload_progress_template + + The HTTP request to this location must have a X-Progress-ID parameter or HTTP header containing a valid + unique identifier of an in progress upload. + +upload_progress_content_type +++++++++++++++++++++++++++++ + :Syntax: upload_progress_content_type + :Default: text/javascript + :Context: location + :Description: + This directive allows to change the upload progress probe response content-type. + +upload_progress_header +++++++++++++++++++++++ + :Syntax: upload_progress_header + :Default: X-Progress-ID + :Context: location + :Description: + This directive allows to change the header name of the progress ID. + +upload_progress_jsonp_parameter +++++++++++++++++++++++ + :Syntax: upload_progress_jsonp_parameter + :Default: callback + :Context: location + :Description: + This directive allows to change the name of the GET parameter with the jsonp callback name. + +upload_progress_java_output ++++++++++++++++++++++++++++ + :Syntax: upload_progress_java_output + :Default: N/A + :Context: location + :Description: + This directive sets everything to output as eval() javascript compatible code. + +upload_progress_json_output ++++++++++++++++++++++++++++ + :Syntax: upload_progress_json_output + :Default: N/A + :Context: location + :Description: + This directive sets everything to output as pure json. + +upload_progress_jsonp_output +++++++++++++++++++++++++++++ + :Syntax: upload_progress_jsonp_output + :Default: N/A + :Context: location + :Description: + This directive sets everything to output as jsonp (like json output, but with callback). + +upload_progress_template +++++++++++++++++++++++++ + :Syntax: upload_progress_template