From 893842d058f03e53fd59499c5f57ecd01e6dbd13 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Sun, 13 Nov 2011 12:42:30 -0500 Subject: [PATCH] upload progress bar hook --- cgi.d | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cgi.d b/cgi.d index b19813c..8777cf8 100644 --- a/cgi.d +++ b/cgi.d @@ -281,6 +281,7 @@ class Cgi { // And it has worked reliably for me all year in the live environment, // but some servers might be different. int contentLength = to!int(getenv("CONTENT_LENGTH")); + immutable originalContentLength = contentLength; if(contentLength) { if(maxContentLength > 0 && contentLength > maxContentLength) { setResponseStatus("413 Request entity too large"); @@ -301,6 +302,8 @@ class Cgi { } if(contentLength == 0) break; + + onRequestBodyDataReceived(data.length, originalContentLength); } else { // we have a custom data source.. @@ -319,8 +322,10 @@ class Cgi { break; chunk = readdata(); + onRequestBodyDataReceived(data.length, originalContentLength); } } + onRequestBodyDataReceived(data.length, originalContentLength); } version(preserveData) @@ -331,6 +336,23 @@ class Cgi { // fixme: remote_user script name } + /// you can override this function to somehow react + /// to an upload in progress. + /// + /// Take note that most of the CGI object is not yet + /// initialized! Stuff from HTTP headers, in raw form, is usable. + /// Stuff processed from them (such as get[]!) is not. + /// + /// In the current implementation, you can't even look at partial + /// post. My idea here was so you can output a progress bar or + /// something to a cooperative client. + /// + /// The default is to do nothing. Subclass cgi and use the + /// CustomCgiMain mixin to do something here. + void onRequestBodyDataReceived(size_t receivedSoFar, size_t totalExpected) { + // This space intentionally left blank. + } + /** Initializes it from some almost* raw HTTP request data headers[0] should be the "GET / HTTP/1.1" line @@ -872,6 +894,7 @@ class Cgi { void flush() { if(rawDataOutput is null) stdout.flush(); + // FIXME: also flush to other sources } version(autoBuffer)