Skip to content

Commit

Permalink
Handle Content-Length header for responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccutrer committed Apr 10, 2009
1 parent 662eb5f commit 6c0cf62
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion mordor/common/http/client.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import mordor.common.http.parser;
import mordor.common.scheduler;
import mordor.common.streams.buffered;
import mordor.common.streams.duplex;
import mordor.common.streams.limited;
import mordor.common.streams.singleplex;
import mordor.common.streams.singleplexer;
import mordor.common.streams.stream;
Expand Down Expand Up @@ -191,7 +192,7 @@ class Connection
}

Response responseHeaders;
Stream responseStream = _stream;
Stream responseStream;
// Read and parse headers
scope parser = new ResponseParser(responseHeaders);
parser.init();
Expand Down Expand Up @@ -229,6 +230,23 @@ class Connection
} else {
throw new Exception("Unrecognized HTTP server version.");
}
if (cast(int)status.status >= 100 && cast(int)status.status <= 199 ||
cast(int)status.status == 204 ||
cast(int)status.status == 304 ||
requestHeaders.requestLine.method == Method.HEAD) {
// no entity
} else {
responseStream = new SingleplexStream(_stream, SingleplexStream.Type.READ, false);
// TODO: transfer encoding
if (entity.contentLength != ~0) {
responseStream = new LimitedStream(responseStream, entity.contentLength);
} else {
if (!close) {
_log.warn("Server indicated persistent connection, but has no way to delimit the message; closing");
close = true;
}
}
}
}
response(responseHeaders, responseStream);

Expand Down

0 comments on commit 6c0cf62

Please sign in to comment.