@@ -29,7 +29,7 @@ class HTTPResponse:
29
29
status : HTTPStatus
30
30
headers : Dict [str , str ]
31
31
content_type : str
32
-
32
+ cache : Optional [ int ]
33
33
filename : Optional [str ]
34
34
root_path : str
35
35
@@ -41,6 +41,7 @@ def __init__( # pylint: disable=too-many-arguments
41
41
body : str = "" ,
42
42
headers : Dict [str , str ] = None ,
43
43
content_type : str = MIMEType .TYPE_TXT ,
44
+ cache : Optional [int ] = 0 ,
44
45
filename : Optional [str ] = None ,
45
46
root_path : str = "" ,
46
47
http_version : str = "HTTP/1.1" ,
@@ -54,6 +55,7 @@ def __init__( # pylint: disable=too-many-arguments
54
55
self .body = body
55
56
self .headers = headers or {}
56
57
self .content_type = content_type
58
+ self .cache = cache
57
59
self .filename = filename
58
60
self .root_path = root_path
59
61
self .http_version = http_version
@@ -64,6 +66,7 @@ def _construct_response_bytes( # pylint: disable=too-many-arguments
64
66
status : HTTPStatus = CommonHTTPStatus .OK_200 ,
65
67
content_type : str = MIMEType .TYPE_TXT ,
66
68
content_length : Union [int , None ] = None ,
69
+ cache : int = 0 ,
67
70
headers : Dict [str , str ] = None ,
68
71
body : str = "" ,
69
72
) -> bytes :
@@ -81,6 +84,8 @@ def _construct_response_bytes( # pylint: disable=too-many-arguments
81
84
for header , value in response_headers .items ():
82
85
response += f"{ header } : { value } \r \n "
83
86
87
+ response += f"Cache-Control: max-age={ cache } \r \n "
88
+
84
89
response += f"\r \n { body } "
85
90
86
91
return response .encode ("utf-8" )
@@ -129,6 +134,7 @@ def _send_response( # pylint: disable=too-many-arguments
129
134
self ._construct_response_bytes (
130
135
status = status ,
131
136
content_type = content_type ,
137
+ cache = self .cache ,
132
138
headers = headers ,
133
139
body = body ,
134
140
),
@@ -148,6 +154,7 @@ def _send_file_response( # pylint: disable=too-many-arguments
148
154
status = self .status ,
149
155
content_type = MIMEType .from_file_name (filename ),
150
156
content_length = file_length ,
157
+ cache = self .cache ,
151
158
headers = headers ,
152
159
),
153
160
)
0 commit comments