MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / DoPrepareRequest

Method DoPrepareRequest

Sources/Shared/IO/WebRequest.cpp:2113–2168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2111 }
2112
2113 WebRequest::Result WebRequestWinHTTP::DoPrepareRequest()
2114 {
2115 auto urlW = Utf8::ToUtf16(_url);
2116 URLComponents urlComps;
2117 if (!WinHTTP::WinHttpCrackUrl(urlW.data(), DWORD(urlW.size()), 0, &urlComps)) {
2118 return FailWithLastError("Parsing URL"_s);
2119 }
2120
2121 if (urlComps.HasCredentials()) {
2122 _credentialsFromURL = urlComps.GetCredentials();
2123 _tryCredentialsFromURL = true;
2124 }
2125
2126 Array<wchar_t> hostNameW(NoInit, urlComps.dwHostNameLength + 1);
2127 std::memcpy(hostNameW.data(), urlComps.lpszHostName, urlComps.dwHostNameLength * sizeof(wchar_t));
2128 hostNameW[urlComps.dwHostNameLength] = L'\0';
2129
2130 _connect = WinHTTP::WinHttpConnect(_sessionImpl.GetHandle(), hostNameW, urlComps.nPort, NULL);
2131 if (_connect == NULL) {
2132 return FailWithLastError("Connecting"_s);
2133 }
2134
2135 SmallVector<wchar_t, 500> objectNameW;
2136 objectNameW.reserve(urlComps.dwExtraInfoLength + urlComps.dwExtraInfoLength + 1);
2137 objectNameW.append(urlComps.lpszUrlPath, urlComps.lpszUrlPath + urlComps.dwUrlPathLength);
2138 if (urlComps.dwExtraInfoLength != 0) {
2139 objectNameW.append(urlComps.lpszExtraInfo, urlComps.lpszExtraInfo + urlComps.dwExtraInfoLength);
2140 }
2141 objectNameW.push_back(L'\0');
2142
2143 String method = GetHTTPMethod();
2144 static const wchar_t* acceptedTypesW[] = { L"*/*", nullptr };
2145 _request = WinHTTP::WinHttpOpenRequest(_connect, Utf8::ToUtf16(method), objectNameW.data(), nullptr,
2146 WINHTTP_NO_REFERER, acceptedTypesW, urlComps.nScheme == INTERNET_SCHEME_HTTPS ? WINHTTP_FLAG_SECURE : 0);
2147 if (_request == nullptr) {
2148 return FailWithLastError("Opening request"_s);
2149 }
2150
2151 auto flags = GetSecurityFlags();
2152 if (flags != WebRequest::Ignore::None) {
2153 DWORD optValue = 0;
2154
2155 if ((flags & WebRequest::Ignore::Certificate) != WebRequest::Ignore::None) {
2156 optValue |= SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
2157 SECURITY_FLAG_IGNORE_UNKNOWN_CA |
2158 SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE;
2159 }
2160 if ((flags & WebRequest::Ignore::Host) != WebRequest::Ignore::None) {
2161 optValue |= SECURITY_FLAG_IGNORE_CERT_CN_INVALID;
2162 }
2163
2164 WinHTTPSetOption(_request, WINHTTP_OPTION_SECURITY_FLAGS, optValue);
2165 }
2166
2167 return Result::Ok();
2168 }
2169
2170 void WebRequestWinHTTP::Run()

Callers

nothing calls this directly

Calls 10

WinHTTPSetOptionFunction · 0.85
HasCredentialsMethod · 0.80
GetCredentialsMethod · 0.80
appendMethod · 0.80
ToUtf16Function · 0.50
dataMethod · 0.45
sizeMethod · 0.45
GetHandleMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected