Skip to content

Commit a904fc6

Browse files
authored
Merge pull request libgit2#4870 from libgit2/ethomson/proxy
Add builtin proxy support for the http transport
2 parents dcd0063 + 30ac46a commit a904fc6

File tree

28 files changed

+1209
-769
lines changed

28 files changed

+1209
-769
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ OPTION(USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON)
6060
OPTION(USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF)
6161
OPTION(USE_STANDALONE_FUZZERS "Enable standalone fuzzers (compatible with gcc)" OFF)
6262
OPTION(VALGRIND "Configure build for valgrind" OFF)
63-
OPTION(CURL "Use curl for HTTP if available" ON)
6463
OPTION(USE_EXT_HTTP_PARSER "Use system HTTP_Parser if available" ON)
6564
OPTION(DEBUG_POOL "Enable debug pool allocator" OFF)
6665
OPTION(ENABLE_WERROR "Enable compilation with -Werror" OFF)
@@ -234,6 +233,7 @@ ELSE ()
234233
ENABLE_WARNINGS(format)
235234
ENABLE_WARNINGS(format-security)
236235
ENABLE_WARNINGS(int-conversion)
236+
DISABLE_WARNINGS(documentation-deprecated-sync)
237237

238238
IF (APPLE) # Apple deprecated OpenSSL
239239
DISABLE_WARNINGS(deprecated-declarations)

