@matheusbsbs / matheus-bagliano / commits / 9fc6440d78
Fork 0

Set proxy override with http_init()

In transport.c, proxy setting (the one from the remote conf) was set through curl_easy_setopt() call, while http.c already does the same with the http.proxy setting. We now just use this infrastructure instead, and make http_init() now take the struct remote as argument so that it can take the http_proxy setting from there, and any other property that would be added later. At the same time, we make get_http_walker() take a struct remote argument too, and pass it to http_init(), which makes remote defined proxy be used for more than get_refs_via_curl(). We leave out http-fetch and http-push, which don't use remotes for the moment, purposefully. Signed-off-by: Mike Hommey <mh@glandium.org> Acked-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mike Hommey committed Feb 27, 2008 at 21:35 UTC 9fc6440d783ca773353880aa97c23ed9c640d3c0
7 files changed +22 -12
builtin-http-fetch.c
+1 -1
@@ -59,7 +59,7 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
59 url = rewritten_url;
60 }
61
62 - walker = get_http_walker(url);
62 + walker = get_http_walker(url, NULL);
63 walker->get_tree = get_tree;
64 walker->get_history = get_history;
65 walker->get_all = get_all;
http-push.c
+1 -1
@@ -2233,7 +2233,7 @@ int main(int argc, char **argv)
2233
2234 memset(remote_dir_exists, -1, 256);
2235
2236 - http_init();
2236 + http_init(NULL);
2237
2238 no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
2239
http-walker.c
+2 -2
@@ -902,13 +902,13 @@ static void cleanup(struct walker *walker)
902 curl_slist_free_all(data->no_pragma_header);
903 }
904
905 -struct walker *get_http_walker(const char *url)
905 +struct walker *get_http_walker(const char *url, struct remote *remote)
906 {
907 char *s;
908 struct walker_data *data = xmalloc(sizeof(struct walker_data));
909 struct walker *walker = xmalloc(sizeof(struct walker));
910
911 - http_init();
911 + http_init(remote);
912
913 data->no_pragma_header = curl_slist_append(NULL, "Pragma:");
914
http.c
+9 -1
@@ -218,13 +218,16 @@ static CURL* get_curl_handle(void)
218 return result;
219 }
220
221 -void http_init(void)
221 +void http_init(struct remote *remote)
222 {
223 char *low_speed_limit;
224 char *low_speed_time;
225
226 curl_global_init(CURL_GLOBAL_ALL);
227
228 + if (remote && remote->http_proxy)
229 + curl_http_proxy = xstrdup(remote->http_proxy);
230 +
231 pragma_header = curl_slist_append(pragma_header, "Pragma: no-cache");
232
233 #ifdef USE_CURL_MULTI
@@ -314,6 +317,11 @@ void http_cleanup(void)
317
318 curl_slist_free_all(pragma_header);
319 pragma_header = NULL;
320 +
321 + if (curl_http_proxy) {
322 + free(curl_http_proxy);
323 + curl_http_proxy = NULL;
324 + }
325 }
326
327 struct active_request_slot *get_active_slot(void)
http.h
+2 -1
@@ -7,6 +7,7 @@
7 #include <curl/easy.h>
8
9 #include "strbuf.h"
10 +#include "remote.h"
11
12 /*
13 * We detect based on the cURL version if multi-transfer is
@@ -83,7 +84,7 @@ extern void add_fill_function(void *data, int (*fill)(void *));
84 extern void step_active_slots(void);
85 #endif
86
86 -extern void http_init(void);
87 +extern void http_init(struct remote *remote);
88 extern void http_cleanup(void);
89
90 extern int data_received;
transport.c
+4 -5
@@ -442,7 +442,8 @@ static struct ref *get_refs_via_curl(struct transport *transport)
442 struct ref *last_ref = NULL;
443
444 if (!transport->data)
445 - transport->data = get_http_walker(transport->url);
445 + transport->data = get_http_walker(transport->url,
446 + transport->remote);
447
448 refs_url = xmalloc(strlen(transport->url) + 11);
449 sprintf(refs_url, "%s/info/refs", transport->url);
@@ -453,9 +454,6 @@ static struct ref *get_refs_via_curl(struct transport *transport)
454 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
455 curl_easy_setopt(slot->curl, CURLOPT_URL, refs_url);
456 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
456 - if (transport->remote->http_proxy)
457 - curl_easy_setopt(slot->curl, CURLOPT_PROXY,
458 - transport->remote->http_proxy);
457
458 if (start_active_slot(slot)) {
459 run_active_slot(slot);
@@ -509,7 +507,8 @@ static int fetch_objs_via_curl(struct transport *transport,
507 int nr_objs, struct ref **to_fetch)
508 {
509 if (!transport->data)
512 - transport->data = get_http_walker(transport->url);
510 + transport->data = get_http_walker(transport->url,
511 + transport->remote);
512 return fetch_objs_via_walker(transport, nr_objs, to_fetch);
513 }
514
walker.h
+3 -1
@@ -1,6 +1,8 @@
1 #ifndef WALKER_H
2 #define WALKER_H
3
4 +#include "remote.h"
5 +
6 struct walker {
7 void *data;
8 int (*fetch_ref)(struct walker *, char *ref, unsigned char *sha1);
@@ -32,6 +34,6 @@ int walker_fetch(struct walker *impl, int targets, char **target,
34
35 void walker_free(struct walker *walker);
36
35 -struct walker *get_http_walker(const char *url);
37 +struct walker *get_http_walker(const char *url, struct remote *remote);
38
39 #endif /* WALKER_H */