Skip to content

refactoring closure this in func #10816

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

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 15 additions & 8 deletions std/net/curl.d
Original file line number Diff line number Diff line change
Expand Up @@ -2424,13 +2424,20 @@ struct HTTP
import std.string : indexOf, chomp;
import std.uni : toLower;
import std.exception : assumeUnique;
import std.utf : UTFException;

// Wrap incoming callback in order to separate http status line from
// http headers. On redirected requests there may be several such
// status lines. The last one is the one recorded.

// Local copies of the required fields so as not to capture all of this
auto headersInPtr = &headersIn;
auto statusPtr = &status;
auto charsetPtr = &charset;
auto onStatus = onReceiveStatusLine;

auto dg = (in char[] header)
{
import std.utf : UTFException;
try
{
if (header.empty)
Expand All @@ -2440,11 +2447,11 @@ struct HTTP
}
if (header.startsWith("HTTP/"))
{
headersIn.clear();
if (parseStatusLine(header, status))
headersInPtr.clear();
if (parseStatusLine(header, *statusPtr))
{
if (onReceiveStatusLine != null)
onReceiveStatusLine(status);
if (onStatus !is null)
onStatus(*statusPtr);
}
return;
}
Expand All @@ -2458,15 +2465,15 @@ struct HTTP
{
auto io = indexOf(fieldContent, "charset=", No.caseSensitive);
if (io != -1)
charset = fieldContent[io + "charset=".length .. $].findSplit(";")[0].idup;
*charsetPtr = fieldContent[io + "charset=".length .. $].findSplit(";")[0].idup;
}
if (!m[1].empty && callback !is null)
callback(fieldName, fieldContent);
headersIn[fieldName] = fieldContent.idup;
(*headersInPtr)[fieldName] = fieldContent.idup;
}
catch (UTFException e)
{
//munch it - a header should be all ASCII, any "wrong UTF" is broken header
// munch it - a header should be all ASCII, any "wrong UTF" is broken header
}
};

Expand Down