ci/test.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ if (-not $Env:SKIP_PROXY_TESTS) {
6565
Write-Host "Running proxy tests"
6666
Write-Host ""
6767

68-
$Env:GITTEST_REMOTE_PROXY_URL="localhost:8080"
68+
$Env:GITTEST_REMOTE_PROXY_HOST="localhost:8080"
6969
$Env:GITTEST_REMOTE_PROXY_USER="foo"
7070
$Env:GITTEST_REMOTE_PROXY_PASS="bar"
7171

ci/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ if [ -z "$SKIP_PROXY_TESTS" ]; then
164164
echo "Running proxy tests"
165165
echo ""
166166

167-
export GITTEST_REMOTE_PROXY_URL="localhost:8080"
167+
export GITTEST_REMOTE_PROXY_HOST="localhost:8080"
168168
export GITTEST_REMOTE_PROXY_USER="foo"
169169
export GITTEST_REMOTE_PROXY_PASS="bar"
170170
run_test proxy
171-
unset GITTEST_REMOTE_PROXY_URL
171+
unset GITTEST_REMOTE_PROXY_HOST
172172
unset GITTEST_REMOTE_PROXY_USER
173173
unset GITTEST_REMOTE_PROXY_PASS
174174
fi

include/git2/sys/stream.h

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,90 @@ typedef struct git_stream {
4040
void (*free)(struct git_stream *);
4141
} git_stream;
4242

43-
typedef int (*git_stream_cb)(git_stream **out, const char *host, const char *port);
43+
typedef struct {
44+
/** The `version` field should be set to `GIT_STREAM_VERSION`. */
45+
int version;
46+
47+
/**
48+
* Called to create a new connection to a given host.
49+
*
50+
* @param out The created stream
51+
* @param host The hostname to connect to; may be a hostname or
52+
* IP address
53+
* @param port The port to connect to; may be a port number or
54+
* service name
55+
* @return 0 or an error code
56+
*/
57+
int (*init)(git_stream **out, const char *host, const char *port);
58+
59+
/**
60+
* Called to create a new connection on top of the given stream. If
61+
* this is a TLS stream, then this function may be used to proxy a
62+
* TLS stream over an HTTP CONNECT session. If this is unset, then
63+
* HTTP CONNECT proxies will not be supported.
64+
*
65+
* @param out The created stream
66+
* @param in An existing stream to add TLS to
67+
* @param host The hostname that the stream is connected to,
68+
* for certificate validation
69+
* @return 0 or an error code
70+
*/
71+
int (*wrap)(git_stream **out, git_stream *in, const char *host);
72+
} git_stream_registration;
4473

4574
/**
46-
* Register a TLS stream constructor for the library to use
75+
* The type of stream to register.
76+
*/
77+
typedef enum {
78+
/** A standard (non-TLS) socket. */
79+
GIT_STREAM_STANDARD = 1,
80+
81+
/** A TLS-encrypted socket. */
82+
GIT_STREAM_TLS = 2,
83+
} git_stream_t;
84+
85+
/**
86+
* Register stream constructors for the library to use
87+
*
88+
* If a registration structure is already set, it will be overwritten.
89+
* Pass `NULL` in order to deregister the current constructor and return
90+
* to the system defaults.
4791
*
48-
* If a constructor is already set, it will be overwritten. Pass
49-
* `NULL` in order to deregister the current constructor.
92+
* The type parameter may be a bitwise AND of types.
5093
*
51-
* @param ctor the constructor to use
94+
* @param type the type or types of stream to register
95+
* @param registration the registration data
5296
* @return 0 or an error code
5397
*/
98+
GIT_EXTERN(int) git_stream_register(
99+
git_stream_t type, git_stream_registration *registration);
100+
101+
/** @name Deprecated TLS Stream Registration Functions
102+
*
103+
* These typedefs and functions are retained for backward compatibility.
104+
* The newer versions of these functions and structures should be preferred
105+
* in all new code.
106+
*/
107+
108+
/**@{*/
109+
110+
/**
111+
* @deprecated Provide a git_stream_registration to git_stream_register
112+
* @see git_stream_registration
113+
*/
114+
typedef int (*git_stream_cb)(git_stream **out, const char *host, const char *port);
115+
116+
/**
117+
* Register a TLS stream constructor for the library to use. This stream
118+
* will not support HTTP CONNECT proxies.
119+
*
120+
* @deprecated Provide a git_stream_registration to git_stream_register
121+
* @see git_stream_register
122+
*/
54123
GIT_EXTERN(int) git_stream_register_tls(git_stream_cb ctor);
55124

125+
/**@}*/
126+
56127
GIT_END_DECL
57128

58129
#endif

src/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,6 @@ IF (WIN32 AND WINHTTP)
125125

126126
LIST(APPEND LIBGIT2_LIBS "rpcrt4" "crypt32" "ole32")
127127
LIST(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32")
128-
ELSE ()
129-
IF (CURL)
130-
FIND_PKGLIBRARIES(CURL libcurl)
131-
ENDIF ()
132-
IF (CURL_FOUND)
133-
SET(GIT_CURL 1)
134-
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${CURL_INCLUDE_DIRS})
135-
LIST(APPEND LIBGIT2_LIBS ${CURL_LIBRARIES})
136-
LIST(APPEND LIBGIT2_PC_LIBS ${CURL_LDFLAGS})
137-
ENDIF()
138-
ADD_FEATURE_INFO(cURL GIT_CURL "cURL for HTTP proxy support")
139128
ENDIF()
140129

141130
IF (USE_HTTPS)

src/features.h.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
#cmakedefine GIT_GSSAPI 1
2424
#cmakedefine GIT_WINHTTP 1
25-
#cmakedefine GIT_CURL 1
2625

2726
#cmakedefine GIT_HTTPS 1
2827
#cmakedefine GIT_OPENSSL 1

src/global.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "sysdir.h"
1313
#include "filter.h"
1414
#include "merge_driver.h"
15-
#include "streams/curl.h"
15+
#include "streams/registry.h"
1616
#include "streams/mbedtls.h"
1717
#include "streams/openssl.h"
1818
#include "thread-utils.h"
@@ -67,8 +67,8 @@ static int init_common(void)
6767
(ret = git_filter_global_init()) == 0 &&
6868
(ret = git_merge_driver_global_init()) == 0 &&
6969
(ret = git_transport_ssh_global_init()) == 0 &&
70+
(ret = git_stream_registry_global_init()) == 0 &&
7071
(ret = git_openssl_stream_global_init()) == 0 &&
71-
(ret = git_curl_stream_global_init()) == 0 &&
7272
(ret = git_mbedtls_stream_global_init()) == 0)
7373
ret = git_mwindow_global_init();
7474

0 commit comments

Comments
 (0)