@@ -51,6 +51,7 @@ <h1 class="title">Module <code>supertokens_python.framework.flask.flask_response
51
51
def __init__(self, response: Response):
52
52
super().__init__({})
53
53
self.response = response
54
+ self.original = response
54
55
self.headers: List[Any] = []
55
56
self.response_sent = False
56
57
self.status_set = False
@@ -72,53 +73,22 @@ <h1 class="title">Module <code>supertokens_python.framework.flask.flask_response
72
73
httponly: bool = False,
73
74
samesite: str = "lax",
74
75
):
75
- from werkzeug.http import dump_cookie
76
-
77
- if self.response is None:
78
- cookie = dump_cookie(
79
- key,
80
- value=value,
81
- expires=int(expires / 1000),
82
- path=path,
83
- domain=domain,
84
- secure=secure,
85
- httponly=httponly,
86
- samesite=samesite,
87
- )
88
- self.headers.append(("Set-Cookie", cookie))
89
- else:
90
- self.response.set_cookie(
91
- key,
92
- value=value,
93
- expires=expires / 1000,
94
- path=path,
95
- domain=domain,
96
- secure=secure,
97
- httponly=httponly,
98
- samesite=samesite,
99
- )
76
+ self.response.set_cookie(
77
+ key,
78
+ value=value,
79
+ expires=expires / 1000,
80
+ path=path,
81
+ domain=domain,
82
+ secure=secure,
83
+ httponly=httponly,
84
+ samesite=samesite,
85
+ )
100
86
101
87
def set_header(self, key: str, value: str):
102
- if self.response is None:
103
- # TODO in the future the headrs must be validated..
104
- # if not isinstance(value, str):
105
- # raise TypeError("Value should be unicode.")
106
- if "\n" in value or "\r" in value:
107
- raise ValueError(
108
- "Detected newline in header value. This is "
109
- "a potential security problem"
110
- )
111
- self.headers.append((key, value))
112
- else:
113
- self.response.headers.add(key, value)
88
+ self.response.headers.add(key, value)
114
89
115
90
def get_header(self, key: str) -> Union[None, str]:
116
- if self.response is not None:
117
- return self.response.headers.get(key)
118
- for value in self.headers:
119
- if value[0] == key:
120
- return value[1]
121
- return None
91
+ return self.response.headers.get(key)
122
92
123
93
def set_status_code(self, status_code: int):
124
94
if not self.status_set:
@@ -127,8 +97,6 @@ <h1 class="title">Module <code>supertokens_python.framework.flask.flask_response
127
97
self.status_set = True
128
98
129
99
def get_headers(self):
130
- if self.response is None:
131
- return self.headers
132
100
return self.response.headers
133
101
134
102
def set_json_content(self, content: Dict[str, Any]):
@@ -170,6 +138,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
170
138
def __init__(self, response: Response):
171
139
super().__init__({})
172
140
self.response = response
141
+ self.original = response
173
142
self.headers: List[Any] = []
174
143
self.response_sent = False
175
144
self.status_set = False
@@ -191,53 +160,22 @@ <h2 class="section-title" id="header-classes">Classes</h2>
191
160
httponly: bool = False,
192
161
samesite: str = "lax",
193
162
):
194
- from werkzeug.http import dump_cookie
195
-
196
- if self.response is None:
197
- cookie = dump_cookie(
198
- key,
199
- value=value,
200
- expires=int(expires / 1000),
201
- path=path,
202
- domain=domain,
203
- secure=secure,
204
- httponly=httponly,
205
- samesite=samesite,
206
- )
207
- self.headers.append(("Set-Cookie", cookie))
208
- else:
209
- self.response.set_cookie(
210
- key,
211
- value=value,
212
- expires=expires / 1000,
213
- path=path,
214
- domain=domain,
215
- secure=secure,
216
- httponly=httponly,
217
- samesite=samesite,
218
- )
163
+ self.response.set_cookie(
164
+ key,
165
+ value=value,
166
+ expires=expires / 1000,
167
+ path=path,
168
+ domain=domain,
169
+ secure=secure,
170
+ httponly=httponly,
171
+ samesite=samesite,
172
+ )
219
173
220
174
def set_header(self, key: str, value: str):
221
- if self.response is None:
222
- # TODO in the future the headrs must be validated..
223
- # if not isinstance(value, str):
224
- # raise TypeError("Value should be unicode.")
225
- if "\n" in value or "\r" in value:
226
- raise ValueError(
227
- "Detected newline in header value. This is "
228
- "a potential security problem"
229
- )
230
- self.headers.append((key, value))
231
- else:
232
- self.response.headers.add(key, value)
175
+ self.response.headers.add(key, value)
233
176
234
177
def get_header(self, key: str) -> Union[None, str]:
235
- if self.response is not None:
236
- return self.response.headers.get(key)
237
- for value in self.headers:
238
- if value[0] == key:
239
- return value[1]
240
- return None
178
+ return self.response.headers.get(key)
241
179
242
180
def set_status_code(self, status_code: int):
243
181
if not self.status_set:
@@ -246,8 +184,6 @@ <h2 class="section-title" id="header-classes">Classes</h2>
246
184
self.status_set = True
247
185
248
186
def get_headers(self):
249
- if self.response is None:
250
- return self.headers
251
187
return self.response.headers
252
188
253
189
def set_json_content(self, content: Dict[str, Any]):
@@ -302,12 +238,7 @@ <h3>Methods</h3>
302
238
< span > Expand source code</ span >
303
239
</ summary >
304
240
< pre > < code class ="python "> def get_header(self, key: str) -> Union[None, str]:
305
- if self.response is not None:
306
- return self.response.headers.get(key)
307
- for value in self.headers:
308
- if value[0] == key:
309
- return value[1]
310
- return None</ code > </ pre >
241
+ return self.response.headers.get(key)</ code > </ pre >
311
242
</ details >
312
243
</ dd >
313
244
< dt id ="supertokens_python.framework.flask.flask_response.FlaskResponse.get_headers "> < code class ="name flex ">
@@ -320,8 +251,6 @@ <h3>Methods</h3>
320
251
< span > Expand source code</ span >
321
252
</ summary >
322
253
< pre > < code class ="python "> def get_headers(self):
323
- if self.response is None:
324
- return self.headers
325
254
return self.response.headers</ code > </ pre >
326
255
</ details >
327
256
</ dd >
@@ -345,31 +274,16 @@ <h3>Methods</h3>
345
274
httponly: bool = False,
346
275
samesite: str = "lax",
347
276
):
348
- from werkzeug.http import dump_cookie
349
-
350
- if self.response is None:
351
- cookie = dump_cookie(
352
- key,
353
- value=value,
354
- expires=int(expires / 1000),
355
- path=path,
356
- domain=domain,
357
- secure=secure,
358
- httponly=httponly,
359
- samesite=samesite,
360
- )
361
- self.headers.append(("Set-Cookie", cookie))
362
- else:
363
- self.response.set_cookie(
364
- key,
365
- value=value,
366
- expires=expires / 1000,
367
- path=path,
368
- domain=domain,
369
- secure=secure,
370
- httponly=httponly,
371
- samesite=samesite,
372
- )</ code > </ pre >
277
+ self.response.set_cookie(
278
+ key,
279
+ value=value,
280
+ expires=expires / 1000,
281
+ path=path,
282
+ domain=domain,
283
+ secure=secure,
284
+ httponly=httponly,
285
+ samesite=samesite,
286
+ )</ code > </ pre >
373
287
</ details >
374
288
</ dd >
375
289
< dt id ="supertokens_python.framework.flask.flask_response.FlaskResponse.set_header "> < code class ="name flex ">
@@ -382,18 +296,7 @@ <h3>Methods</h3>
382
296
< span > Expand source code</ span >
383
297
</ summary >
384
298
< pre > < code class ="python "> def set_header(self, key: str, value: str):
385
- if self.response is None:
386
- # TODO in the future the headrs must be validated..
387
- # if not isinstance(value, str):
388
- # raise TypeError("Value should be unicode.")
389
- if "\n" in value or "\r" in value:
390
- raise ValueError(
391
- "Detected newline in header value. This is "
392
- "a potential security problem"
393
- )
394
- self.headers.append((key, value))
395
- else:
396
- self.response.headers.add(key, value)</ code > </ pre >
299
+ self.response.headers.add(key, value)</ code > </ pre >
397
300
</ details >
398
301
</ dd >
399
302
< dt id ="supertokens_python.framework.flask.flask_response.FlaskResponse.set_html_content "> < code class ="name flex ">
0 commit comments