SecureTransport: use the curl stream if available If the libcurl stream is available, use that as the underlying stream instead of the socket stream. This allows us to set a proxy for HTTPS connections.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
diff --git a/src/stransport_stream.c b/src/stransport_stream.c
index 34c38b2..bbc2d32 100644
--- a/src/stransport_stream.c
+++ b/src/stransport_stream.c
@@ -14,6 +14,7 @@
#include "git2/transport.h"
#include "socket_stream.h"
+#include "curl_stream.h"
int stransport_error(OSStatus ret)
{
@@ -115,6 +116,13 @@ int stransport_certificate(git_cert **out, git_stream *stream)
return 0;
}
+int stransport_set_proxy(git_stream *stream, const char *proxy)
+{
+ stransport_stream *st = (stransport_stream *) stream;
+
+ return git_stream_set_proxy(st->io, proxy);
+}
+
/*
* Contrary to typical network IO callbacks, Secure Transport write callback is
* expected to write *all* passed data, not just as much as it can, and any
@@ -233,7 +241,13 @@ int git_stransport_stream_new(git_stream **out, const char *host, const char *po
st = git__calloc(1, sizeof(stransport_stream));
GITERR_CHECK_ALLOC(st);
- if ((error = git_socket_stream_new(&st->io, host, port)) < 0){
+#ifdef GIT_CURL
+ error = git_curl_stream_new(&st->io, host, port);
+#else
+ error = git_socket_stream_new(&st->io, host, port)
+#endif
+
+ if (error < 0){
git__free(st);
return error;
}
@@ -256,8 +270,10 @@ int git_stransport_stream_new(git_stream **out, const char *host, const char *po
st->parent.version = GIT_STREAM_VERSION;
st->parent.encrypted = 1;
+ st->parent.proxy_support = git_stream_supports_proxy(st->io);
st->parent.connect = stransport_connect;
st->parent.certificate = stransport_certificate;
+ st->parent.set_proxy = stransport_set_proxy;
st->parent.read = stransport_read;
st->parent.write = stransport_write;
st->parent.close = stransport_close;