diff --git a/src/protocol/curl/http.c b/src/protocol/curl/http.c index 53a46c87..78f8e274 100644 --- a/src/protocol/curl/http.c +++ b/src/protocol/curl/http.c @@ -185,6 +185,7 @@ do_http(struct connection *conn) char *optstr; int no_verify = get_blacklist_flags(conn->uri) & SERVER_BLACKLIST_NO_CERT_VERIFY; struct string *cookies; + struct string referer; http->easy = curl; curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite); @@ -198,9 +199,6 @@ do_http(struct connection *conn) curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, my_fwrite_header); curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""); curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); - /* set Referer: automatically when following redirects */ - curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L); - #ifdef CONFIG_COOKIES cookies = send_cookies(conn->uri); @@ -209,6 +207,38 @@ do_http(struct connection *conn) done_string(cookies); } #endif + switch (get_opt_int("protocol.http.referer.policy", NULL)) { + case REFERER_NONE: + /* oh well */ + break; + + case REFERER_FAKE: + optstr = get_opt_str("protocol.http.referer.fake", NULL); + if (!optstr[0]) break; + + curl_easy_setopt(curl, CURLOPT_REFERER, optstr); + break; + + case REFERER_TRUE: + if (!conn->referrer) break; + + if (!init_string(&referer)) { + break; + } + add_url_to_http_string(&referer, conn->referrer, URI_HTTP_REFERRER); + curl_easy_setopt(curl, CURLOPT_REFERER, referer.source); + done_string(&referer); + break; + + case REFERER_SAME_URL: + if (!init_string(&referer)) { + break; + } + add_url_to_http_string(&referer, conn->uri, URI_HTTP_REFERRER); + curl_easy_setopt(curl, CURLOPT_REFERER, referer.source); + done_string(&referer); + break; + } if (auth) { curl_easy_setopt(curl, CURLOPT_USERNAME, auth->user); diff --git a/src/protocol/http/http.c b/src/protocol/http/http.c index 5a40ebf9..8531b337 100644 --- a/src/protocol/http/http.c +++ b/src/protocol/http/http.c @@ -346,7 +346,7 @@ subst_user_agent(char *fmt, const char *version, return agent.source; } -static void +void add_url_to_http_string(struct string *header, struct uri *uri, uri_component_T components) { /* This block substitues spaces in URL by %20s. This is diff --git a/src/protocol/http/http.h b/src/protocol/http/http.h index 7cc44102..1be2cb71 100644 --- a/src/protocol/http/http.h +++ b/src/protocol/http/http.h @@ -6,6 +6,7 @@ #include "protocol/http/blacklist.h" #include "protocol/http/post.h" #include "protocol/protocol.h" +#include "protocol/uri.h" #ifdef __cplusplus extern "C" { @@ -14,6 +15,7 @@ extern "C" { struct connection; struct read_buffer; struct socket; +struct string; /* Macros related to this struct are defined in the http.c. */ struct http_version { @@ -51,6 +53,8 @@ void http_got_header(struct socket *, struct read_buffer *); char *subst_user_agent(char *fmt, const char *version, char *sysname, char *termsize); +void add_url_to_http_string(struct string *header, struct uri *uri, uri_component_T components); + #ifdef __cplusplus }