mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[http] Added REFERER to curl
This commit is contained in:
parent
2c978637f0
commit
ddbc49b6b3
@ -185,6 +185,7 @@ do_http(struct connection *conn)
|
|||||||
char *optstr;
|
char *optstr;
|
||||||
int no_verify = get_blacklist_flags(conn->uri) & SERVER_BLACKLIST_NO_CERT_VERIFY;
|
int no_verify = get_blacklist_flags(conn->uri) & SERVER_BLACKLIST_NO_CERT_VERIFY;
|
||||||
struct string *cookies;
|
struct string *cookies;
|
||||||
|
struct string referer;
|
||||||
|
|
||||||
http->easy = curl;
|
http->easy = curl;
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
|
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_HEADERFUNCTION, my_fwrite_header);
|
||||||
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
|
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
|
||||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
|
||||||
/* set Referer: automatically when following redirects */
|
|
||||||
curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
|
|
||||||
|
|
||||||
#ifdef CONFIG_COOKIES
|
#ifdef CONFIG_COOKIES
|
||||||
cookies = send_cookies(conn->uri);
|
cookies = send_cookies(conn->uri);
|
||||||
|
|
||||||
@ -209,6 +207,38 @@ do_http(struct connection *conn)
|
|||||||
done_string(cookies);
|
done_string(cookies);
|
||||||
}
|
}
|
||||||
#endif
|
#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) {
|
if (auth) {
|
||||||
curl_easy_setopt(curl, CURLOPT_USERNAME, auth->user);
|
curl_easy_setopt(curl, CURLOPT_USERNAME, auth->user);
|
||||||
|
@ -346,7 +346,7 @@ subst_user_agent(char *fmt, const char *version,
|
|||||||
return agent.source;
|
return agent.source;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
add_url_to_http_string(struct string *header, struct uri *uri, uri_component_T components)
|
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
|
/* This block substitues spaces in URL by %20s. This is
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "protocol/http/blacklist.h"
|
#include "protocol/http/blacklist.h"
|
||||||
#include "protocol/http/post.h"
|
#include "protocol/http/post.h"
|
||||||
#include "protocol/protocol.h"
|
#include "protocol/protocol.h"
|
||||||
|
#include "protocol/uri.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -14,6 +15,7 @@ extern "C" {
|
|||||||
struct connection;
|
struct connection;
|
||||||
struct read_buffer;
|
struct read_buffer;
|
||||||
struct socket;
|
struct socket;
|
||||||
|
struct string;
|
||||||
|
|
||||||
/* Macros related to this struct are defined in the http.c. */
|
/* Macros related to this struct are defined in the http.c. */
|
||||||
struct http_version {
|
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 *subst_user_agent(char *fmt, const char *version,
|
||||||
char *sysname, char *termsize);
|
char *sysname, char *termsize);
|
||||||
|
void add_url_to_http_string(struct string *header, struct uri *uri, uri_component_T components);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user