Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dmd-cxx] Backport fixes from #6752 and #7196 #7486

Merged
merged 2 commits into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions std/net/curl.d
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,6 @@ struct HTTP
in char[] value) callback)
{
import std.algorithm.searching : startsWith;
import std.conv : to;
import std.regex : regex, match;
import std.uni : toLower;

Expand All @@ -2471,18 +2470,8 @@ struct HTTP
if (header.startsWith("HTTP/"))
{
headersIn.clear();

const m = match(header, regex(r"^HTTP/(\d+)\.(\d+) (\d+) (.*)$"));
if (m.empty)
if (parseStatusLine(header, status))
{
// Invalid status line
}
else
{
status.majorVersion = to!ushort(m.captures[1]);
status.minorVersion = to!ushort(m.captures[2]);
status.code = to!ushort(m.captures[3]);
status.reason = m.captures[4].idup;
if (onReceiveStatusLine != null)
onReceiveStatusLine(status);
}
Expand Down Expand Up @@ -2517,6 +2506,37 @@ struct HTTP

private RefCounted!Impl p;

/// Parse status line, as received from / generated by cURL.
private static bool parseStatusLine(in char[] header, out StatusLine status) @safe
{
import std.conv : to;
import std.regex : regex, match;

const m = match(header, regex(r"^HTTP/(\d+)(?:\.(\d+))? (\d+)(?: (.*))?$"));
if (m.empty)
return false; // Invalid status line
else
{
status.majorVersion = to!ushort(m.captures[1]);
status.minorVersion = m.captures[2].length ? to!ushort(m.captures[2]) : 0;
status.code = to!ushort(m.captures[3]);
status.reason = m.captures[4].idup;
return true;
}
}

@safe unittest
{
StatusLine status;
assert(parseStatusLine("HTTP/1.1 200 OK", status)
&& status == StatusLine(1, 1, 200, "OK"));
assert(parseStatusLine("HTTP/1.0 304 Not Modified", status)
&& status == StatusLine(1, 0, 304, "Not Modified"));
// The HTTP2 protocol is binary; cURL generates this fake text header.
assert(parseStatusLine("HTTP/2 200", status)
&& status == StatusLine(2, 0, 200, null));
}

/** Time condition enumeration as an alias of $(REF CurlTimeCond, etc,c,curl)

$(HTTP www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.25, _RFC2616 Section 14.25)
Expand Down
6 changes: 6 additions & 0 deletions std/zip.d
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,12 @@ version (Posix) @system unittest
{
import std.datetime, std.file, std.format, std.path, std.process, std.stdio;

if (executeShell("unzip").status != 0)
{
writeln("Can't run unzip, skipping unzip test");
return;
}

auto zr = new ZipArchive();
auto am = new ArchiveMember();
am.compressionMethod = CompressionMethod.deflate;
Expand Down