diff options
author | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-08-22 17:43:43 -0300 |
---|---|---|
committer | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-08-22 17:43:43 -0300 |
commit | a926878ddbd5a98b272c22171ce58663fc04c3e0 (patch) | |
tree | 86af256e5d9a9c06263c00adc90e5fe348008c43 /libphobos/src/std | |
parent | 542730f087133690b47e036dfd43eb0db8a650ce (diff) | |
parent | 07cbaed8ba7d1b6e4ab3a9f44175502a4e1ecdb1 (diff) | |
download | gcc-devel/autopar_devel.zip gcc-devel/autopar_devel.tar.gz gcc-devel/autopar_devel.tar.bz2 |
Merge branch 'autopar_rebase2' into autopar_develdevel/autopar_devel
Quickly commit changes in the rebase branch.
Diffstat (limited to 'libphobos/src/std')
-rw-r--r-- | libphobos/src/std/net/curl.d | 44 | ||||
-rw-r--r-- | libphobos/src/std/range/package.d | 2 | ||||
-rw-r--r-- | libphobos/src/std/zip.d | 6 |
3 files changed, 39 insertions, 13 deletions
diff --git a/libphobos/src/std/net/curl.d b/libphobos/src/std/net/curl.d index 32ba45c..445f996 100644 --- a/libphobos/src/std/net/curl.d +++ b/libphobos/src/std/net/curl.d @@ -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; @@ -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); } @@ -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) diff --git a/libphobos/src/std/range/package.d b/libphobos/src/std/range/package.d index fe581f3..13601cb 100644 --- a/libphobos/src/std/range/package.d +++ b/libphobos/src/std/range/package.d @@ -4874,7 +4874,7 @@ if (allSatisfy!(isInputRange, Ranges)) // Just make sure 1-range case instantiates. This hangs the compiler // when no explicit stopping policy is specified due to Bug 4652. auto stuff = lockstep([1,2,3,4,5], StoppingPolicy.shortest); - foreach (int i, a; stuff) + foreach (i, a; stuff) { assert(stuff[i] == a); } diff --git a/libphobos/src/std/zip.d b/libphobos/src/std/zip.d index db47dde..8b130ea 100644 --- a/libphobos/src/std/zip.d +++ b/libphobos/src/std/zip.d @@ -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; |