1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-27 01:25:34 +00:00

[http] Added REFERER to curl

This commit is contained in:
Witold Filipczyk 2023-10-06 15:12:29 +02:00
parent 2c978637f0
commit ddbc49b6b3
3 changed files with 38 additions and 4 deletions

View File

@ -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);

View File

@ -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

View File

@ -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
}