src: http2::add_header: strip white spaces in value
This commit is contained in:
parent
93ee9e30d8
commit
6f70a53da6
|
@ -316,6 +316,15 @@ Headers::value_type to_header(const uint8_t *name, size_t namelen,
|
|||
|
||||
void add_header(Headers &nva, const uint8_t *name, size_t namelen,
|
||||
const uint8_t *value, size_t valuelen, bool no_index) {
|
||||
if (valuelen > 0) {
|
||||
size_t i, j;
|
||||
for (i = 0; i < valuelen && (value[i] == ' ' || value[i] == '\t'); ++i)
|
||||
;
|
||||
for (j = valuelen - 1; j > i && (value[j] == ' ' || value[j] == '\t'); --j)
|
||||
;
|
||||
value += i;
|
||||
valuelen -= i + (valuelen - j - 1);
|
||||
}
|
||||
nva.push_back(to_header(name, namelen, value, valuelen, no_index));
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ Headers::value_type to_header(const uint8_t *name, size_t namelen,
|
|||
|
||||
// Add name/value pairs to |nva|. If |no_index| is true, this
|
||||
// name/value pair won't be indexed when it is forwarded to the next
|
||||
// hop.
|
||||
// hop. This function strips white spaces around |value|.
|
||||
void add_header(Headers &nva, const uint8_t *name, size_t namelen,
|
||||
const uint8_t *value, size_t valuelen, bool no_index);
|
||||
|
||||
|
|
|
@ -68,6 +68,36 @@ void test_http2_add_header(void) {
|
|||
true);
|
||||
CU_ASSERT(Headers::value_type("alpha", "") == nva[0]);
|
||||
CU_ASSERT(nva[0].no_index);
|
||||
|
||||
nva.clear();
|
||||
|
||||
http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)" b", 2,
|
||||
false);
|
||||
CU_ASSERT(Headers::value_type("a", "b") == nva[0]);
|
||||
|
||||
nva.clear();
|
||||
|
||||
http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)"b ", 2,
|
||||
false);
|
||||
CU_ASSERT(Headers::value_type("a", "b") == nva[0]);
|
||||
|
||||
nva.clear();
|
||||
|
||||
http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)" b ", 5,
|
||||
false);
|
||||
CU_ASSERT(Headers::value_type("a", "b") == nva[0]);
|
||||
|
||||
nva.clear();
|
||||
|
||||
http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)" bravo ",
|
||||
9, false);
|
||||
CU_ASSERT(Headers::value_type("a", "bravo") == nva[0]);
|
||||
|
||||
nva.clear();
|
||||
|
||||
http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)" ", 4,
|
||||
false);
|
||||
CU_ASSERT(Headers::value_type("a", "") == nva[0]);
|
||||
}
|
||||
|
||||
void test_http2_check_http2_headers(void) {
|
||||
|
|
Loading…
Reference in New Issue