Skip to content

Commit

Permalink
Merge pull request #137 from yetamrra/host_port_quirk
Browse files Browse the repository at this point in the history
Add quirk to force port in Host header
  • Loading branch information
alexpevzner committed Apr 15, 2021
2 parents 5c35910 + 5d175bb commit 8e8ea91
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
16 changes: 15 additions & 1 deletion airscan-escl.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct {
/* Miscellaneous flags */
bool quirk_localhost; /* Set Host: localhost in ScanJobs rq */
bool quirk_canon_mf410_series; /* Canon MF410 Series */
bool quirk_port_in_host; /* Always set port in Host: header */
} proto_handler_escl;

/* XML namespace for XML writer
Expand Down Expand Up @@ -85,8 +86,13 @@ static http_query*
escl_http_query (const proto_ctx *ctx, const char *path,
const char *method, char *body)
{
return http_query_new_relative(ctx->http, ctx->base_uri, path,
proto_handler_escl *escl = (proto_handler_escl*) ctx->proto;
http_query *query = http_query_new_relative(ctx->http, ctx->base_uri, path,
method, body, "text/xml");
if (escl->quirk_port_in_host) {
http_query_force_port(query, true);
}
return query;
}

/* Create HTTP get query
Expand Down Expand Up @@ -480,6 +486,14 @@ escl_devcaps_parse (proto_handler_escl *escl,
escl->quirk_localhost = true;
} else if (!strcmp(m, "MF410 Series")) {
escl->quirk_canon_mf410_series = true;
} else if (!strncasecmp(m, "EPSON ", 6)) {
escl->quirk_port_in_host = true;
}
} else if (xml_rd_node_name_match(xml, "scan:Manufacturer")) {
const char *m = xml_rd_node_value(xml);

if (!strcasecmp(m, "EPSON")) {
escl->quirk_port_in_host = true;
}
} else if (xml_rd_node_name_match(xml, "scan:Platen")) {
xml_rd_enter(xml);
Expand Down
14 changes: 14 additions & 0 deletions airscan-http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,7 @@ struct http_query {
http_hdr request_header; /* Request header */
http_hdr response_header; /* Response header */
bool host_inserted; /* Host: auto-inserted */
bool force_port; /* Host: always includes port */

/* HTTP redirects */
int redirect_count; /* Count of redirects */
Expand Down Expand Up @@ -2126,6 +2127,9 @@ http_query_set_host (http_query *q)
dport = -1;
break;
}
if (q->force_port) {
dport = -1;
}

s = ip_straddr_from_sockaddr_dport(addr, dport, false);
http_query_set_request_header(q, "Host", s.text);
Expand Down Expand Up @@ -2272,6 +2276,16 @@ http_query_timeout_cancel (http_query *q)
}
}

/* Set forcing port to be added to the Host header for this query.
*
* This function may be called multiple times (each subsequent call overrides
* a previous one).
*/
void
http_query_force_port(http_query *q, bool force_port) {
q->force_port = force_port;
}

/* For this particular query override on-error callback, previously
* set by http_client_onerror()
*
Expand Down
8 changes: 8 additions & 0 deletions airscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,14 @@ http_query_new_relative(http_client *client,
void
http_query_timeout (http_query *q, int timeout);

/* Set forcing port to be added to the Host header for this query.
*
* This function may be called multiple times (each subsequent call overrides
* a previous one).
*/
void
http_query_force_port(http_query *q, bool force_port);

/* For this particular query override on-error callback, previously
* set by http_client_onerror()
*
Expand Down

0 comments on commit 8e8ea91

Please sign in to comment.