]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proto_htx: Add functions htx_send_name_header
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 24 Oct 2018 19:15:35 +0000 (21:15 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 18 Nov 2018 21:08:58 +0000 (22:08 +0100)
It is more or less the same than legacy version but adapted to be called from
HTX analyzers. In the legacy version of this function, we switch on the HTX code
when applicable.

include/proto/proto_http.h
src/proto_http.c
src/proto_htx.c

index 2961eaee4c95eadb60dd9a1b39b1742c0d444807..40e82b2c361faa05d07dd0cf4c7a62eb331ffc77 100644 (file)
@@ -61,7 +61,6 @@ int htx_process_req_common(struct stream *s, struct channel *req, int an_bit, st
 int htx_process_request(struct stream *s, struct channel *req, int an_bit);
 int htx_process_tarpit(struct stream *s, struct channel *req, int an_bit);
 int htx_wait_for_request_body(struct stream *s, struct channel *req, int an_bit);
-int htx_send_name_header(struct http_txn *txn, struct proxy* be, const char* svr_name);
 int htx_wait_for_response(struct stream *s, struct channel *rep, int an_bit);
 int htx_process_res_common(struct stream *s, struct channel *rep, int an_bit, struct proxy *px);
 int htx_request_forward_body(struct stream *s, struct channel *req, int an_bit);
@@ -75,6 +74,7 @@ int htx_req_replace_stline(int action, const char *replace, int len,
 void htx_res_set_status(unsigned int status, const char *reason, struct stream *s);
 void htx_check_request_for_cacheability(struct stream *s, struct channel *req);
 void htx_check_response_for_cacheability(struct stream *s, struct channel *res);
+int htx_send_name_header(struct stream *s, struct proxy *be, const char *srv_name);
 void htx_server_error(struct stream *s, struct stream_interface *si, int err, int finst, const struct buffer *msg);
 void htx_reply_and_close(struct stream *s, short status, struct buffer *msg);
 
index 25b85fff778dfc3943ff8f1a1e0c8f031cdbf5b6..fc46826b5c4148ce6c662f0b61c50c5aa11c69f0 100644 (file)
@@ -3683,6 +3683,8 @@ int http_send_name_header(struct stream *s, struct proxy* be, const char* srv_na
        char *hdr_val;
        unsigned int old_o, old_i;
 
+       if (IS_HTX_STRM(s))
+               return htx_send_name_header(s, be, srv_name);
        ctx.idx = 0;
 
        old_o = http_hdr_rewind(&txn->req);
index 0dd17c8b86a0d58997bfb20e8f4067e45861c534..d7dbabac9c6c494e45bd4cad25cd18f6b8b95636 100644 (file)
@@ -4735,6 +4735,36 @@ void htx_check_response_for_cacheability(struct stream *s, struct channel *res)
        }
 }
 
+/* send a server's name with an outgoing request over an established connection.
+ * Note: this function is designed to be called once the request has been
+ * scheduled for being forwarded. This is the reason why the number of forwarded
+ * bytes have to be adjusted.
+ */
+int htx_send_name_header(struct stream *s, struct proxy *be, const char *srv_name)
+{
+       struct htx *htx;
+       struct http_hdr_ctx ctx;
+       struct ist hdr;
+       uint32_t data;
+
+       hdr = ist2(be->server_id_hdr_name, be->server_id_hdr_len);
+       htx = htx_from_buf(&s->req.buf);
+       data = htx->data;
+
+       ctx.blk = NULL;
+       while (http_find_header(htx, hdr, &ctx, 1))
+               http_remove_header(htx, &ctx);
+       http_add_header(htx, hdr, ist2(srv_name, strlen(srv_name)));
+
+       if (co_data(&s->req)) {
+               if (data >= htx->data)
+                       c_rew(&s->req, data - htx->data);
+               else
+                       c_adv(&s->req, htx->data - data);
+       }
+       return 0;
+}
+
 /* This function terminates the request because it was completly analyzed or
  * because an error was triggered during the body forwarding.
  */