aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/hs_apps/http_tps.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/hs_apps/http_tps.c')
-rw-r--r--src/plugins/hs_apps/http_tps.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/src/plugins/hs_apps/http_tps.c b/src/plugins/hs_apps/http_tps.c
index f4ef808e410..59a0309e363 100644
--- a/src/plugins/hs_apps/http_tps.c
+++ b/src/plugins/hs_apps/http_tps.c
@@ -17,7 +17,6 @@
#include <vnet/session/application_interface.h>
#include <vnet/session/session.h>
#include <http/http.h>
-#include <http/http_header_names.h>
#include <http/http_content_types.h>
#define HTS_RX_BUF_SIZE (64 << 10)
@@ -41,7 +40,8 @@ typedef struct
};
u8 *uri;
u8 *rx_buf;
- http_header_t *resp_headers;
+ http_headers_ctx_t resp_headers;
+ u8 *resp_headers_buf;
} hts_session_t;
typedef struct hts_listen_cfg_
@@ -86,6 +86,7 @@ hts_session_alloc (u32 thread_index)
pool_get_zero (htm->sessions[thread_index], hs);
hs->session_index = hs - htm->sessions[thread_index];
hs->thread_index = thread_index;
+ vec_validate (hs->resp_headers_buf, 255);
return hs;
}
@@ -111,6 +112,7 @@ hts_session_free (hts_session_t *hs)
clib_warning ("Freeing session %u", hs->session_index);
vec_free (hs->rx_buf);
+ vec_free (hs->resp_headers_buf);
if (CLIB_DEBUG)
clib_memset (hs, 0xfa, sizeof (*hs));
@@ -233,26 +235,20 @@ hts_start_send_data (hts_session_t *hs, http_status_code_t status)
{
http_msg_t msg;
session_t *ts;
- u8 *headers_buf = 0;
u32 n_segs = 1;
svm_fifo_seg_t seg[2];
int rv;
- if (vec_len (hs->resp_headers))
+ msg.data.headers_offset = 0;
+ msg.data.headers_len = 0;
+
+ if (hs->resp_headers.tail_offset)
{
- headers_buf = http_serialize_headers (hs->resp_headers);
- vec_free (hs->resp_headers);
- msg.data.headers_offset = 0;
- msg.data.headers_len = vec_len (headers_buf);
- seg[1].data = headers_buf;
+ msg.data.headers_len = hs->resp_headers.tail_offset;
+ seg[1].data = hs->resp_headers_buf;
seg[1].len = msg.data.headers_len;
n_segs = 2;
}
- else
- {
- msg.data.headers_offset = 0;
- msg.data.headers_len = 0;
- }
msg.type = HTTP_MSG_REPLY;
msg.code = status;
@@ -266,7 +262,6 @@ hts_start_send_data (hts_session_t *hs, http_status_code_t status)
ts = session_get (hs->vpp_session_index, hs->thread_index);
rv = svm_fifo_enqueue_segments (ts->tx_fifo, seg, n_segs,
0 /* allow partial */);
- vec_free (headers_buf);
ASSERT (rv == (sizeof (msg) + msg.data.headers_len));
if (!msg.data.body_len)
@@ -320,8 +315,7 @@ try_test_file (hts_session_t *hs, u8 *target)
}
}
- http_add_header (&hs->resp_headers,
- http_header_name_token (HTTP_HEADER_CONTENT_TYPE),
+ http_add_header (&hs->resp_headers, HTTP_HEADER_CONTENT_TYPE,
http_content_type_token (HTTP_CONTENT_APP_OCTET_STREAM));
hts_start_send_data (hs, HTTP_STATUS_OK);
@@ -380,9 +374,9 @@ hts_ts_rx_callback (session_t *ts)
if (hs->left_recv == 0)
{
hs->data_len = 0;
- hs->resp_headers = 0;
hs->rx_buf = 0;
-
+ http_init_headers_ctx (&hs->resp_headers, hs->resp_headers_buf,
+ vec_len (hs->resp_headers_buf));
/* Read the http message header */
rv = svm_fifo_dequeue (ts->rx_fifo, sizeof (msg), (u8 *) &msg);
ASSERT (rv == sizeof (msg));
@@ -394,8 +388,7 @@ hts_ts_rx_callback (session_t *ts)
}
if (msg.method_type != HTTP_REQ_GET && msg.method_type != HTTP_REQ_POST)
{
- http_add_header (&hs->resp_headers,
- http_header_name_token (HTTP_HEADER_ALLOW),
+ http_add_header (&hs->resp_headers, HTTP_HEADER_ALLOW,
http_token_lit ("GET, POST"));
hts_start_send_data (hs, HTTP_STATUS_METHOD_NOT_ALLOWED);
goto done;