mirror of https://github.com/adamdruppe/arsd.git
upload progress bar hook
This commit is contained in:
parent
142790636a
commit
893842d058
23
cgi.d
23
cgi.d
|
@ -281,6 +281,7 @@ class Cgi {
|
||||||
// And it has worked reliably for me all year in the live environment,
|
// And it has worked reliably for me all year in the live environment,
|
||||||
// but some servers might be different.
|
// but some servers might be different.
|
||||||
int contentLength = to!int(getenv("CONTENT_LENGTH"));
|
int contentLength = to!int(getenv("CONTENT_LENGTH"));
|
||||||
|
immutable originalContentLength = contentLength;
|
||||||
if(contentLength) {
|
if(contentLength) {
|
||||||
if(maxContentLength > 0 && contentLength > maxContentLength) {
|
if(maxContentLength > 0 && contentLength > maxContentLength) {
|
||||||
setResponseStatus("413 Request entity too large");
|
setResponseStatus("413 Request entity too large");
|
||||||
|
@ -301,6 +302,8 @@ class Cgi {
|
||||||
}
|
}
|
||||||
if(contentLength == 0)
|
if(contentLength == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
onRequestBodyDataReceived(data.length, originalContentLength);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// we have a custom data source..
|
// we have a custom data source..
|
||||||
|
@ -319,8 +322,10 @@ class Cgi {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
chunk = readdata();
|
chunk = readdata();
|
||||||
|
onRequestBodyDataReceived(data.length, originalContentLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onRequestBodyDataReceived(data.length, originalContentLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
version(preserveData)
|
version(preserveData)
|
||||||
|
@ -331,6 +336,23 @@ class Cgi {
|
||||||
// fixme: remote_user script name
|
// 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
|
/** Initializes it from some almost* raw HTTP request data
|
||||||
headers[0] should be the "GET / HTTP/1.1" line
|
headers[0] should be the "GET / HTTP/1.1" line
|
||||||
|
|
||||||
|
@ -872,6 +894,7 @@ class Cgi {
|
||||||
void flush() {
|
void flush() {
|
||||||
if(rawDataOutput is null)
|
if(rawDataOutput is null)
|
||||||
stdout.flush();
|
stdout.flush();
|
||||||
|
// FIXME: also flush to other sources
|
||||||
}
|
}
|
||||||
|
|
||||||
version(autoBuffer)
|
version(autoBuffer)
|
||||||
|
|
Loading…
Reference in New Issue