Implement and document support for an HTTP_REFERER environment variable.
PR: 28171 Submitted by: Andre Albsmeier <andre.albsmeier@mchp.siemens.de> Approved by: re (bmah) MFC after: 1 week
This commit is contained in:
parent
fdff30d256
commit
d5216a4fb7
@ -511,6 +511,11 @@ variable.
|
|||||||
This variable is used if and only if connected to an HTTP proxy, and
|
This variable is used if and only if connected to an HTTP proxy, and
|
||||||
is ignored if a user and/or a password were specified in the proxy
|
is ignored if a user and/or a password were specified in the proxy
|
||||||
URL.
|
URL.
|
||||||
|
.It Ev HTTP_REFERER
|
||||||
|
Specifies the referer URL to use for HTTP requests.
|
||||||
|
If set to
|
||||||
|
.Dq auto ,
|
||||||
|
the document URL will be used as referer URL.
|
||||||
.It Ev HTTP_USER_AGENT
|
.It Ev HTTP_USER_AGENT
|
||||||
Specifies the User-Agent string to use for HTTP requests.
|
Specifies the User-Agent string to use for HTTP requests.
|
||||||
This can be useful when working with HTTP origin or proxy servers that
|
This can be useful when working with HTTP origin or proxy servers that
|
||||||
|
@ -776,10 +776,7 @@ _http_request(struct url *URL, const char *op, struct url_stat *us,
|
|||||||
const char *p;
|
const char *p;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
hdr_t h;
|
hdr_t h;
|
||||||
char *host;
|
char hbuf[MAXHOSTNAMELEN + 7], *host;
|
||||||
#ifdef INET6
|
|
||||||
char hbuf[MAXHOSTNAMELEN + 1];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
direct = CHECK_FLAG('d');
|
direct = CHECK_FLAG('d');
|
||||||
noredirect = CHECK_FLAG('A');
|
noredirect = CHECK_FLAG('A');
|
||||||
@ -831,24 +828,29 @@ _http_request(struct url *URL, const char *op, struct url_stat *us,
|
|||||||
host = hbuf;
|
host = hbuf;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (url->port != _fetch_default_port(url->scheme)) {
|
||||||
|
if (host != hbuf) {
|
||||||
|
strcpy(hbuf, host);
|
||||||
|
host = hbuf;
|
||||||
|
}
|
||||||
|
snprintf(hbuf + strlen(hbuf),
|
||||||
|
sizeof(hbuf) - strlen(hbuf), ":%d", url->port);
|
||||||
|
}
|
||||||
|
|
||||||
/* send request */
|
/* send request */
|
||||||
if (verbose)
|
if (verbose)
|
||||||
_fetch_info("requesting %s://%s:%d%s",
|
_fetch_info("requesting %s://%s%s",
|
||||||
url->scheme, host, url->port, url->doc);
|
url->scheme, host, url->doc);
|
||||||
if (purl) {
|
if (purl) {
|
||||||
_http_cmd(conn, "%s %s://%s:%d%s HTTP/1.1",
|
_http_cmd(conn, "%s %s://%s%s HTTP/1.1",
|
||||||
op, url->scheme, host, url->port, url->doc);
|
op, url->scheme, host, url->doc);
|
||||||
} else {
|
} else {
|
||||||
_http_cmd(conn, "%s %s HTTP/1.1",
|
_http_cmd(conn, "%s %s HTTP/1.1",
|
||||||
op, url->doc);
|
op, url->doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual host */
|
/* virtual host */
|
||||||
if (url->port == _fetch_default_port(url->scheme))
|
_http_cmd(conn, "Host: %s", host);
|
||||||
_http_cmd(conn, "Host: %s", host);
|
|
||||||
else
|
|
||||||
_http_cmd(conn, "Host: %s:%d", host, url->port);
|
|
||||||
|
|
||||||
/* proxy authorization */
|
/* proxy authorization */
|
||||||
if (purl) {
|
if (purl) {
|
||||||
@ -874,6 +876,13 @@ _http_request(struct url *URL, const char *op, struct url_stat *us,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* other headers */
|
/* other headers */
|
||||||
|
if ((p = getenv("HTTP_REFERER")) != NULL && *p != '\0') {
|
||||||
|
if (strcasecmp(p, "auto") == 0)
|
||||||
|
_http_cmd(conn, "Referer: %s://%s%s",
|
||||||
|
url->scheme, host, url->doc);
|
||||||
|
else
|
||||||
|
_http_cmd(conn, "Referer: %s", p);
|
||||||
|
}
|
||||||
if ((p = getenv("HTTP_USER_AGENT")) != NULL && *p != '\0')
|
if ((p = getenv("HTTP_USER_AGENT")) != NULL && *p != '\0')
|
||||||
_http_cmd(conn, "User-Agent: %s", p);
|
_http_cmd(conn, "User-Agent: %s", p);
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user