Skip to content

Commit

Permalink
Merge pull request #1833 from rejectedsoftware/bigger_osr_chunks
Browse files Browse the repository at this point in the history
Use larger streamOutputRange chunk size in the HTTP package.
  • Loading branch information
s-ludwig authored Jul 11, 2017
2 parents ddbeb63 + ef3c234 commit 0980d1f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions http/vibe/http/client.d
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ final class HTTPClientRequest : HTTPRequest {
headers["Content-Length"] = clengthString(length);
}

auto rng = streamOutputRange(bodyWriter);
auto rng = streamOutputRange!1024(bodyWriter);
() @trusted { serializeToJson(&rng, data); } ();
rng.flush();
finalize();
Expand All @@ -756,7 +756,7 @@ final class HTTPClientRequest : HTTPRequest {
counter.formEncode(key_value_map);
headers["Content-Length"] = clengthString(length);
headers["Content-Type"] = "application/x-www-form-urlencoded";
auto dst = streamOutputRange(bodyWriter);
auto dst = streamOutputRange!1024(bodyWriter);
() @trusted { return &dst; } ().formEncode(key_value_map);
}

Expand Down Expand Up @@ -808,7 +808,7 @@ final class HTTPClientRequest : HTTPRequest {
assert(!m_headerWritten, "HTTPClient tried to write headers twice.");
m_headerWritten = true;

auto output = streamOutputRange(m_conn);
auto output = streamOutputRange!1024(m_conn);

formattedWrite(() @trusted { return &output; } (), "%s %s %s\r\n", httpMethodString(method), requestURL, getHTTPVersionString(httpVersion));
logTrace("--------------------");
Expand Down
6 changes: 3 additions & 3 deletions http/vibe/http/server.d
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void setVibeDistHost(string host, ushort port)
} else {
import vibe.stream.wrapper : streamOutputRange;
import diet.html : compileHTMLDietFile;
auto output = streamOutputRange(res.bodyWriter);
auto output = streamOutputRange!1024(res.bodyWriter);
compileHTMLDietFile!(template_file, ALIASES, DefaultFilters)(output);
}
}
Expand Down Expand Up @@ -1274,7 +1274,7 @@ final class HTTPServerResponse : HTTPResponse {
headers["Content-Length"] = formatAlloc(m_requestAlloc, "%d", length);
}

auto rng = streamOutputRange(bodyWriter);
auto rng = streamOutputRange!1024(bodyWriter);
static if (PRETTY) serializeToPrettyJson(() @trusted { return &rng; } (), data);
else serializeToJson(() @trusted { return &rng; } (), data);
}
Expand Down Expand Up @@ -1581,7 +1581,7 @@ final class HTTPServerResponse : HTTPResponse {

assert(!m_bodyWriter && !m_headerWritten, "Try to write header after body has already begun.");
m_headerWritten = true;
auto dst = StreamOutputRange!(InterfaceProxy!Stream)(m_conn);
auto dst = streamOutputRange!1024(m_conn);

void writeLine(T...)(string fmt, T args)
@safe {
Expand Down
8 changes: 4 additions & 4 deletions stream/vibe/stream/wrapper.d
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ struct StreamInputRange {
*/
StreamOutputRange!OutputStream StreamOutputRange()(OutputStream stream) { return StreamOutputRange!OutputStream(stream); }
/// ditto
struct StreamOutputRange(OutputStream)
struct StreamOutputRange(OutputStream, size_t buffer_size = 256)
if (isOutputStream!OutputStream)
{
@safe:

private {
OutputStream m_stream;
size_t m_fill = 0;
ubyte[256] m_data = void;
ubyte[buffer_size] m_data = void;
}

@disable this(this);
Expand Down Expand Up @@ -362,10 +362,10 @@ struct StreamOutputRange(OutputStream)
void put(const(dchar)[] elems) { foreach( ch; elems ) put(ch); }
}
/// ditto
auto streamOutputRange(OutputStream)(OutputStream stream)
auto streamOutputRange(size_t buffer_size = 256, OutputStream)(OutputStream stream)
if (isOutputStream!OutputStream)
{
return StreamOutputRange!OutputStream(stream);
return StreamOutputRange!(OutputStream, buffer_size)(stream);
}

unittest {
Expand Down

0 comments on commit 0980d1f

Please sign in to comment.