bug in embedded_http if headers and content are in separate packets

This commit is contained in:
Adam D. Ruppe 2015-08-04 23:18:37 -04:00
parent baa5926a62
commit c0bc728df0
1 changed files with 21 additions and 4 deletions

25
cgi.d
View File

@ -920,6 +920,8 @@ class Cgi {
// file stuff I'm sure is inefficient. But, my guess is the real bottleneck is network // file stuff I'm sure is inefficient. But, my guess is the real bottleneck is network
// input anyway, so I'm not going to get too worked up about it right now. // input anyway, so I'm not going to get too worked up about it right now.
protected void handleIncomingDataChunk(const(ubyte)[] chunk) { protected void handleIncomingDataChunk(const(ubyte)[] chunk) {
if(chunk.length == 0)
return;
assert(chunk.length <= 32 * 1024 * 1024); // we use chunk size as a memory constraint thing, so assert(chunk.length <= 32 * 1024 * 1024); // we use chunk size as a memory constraint thing, so
// if we're passed big chunks, it might throw unnecessarily. // if we're passed big chunks, it might throw unnecessarily.
// just pass it smaller chunks at a time. // just pass it smaller chunks at a time.
@ -1222,6 +1224,9 @@ class Cgi {
// simple handling, but it works... until someone bombs us with gigabytes of crap at least... // simple handling, but it works... until someone bombs us with gigabytes of crap at least...
if(pps.buffer.length == pps.expectedLength) if(pps.buffer.length == pps.expectedLength)
pps._post = decodeVariables(cast(string) pps.buffer); pps._post = decodeVariables(cast(string) pps.buffer);
else {
// just for debugging
}
} }
} }
@ -1479,8 +1484,9 @@ class Cgi {
if(contentLength) { if(contentLength) {
prepareForIncomingDataChunks(contentType, contentLength); prepareForIncomingDataChunks(contentType, contentLength);
foreach(dataChunk; dataByChunk) foreach(dataChunk; dataByChunk) {
handleIncomingDataChunk(dataChunk); handleIncomingDataChunk(dataChunk);
}
postArray = assumeUnique(pps._post); postArray = assumeUnique(pps._post);
filesArray = assumeUnique(pps._files); filesArray = assumeUnique(pps._files);
files = keepLastOf(filesArray); files = keepLastOf(filesArray);
@ -3130,10 +3136,11 @@ class BufferedInputRange {
You can also specify 0, to append to the buffer, or any other number You can also specify 0, to append to the buffer, or any other number
to remove the front n bytes and wait for more. to remove the front n bytes and wait for more.
*/ */
void popFront(size_t maxBytesToConsume = 0 /*size_t.max*/, size_t minBytesToSettleFor = 0) { void popFront(size_t maxBytesToConsume = 0 /*size_t.max*/, size_t minBytesToSettleFor = 0, bool skipConsume = false) {
if(sourceClosed) if(sourceClosed)
throw new Exception("can't get any more data from a closed source"); throw new Exception("can't get any more data from a closed source");
consume(maxBytesToConsume); if(!skipConsume)
consume(maxBytesToConsume);
// we might have to grow the buffer // we might have to grow the buffer
if(minBytesToSettleFor > underlyingBuffer.length || view.length == underlyingBuffer.length) { if(minBytesToSettleFor > underlyingBuffer.length || view.length == underlyingBuffer.length) {
@ -3178,8 +3185,15 @@ class BufferedInputRange {
/// consume some. /// consume some.
ubyte[] consume(size_t bytes) { ubyte[] consume(size_t bytes) {
view = view[bytes > $ ? $ : bytes .. $]; view = view[bytes > $ ? $ : bytes .. $];
if(view.length == 0) if(view.length == 0) {
view = underlyingBuffer[0 .. 0]; // go ahead and reuse the beginning view = underlyingBuffer[0 .. 0]; // go ahead and reuse the beginning
/*
writeln("HERE");
popFront(0, 0, true); // try to load more if we can, checks if the source is closed
writeln(cast(string)front);
writeln("DONE");
*/
}
return front; return front;
} }
@ -3603,6 +3617,9 @@ ByChunkRange byChunk(BufferedInputRange ir, size_t atMost) {
a = ir.consume(a.length); a = ir.consume(a.length);
if(atMost != 0) if(atMost != 0)
ir.popFront(); ir.popFront();
if(f.length == 0) {
f = ir.front();
}
} else { } else {
// we actually have *more* here than we need.... // we actually have *more* here than we need....
f = a[0..atMost]; f = a[0..atMost];