diff options
author | 2025-01-22 10:31:22 -0500 | |
---|---|---|
committer | 2025-01-23 18:28:21 +0000 | |
commit | 7267149267fae4bb814af441fabb42767c1a720d (patch) | |
tree | 20007e98b8deb81d530fd8f7188f2ffd5aa3cd8c /src/plugins/hs_apps/proxy.c | |
parent | 6501202fa02300ebafdb3d799bbe13e1617ac57c (diff) |
http: move header serialization to http transport
Apps called http_serialize_headers, which creates plain text buffer,
this is now hidden in http transport layer and apps pass headers in
generic form, so they can be encoded based on http version.
Type: improvement
Change-Id: Ie4fa0516cd3406d60f956751c8ee7ab40e633fa4
Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'src/plugins/hs_apps/proxy.c')
-rw-r--r-- | src/plugins/hs_apps/proxy.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/plugins/hs_apps/proxy.c b/src/plugins/hs_apps/proxy.c index 38d96bbf5ac..1bcc1e85a17 100644 --- a/src/plugins/hs_apps/proxy.c +++ b/src/plugins/hs_apps/proxy.c @@ -63,32 +63,39 @@ proxy_session_side_ctx_get (proxy_worker_t *wrk, u32 ctx_index) } static_always_inline void -proxy_send_http_resp (session_t *s, http_status_code_t sc, u8 *headers_buf) +proxy_send_http_resp (session_t *s, http_status_code_t sc, + http_headers_ctx_t *headers) { http_msg_t msg; int rv; uword headers_ptr; + svm_fifo_seg_t seg[2]; + u32 n_segs = 1; ASSERT (s->thread_index == vlib_get_thread_index ()); + msg.data.headers_len = 0; + if (headers) + { + msg.data.headers_len = headers->tail_offset; + headers_ptr = pointer_to_uword (headers->buf); + seg[1].data = (u8 *) &headers_ptr; + seg[1].len = sizeof (headers_ptr); + n_segs = 2; + } msg.type = HTTP_MSG_REPLY; msg.code = sc; msg.data.type = HTTP_MSG_DATA_PTR; - msg.data.headers_len = vec_len (headers_buf); msg.data.len = msg.data.headers_len; msg.data.headers_offset = 0; msg.data.body_len = 0; msg.data.body_offset = 0; + seg[0].data = (u8 *) &msg; + seg[0].len = sizeof (msg); - headers_ptr = pointer_to_uword (headers_buf); - svm_fifo_seg_t seg[2] = { - { (u8 *) &msg, sizeof (msg) }, - { (u8 *) &headers_ptr, sizeof (headers_ptr) }, - }; - - rv = svm_fifo_enqueue_segments (s->tx_fifo, seg, msg.data.len ? 2 : 1, - 0 /* allow partial */); - ASSERT (rv == (sizeof (msg) + (msg.data.len ? sizeof (headers_ptr) : 0))); + rv = + svm_fifo_enqueue_segments (s->tx_fifo, seg, n_segs, 0 /* allow partial */); + ASSERT (rv == (sizeof (msg) + (n_segs == 2 ? sizeof (headers_ptr) : 0))); if (svm_fifo_set_event (s->tx_fifo)) session_program_tx_io_evt (s->handle, SESSION_IO_EVT_TX); @@ -872,7 +879,7 @@ active_open_send_http_resp_rpc (void *arg) session_get_from_handle (ps->ao.session_handle)); if (ao_tp == TRANSPORT_PROTO_UDP) proxy_send_http_resp (po_s, HTTP_STATUS_SWITCHING_PROTOCOLS, - pm->capsule_proto_header); + &pm->capsule_proto_header); else proxy_send_http_resp (po_s, HTTP_STATUS_OK, 0); } @@ -1469,8 +1476,6 @@ VLIB_CLI_COMMAND (proxy_create_command, static) = { clib_error_t * proxy_main_init (vlib_main_t * vm) { - http_header_t *headers = 0; - proxy_main_t *pm = &proxy_main; pm->server_client_index = ~0; pm->active_open_client_index = ~0; @@ -1478,11 +1483,12 @@ proxy_main_init (vlib_main_t * vm) pm->idle_timeout = 600; /* connect-proxy default idle timeout 10 minutes */ vec_validate (pm->client_sep, TRANSPORT_N_PROTOS - 1); - http_add_header (&headers, - http_header_name_token (HTTP_HEADER_CAPSULE_PROTOCOL), + vec_validate (pm->capsule_proto_header_buf, 10); + http_init_headers_ctx (&pm->capsule_proto_header, + pm->capsule_proto_header_buf, + vec_len (pm->capsule_proto_header_buf)); + http_add_header (&pm->capsule_proto_header, HTTP_HEADER_CAPSULE_PROTOCOL, http_token_lit (HTTP_BOOLEAN_TRUE)); - pm->capsule_proto_header = http_serialize_headers (headers); - vec_free (headers); return 0; } |