Git-Raw
view release on metacpan or search on metacpan
deps/libgit2/src/libgit2/transports/winhttp.c view on Meta::CPAN
git_str processed_url = GIT_STR_INIT;
WINHTTP_PROXY_INFO proxy_info;
wchar_t *proxy_wide;
git_net_url_dispose(&t->proxy.url);
if ((error = git_net_url_parse(&t->proxy.url, proxy_url)) < 0)
goto on_error;
if (strcmp(t->proxy.url.scheme, "http") != 0 && strcmp(t->proxy.url.scheme, "https") != 0) {
git_error_set(GIT_ERROR_HTTP, "invalid URL: '%s'", proxy_url);
error = -1;
goto on_error;
}
git_str_puts(&processed_url, t->proxy.url.scheme);
git_str_PUTS(&processed_url, "://");
if (git_net_url_is_ipv6(&t->proxy.url))
git_str_putc(&processed_url, '[');
git_str_puts(&processed_url, t->proxy.url.host);
if (git_net_url_is_ipv6(&t->proxy.url))
git_str_putc(&processed_url, ']');
if (!git_net_url_is_default_port(&t->proxy.url))
git_str_printf(&processed_url, ":%s", t->proxy.url.port);
if (git_str_oom(&processed_url)) {
error = -1;
goto on_error;
}
/* Convert URL to wide characters */
error = git__utf8_to_16_alloc(&proxy_wide, processed_url.ptr);
git_str_dispose(&processed_url);
if (error < 0)
goto on_error;
proxy_info.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
proxy_info.lpszProxy = proxy_wide;
proxy_info.lpszProxyBypass = NULL;
if (!WinHttpSetOption(s->request,
WINHTTP_OPTION_PROXY,
&proxy_info,
sizeof(WINHTTP_PROXY_INFO))) {
git_error_set(GIT_ERROR_OS, "failed to set proxy");
git__free(proxy_wide);
goto on_error;
}
git__free(proxy_wide);
if ((error = apply_credentials(s->request, &t->proxy.url, WINHTTP_AUTH_TARGET_PROXY, t->proxy.cred, t->proxy.auth_mechanisms)) < 0)
goto on_error;
}
/* Disable WinHTTP redirects so we can handle them manually. Why, you ask?
* http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/b2ff8879-ab9f-4218-8f09-16d25dff87ae
*/
if (!WinHttpSetOption(s->request,
WINHTTP_OPTION_DISABLE_FEATURE,
&disable_redirects,
sizeof(disable_redirects))) {
git_error_set(GIT_ERROR_OS, "failed to disable redirects");
error = -1;
goto on_error;
}
/* Strip unwanted headers (X-P2P-PeerDist, X-P2P-PeerDistEx) that WinHTTP
* adds itself. This option may not be supported by the underlying
* platform, so we do not error-check it */
WinHttpSetOption(s->request,
WINHTTP_OPTION_PEERDIST_EXTENSION_STATE,
&peerdist,
sizeof(peerdist));
/* Send Pragma: no-cache header */
if (!WinHttpAddRequestHeaders(s->request, pragma_nocache, (ULONG) -1L, WINHTTP_ADDREQ_FLAG_ADD)) {
git_error_set(GIT_ERROR_OS, "failed to add a header to the request");
goto on_error;
}
if (post_verb == s->verb) {
/* Send Content-Type and Accept headers -- only necessary on a POST */
git_str_clear(&buf);
if (git_str_printf(&buf,
"Content-Type: application/x-git-%s-request",
s->service) < 0)
goto on_error;
if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to convert content-type to wide characters");
goto on_error;
}
if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L,
WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) {
git_error_set(GIT_ERROR_OS, "failed to add a header to the request");
goto on_error;
}
git_str_clear(&buf);
if (git_str_printf(&buf,
"Accept: application/x-git-%s-result",
s->service) < 0)
goto on_error;
if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
git_error_set(GIT_ERROR_OS, "failed to convert accept header to wide characters");
goto on_error;
}
if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L,
WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) {
git_error_set(GIT_ERROR_OS, "failed to add a header to the request");
goto on_error;
}
}
( run in 1.512 second using v1.01-cache-2.11-cpan-df04353d9ac )