mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-07 10:20:29 +00:00
Improve based on code review
This commit is contained in:
parent
d7b7fb9dc8
commit
ab0fc800f8
1 changed files with 12 additions and 10 deletions
|
@ -3685,7 +3685,7 @@ static int LuaFetch(lua_State *L) {
|
||||||
bool usessl;
|
bool usessl;
|
||||||
uint32_t ip;
|
uint32_t ip;
|
||||||
struct Url url;
|
struct Url url;
|
||||||
int t, ret, sock, methodidx;
|
int t, ret, sock, methodidx, hdridx;
|
||||||
char *host, *port;
|
char *host, *port;
|
||||||
struct TlsBio *bio;
|
struct TlsBio *bio;
|
||||||
struct addrinfo *addr;
|
struct addrinfo *addr;
|
||||||
|
@ -3742,18 +3742,20 @@ static int LuaFetch(lua_State *L) {
|
||||||
return luaL_argerror(L, 2, "invalid header value encoding");
|
return luaL_argerror(L, 2, "invalid header value encoding");
|
||||||
|
|
||||||
// Content-Length and Connection will be overwritten;
|
// Content-Length and Connection will be overwritten;
|
||||||
// skip them to avoid duplicates
|
// skip them to avoid duplicates;
|
||||||
if (strcasecmp(key, "content-length") &&
|
// also allow unknown headers
|
||||||
strcasecmp(key, "connection")) {
|
if ((hdridx = GetHttpHeader(key, keylen)) == -1 ||
|
||||||
if (!strcasecmp(key, "user-agent")) {
|
hdridx != kHttpContentLength &&
|
||||||
agenthdr = gc(strdup(hdr));
|
hdridx != kHttpConnection) {
|
||||||
} else if (!strcasecmp(key, "host")) {
|
if (hdridx == kHttpUserAgent) {
|
||||||
hosthdr = gc(strdup(hdr));
|
agenthdr = hdr;
|
||||||
|
} else if (hdridx == kHttpHost) {
|
||||||
|
hosthdr = hdr;
|
||||||
} else {
|
} else {
|
||||||
appendd(&headers, key, keylen);
|
appendd(&headers, key, keylen);
|
||||||
appendd(&headers, ": ", 2);
|
appendw(&headers, READ16LE(": "));
|
||||||
appends(&headers, hdr);
|
appends(&headers, hdr);
|
||||||
appendd(&headers, "\r\n", 2);
|
appendw(&headers, READ16LE("\r\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue