551
551
int trace = get_opt_bool("protocol.http.trace");
552
552
struct string header;
553
553
unsigned char *post_data = NULL;
554
struct auth_entry *entry;
554
struct auth_entry *entry = NULL;
555
555
struct uri *uri = conn->proxied_uri; /* Set to the real uri */
556
556
unsigned char *optstr;
557
557
int use_connect, talking_to_proxy;
577
577
add_to_string(&header, "TRACE ");
578
578
} else if (use_connect) {
579
579
add_to_string(&header, "CONNECT ");
580
/* In CONNECT requests, we send only a subset of the
581
* headers to the proxy. See the "CONNECT:" comments
582
* below. After the CONNECT request succeeds, we
583
* negotiate TLS with the real server and make a new
584
* HTTP request that includes all the headers. */
580
585
} else if (uri->post) {
581
586
add_to_string(&header, "POST ");
582
587
conn->unrestartable = 1;
609
614
add_long_to_string(&header, http->sent_version.minor);
610
615
add_crlf_to_string(&header);
617
/* CONNECT: Sending a Host header seems pointless as the same
618
* information is already in the CONNECT line. It's harmless
619
* though and Mozilla does it too. */
612
620
add_to_string(&header, "Host: ");
613
621
add_uri_to_string(&header, uri, URI_HTTP_HOST);
614
622
add_crlf_to_string(&header);
624
/* CONNECT: Proxy-Authorization is intended to be seen by the proxy. */
616
625
if (talking_to_proxy) {
617
626
unsigned char *user = get_opt_str("protocol.http.proxy.user");
618
627
unsigned char *passwd = get_opt_str("protocol.http.proxy.passwd");
672
/* CONNECT: User-Agent does not reveal anything about the
673
* resource we're fetching, and it may help the proxy return
674
* better error messages. */
663
675
optstr = get_opt_str("protocol.http.user_agent");
664
676
if (*optstr && strcmp(optstr, " ")) {
665
677
unsigned char *ustr, ts[64] = "";
685
697
add_crlf_to_string(&header);
688
switch (get_opt_int("protocol.http.referer.policy")) {
694
optstr = get_opt_str("protocol.http.referer.fake");
695
if (!optstr[0]) break;
696
add_to_string(&header, "Referer: ");
697
add_to_string(&header, optstr);
698
add_crlf_to_string(&header);
702
if (!conn->referrer) break;
703
add_to_string(&header, "Referer: ");
704
add_url_to_http_string(&header, conn->referrer, URI_HTTP_REFERRER);
705
add_crlf_to_string(&header);
708
case REFERER_SAME_URL:
709
add_to_string(&header, "Referer: ");
710
add_url_to_http_string(&header, uri, URI_HTTP_REFERRER);
711
add_crlf_to_string(&header);
700
/* CONNECT: Referer probably is a secret page in the HTTPS
701
* server, so don't reveal it to the proxy. */
703
switch (get_opt_int("protocol.http.referer.policy")) {
709
optstr = get_opt_str("protocol.http.referer.fake");
710
if (!optstr[0]) break;
711
add_to_string(&header, "Referer: ");
712
add_to_string(&header, optstr);
713
add_crlf_to_string(&header);
717
if (!conn->referrer) break;
718
add_to_string(&header, "Referer: ");
719
add_url_to_http_string(&header, conn->referrer, URI_HTTP_REFERRER);
720
add_crlf_to_string(&header);
723
case REFERER_SAME_URL:
724
add_to_string(&header, "Referer: ");
725
add_url_to_http_string(&header, uri, URI_HTTP_REFERRER);
726
add_crlf_to_string(&header);
731
/* CONNECT: Do send all Accept* headers to the CONNECT proxy,
732
* because they do not reveal anything about the resource
733
* we're going to request via TLS, and they may affect the
734
* error message if the CONNECT request fails.
736
* If ELinks is ever changed to vary its Accept headers based
737
* on what it intends to do with the returned resource, e.g.
738
* sending "Accept: text/css" when it wants an external
739
* stylesheet, then it should do that only in the inner GET
740
* and not in the outer CONNECT. */
715
741
add_to_string(&header, "Accept: */*");
716
742
add_crlf_to_string(&header);
795
/* CONNECT: Proxy-Connection is intended to be seen by the
796
* proxy. If the CONNECT request succeeds, then the proxy
797
* will forward the remainder of the TCP connection to the
798
* origin server, and Proxy-Connection does not matter; but
799
* if the request fails, then Proxy-Connection may matter. */
769
800
/* FIXME: What about post-HTTP/1.1?? --Zas */
770
801
if (HTTP_1_1(http->sent_version)) {
771
802
if (!IS_PROXY_URI(conn->uri)) {
782
813
add_crlf_to_string(&header);
816
/* CONNECT: Do not tell the proxy anything we have cached
817
* about the resource. */
818
if (!use_connect && conn->cached) {
786
819
if (!conn->cached->incomplete && conn->cached->head && conn->cached->last_modified
787
820
&& conn->cache_mode <= CACHE_MODE_CHECK_IF_MODIFIED) {
788
821
add_to_string(&header, "If-Modified-Since: ");
798
833
add_crlf_to_string(&header);
801
if (conn->from || conn->progress->start > 0) {
836
/* CONNECT: Do not reveal byte ranges to the proxy. It can't
837
* do anything good with that information anyway. */
838
if (!use_connect && (conn->from || conn->progress->start > 0)) {
802
839
/* conn->from takes precedence. conn->progress.start is set only the first
803
840
* time, then conn->from gets updated and in case of any retries
804
841
* etc we have everything interesting in conn->from already. */
882
924
add_crlf_to_string(&header);
926
/* CONNECT: Any POST data is for the origin server only.
927
* This was already checked above and post_data is NULL
928
* in that case. Verified with an assertion below. */
885
930
#define POST_BUFFER_SIZE 4096
886
931
unsigned char *post = post_data;
887
932
unsigned char buffer[POST_BUFFER_SIZE];
935
assert(!use_connect); /* see comment above */
890
937
while (post[0] && post[1]) {