MCO_RET mco_lews_get_header_value(const char *buffer, mco_uint2 buffer_size,
const char *header_name, char *out_buf, mco_uint2 out_buf_size);
buffer
buffer_size
buffer.header_name
"Host").out_buf
out_buf_size
out_buf buffer.This function searches the provided HTTP header block for a header matching
header_nameand copies its value intoout_buf, ensuring it is null-terminated.Header names are matched case-insensitively, as per RFC 7230.
lews_connection_context_t ctx; ... /* Incoming buffer contains the following request: "POST /login?log=usr&noval&pwd=qwe HTTP/1.1\r\n" "Host: example.com\r\n" "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n" "Content-Length: 26\r\n\r\n" "login=user&password=qwerty&novalue&num=123"; */ ... rc = mco_lews_get_header_value((char*)(&ctx.incoming_buf) + ctx.header_pos, ctx.header_len, "Host", tmp_buf, sizeof(tmp_buf)); ASSERT_EQ(MCO_S_OK, rc); ASSERT_STREQ("example.com", tmp_buf); rc = mco_lews_get_header_value((char*)(&ctx.incoming_buf) + ctx.header_pos, ctx.header_len, "Content-Length", tmp_buf, sizeof(tmp_buf)); ASSERT_EQ(MCO_S_OK, rc); ASSERT_STREQ("26", tmp_buf); rc = mco_lews_get_header_value((char*)(&ctx.incoming_buf) + ctx.header_pos, ctx.header_len, "SOMETHING", tmp_buf, sizeof(tmp_buf)); ASSERT_EQ(MCO_E_LEWS_NONEXISTENT_PARAMETER, rc);
MCO_S_OK
out_buf.MCO_E_LEWS_NONEXISTENT_PARAMETER
MCO_E_LEWS_NO_ENOUGH_MEMORY
out_buf is too small to hold the header value (including the null terminator).