Compare commits
2 Commits
896486b64a
...
cd80a194dd
Author | SHA1 | Date | |
---|---|---|---|
cd80a194dd
|
|||
ffc5c80b65
|
@@ -245,16 +245,8 @@ int http_get_header_field_num(const http_hdr *hdr, const char *field_name) {
|
||||
}
|
||||
|
||||
int http_get_header_field_num_len(const http_hdr *hdr, const char *field_name, unsigned long len) {
|
||||
char field_name_1[256], field_name_2[256];
|
||||
memcpy(field_name_1, field_name, len);
|
||||
field_name_1[len] = 0;
|
||||
http_to_camel_case(field_name_1, HTTP_LOWER);
|
||||
|
||||
for (int i = 0; i < list_size(hdr->fields); i++) {
|
||||
strcpy(field_name_2, http_field_get_name(&hdr->fields[i]));
|
||||
http_to_camel_case(field_name_2, HTTP_LOWER);
|
||||
|
||||
if (strcmp(field_name_1, field_name_2) == 0)
|
||||
if (strncasecmp(field_name, http_field_get_name(&hdr->fields[i]), len) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -320,10 +312,6 @@ void http_append_to_header_field(http_field *field, const char *value, unsigned
|
||||
}
|
||||
|
||||
void http_remove_header_field(http_hdr *hdr, const char *field_name, int mode) {
|
||||
char field_name_1[256], field_name_2[256];
|
||||
strcpy(field_name_1, field_name);
|
||||
http_to_camel_case(field_name_1, HTTP_LOWER);
|
||||
|
||||
int i = 0;
|
||||
int diff = 1;
|
||||
if (mode == HTTP_REMOVE_LAST) {
|
||||
@@ -331,9 +319,7 @@ void http_remove_header_field(http_hdr *hdr, const char *field_name, int mode) {
|
||||
diff = -1;
|
||||
}
|
||||
for (; i < list_size(hdr->fields) && i >= 0; i += diff) {
|
||||
strcpy(field_name_2, http_field_get_name(&hdr->fields[i]));
|
||||
http_to_camel_case(field_name_2, HTTP_LOWER);
|
||||
if (strcmp(field_name_1, field_name_2) == 0) {
|
||||
if (strcasecmp(field_name, http_field_get_name(&hdr->fields[i])) == 0) {
|
||||
http_free_field(&hdr->fields[i]);
|
||||
list_remove(hdr->fields, i);
|
||||
if (mode == HTTP_REMOVE_ALL) {
|
||||
|
@@ -22,10 +22,12 @@ static int proxy_handler_2(client_ctx_t *ctx);
|
||||
void proxy_handler_func(client_ctx_t *ctx) {
|
||||
logger_set_prefix("[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
|
||||
|
||||
proxy_handler_1(ctx);
|
||||
int ret = proxy_handler_1(ctx);
|
||||
respond(ctx);
|
||||
|
||||
if (ctx->use_proxy == 0) {
|
||||
if (ret == 1) {
|
||||
|
||||
} else if (ctx->use_proxy == 0) {
|
||||
proxy_close(ctx->proxy);
|
||||
} else if (ctx->use_proxy == 1) {
|
||||
proxy_handler_2(ctx);
|
||||
@@ -74,7 +76,10 @@ static int proxy_handler_1(client_ctx_t *ctx) {
|
||||
const char *content_type = http_get_header_field(&res->hdr, "Content-Type");
|
||||
const char *content_length_f = http_get_header_field(&res->hdr, "Content-Length");
|
||||
const char *content_encoding = http_get_header_field(&res->hdr, "Content-Encoding");
|
||||
if (content_encoding == NULL && content_type != NULL && content_length_f != NULL && strncmp(content_type, "text/html", 9) == 0) {
|
||||
if (content_encoding == NULL && (
|
||||
(content_length_f != NULL && strcmp(content_length_f, "0") == 0) ||
|
||||
(content_type != NULL && content_length_f != NULL && strncmp(content_type, "text/html", 9) == 0)))
|
||||
{
|
||||
long content_len = strtol(content_length_f, NULL, 10);
|
||||
if (content_len <= sizeof(ctx->msg_content) - 1) {
|
||||
if (status->status != 101) {
|
||||
@@ -82,7 +87,11 @@ static int proxy_handler_1(client_ctx_t *ctx) {
|
||||
status->origin = res->status->code >= 400 ? SERVER : NONE;
|
||||
}
|
||||
ctx->use_proxy = 0;
|
||||
proxy_dump(ctx->proxy, ctx->msg_content, content_len);
|
||||
|
||||
if (content_len > 0)
|
||||
proxy_dump(ctx->proxy, ctx->msg_content, content_len);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user