4
4
__copyright__ = "Copyright (C) 2023 Tempesta Technologies, Inc."
5
5
__license__ = "GPL2"
6
6
7
+ import unittest
8
+
7
9
from framework import tester
8
10
from helpers .deproxy import H2Response , HttpMessage , Request , Response
9
11
12
+ MAX_HEADER_NAME = 1024 # See fw/http_parser.c HTTP_MAX_HDR_NAME_LEN
13
+
10
14
11
15
def generate_http1_request (optional_headers = []) -> str :
12
16
return (
@@ -261,8 +265,8 @@ def test_delete_many_special_headers(self):
261
265
"""
262
266
Headers must be removed from base request/response if header is in base request/response.
263
267
"""
264
- header_name = "set-cookie" if self .directive == "resp" else "if-none-match "
265
- header_value = "test=cookie" if self .directive == "resp" else '"qwe"'
268
+ header_name = "set-cookie" if self .directive == "resp" else "forwarded "
269
+ header_value = "test=cookie" if self .directive == "resp" else "for=tempesta.com"
266
270
client , server = self .base_scenario (
267
271
config = f"{ self .directive } _hdr_set { header_name } ;\n " ,
268
272
optional_headers = [(header_name , header_value ), (header_name , header_value )],
@@ -291,6 +295,37 @@ def test_set_large_header(self):
291
295
expected_headers = [("x-my-hdr" , "12" * 2000 )],
292
296
)
293
297
298
+ def test_set_long_header_name (self ):
299
+ self .base_scenario (
300
+ config = (
301
+ f'{ self .directive } _hdr_set { "a" * MAX_HEADER_NAME } "value";\n '
302
+ f'{ self .directive } _hdr_set { "b" * MAX_HEADER_NAME } "value";\n '
303
+ f'{ self .directive } _hdr_set { "c" * MAX_HEADER_NAME } "value";\n '
304
+ f'{ self .directive } _hdr_set { "d" * MAX_HEADER_NAME } "value";\n '
305
+ ),
306
+ optional_headers = [],
307
+ expected_headers = [
308
+ ("a" * MAX_HEADER_NAME , "value" ),
309
+ ("b" * MAX_HEADER_NAME , "value" ),
310
+ ("c" * MAX_HEADER_NAME , "value" ),
311
+ ("d" * MAX_HEADER_NAME , "value" ),
312
+ ],
313
+ )
314
+
315
+ def test_long_header_name (self ):
316
+ self .base_scenario (
317
+ config = f'{ self .directive } _hdr_set { "a" * MAX_HEADER_NAME } "value1";\n ' ,
318
+ optional_headers = [
319
+ ("a" * MAX_HEADER_NAME , "value" ),
320
+ ("a" * MAX_HEADER_NAME , "value" ),
321
+ ("a" * MAX_HEADER_NAME , "value" ),
322
+ ("a" * MAX_HEADER_NAME , "value" ),
323
+ ],
324
+ expected_headers = [
325
+ ("a" * MAX_HEADER_NAME , "value1" ),
326
+ ],
327
+ )
328
+
294
329
295
330
class H2Config :
296
331
clients = [
@@ -407,7 +442,7 @@ def test_add_header_from_static_table(self):
407
442
expected_headers = [("cache-control" , "no-cache" )],
408
443
)
409
444
410
- self .assertIn (b"\x08 no-cache" , client .response_buffer )
445
+ self .assertIn (b"\x08 no-cache" , client .last_response_buffer )
411
446
412
447
def test_add_header_from_dynamic_table (self ):
413
448
"""Tempesta must add header from dynamic table for second response."""
@@ -426,11 +461,11 @@ def test_add_header_from_dynamic_table(self):
426
461
server .set_response (generate_response (optional_headers ))
427
462
428
463
client .send_request (request , "200" )
429
- self .assertIn (b"\x08 x-my-hdr\x04 text" , client .response_buffer )
464
+ self .assertIn (b"\x08 x-my-hdr\x04 text" , client .last_response_buffer )
430
465
431
466
client .send_request (request , "200" )
432
- self .assertNotIn (b"\n x -my-hdr\x04 text" , client .response_buffer )
433
- self .assertIn (b"\xbe " , client .response_buffer )
467
+ self .assertNotIn (b"x -my-hdr\x04 text" , client .last_response_buffer )
468
+ self .assertIn (b"\xbe " , client .last_response_buffer )
434
469
435
470
436
471
class TestCachedRespHeaderH2 (H2Config , TestLogicBase ):
@@ -439,6 +474,9 @@ class TestCachedRespHeaderH2(H2Config, TestLogicBase):
439
474
requests_n = 2
440
475
h2 = True
441
476
477
+ def test_add_header_from_static_table (self ):
478
+ TestRespHeaderH2 .test_add_header_from_static_table (self )
479
+
442
480
443
481
class TestManyRequestHeadersH2 (H2Config , TestManyRequestHeaders ):
444
482
cache = False
0 commit comments