@@ -23,6 +23,7 @@ class FlaskResponse(BaseResponse):
23
23
def __init__ (self , response : Response ):
24
24
super ().__init__ ({})
25
25
self .response = response
26
+ self .original = response
26
27
self .headers : List [Any ] = []
27
28
self .response_sent = False
28
29
self .status_set = False
@@ -44,53 +45,22 @@ def set_cookie(
44
45
httponly : bool = False ,
45
46
samesite : str = "lax" ,
46
47
):
47
- from werkzeug .http import dump_cookie
48
-
49
- if self .response is None :
50
- cookie = dump_cookie (
51
- key ,
52
- value = value ,
53
- expires = int (expires / 1000 ),
54
- path = path ,
55
- domain = domain ,
56
- secure = secure ,
57
- httponly = httponly ,
58
- samesite = samesite ,
59
- )
60
- self .headers .append (("Set-Cookie" , cookie ))
61
- else :
62
- self .response .set_cookie (
63
- key ,
64
- value = value ,
65
- expires = expires / 1000 ,
66
- path = path ,
67
- domain = domain ,
68
- secure = secure ,
69
- httponly = httponly ,
70
- samesite = samesite ,
71
- )
48
+ self .response .set_cookie (
49
+ key ,
50
+ value = value ,
51
+ expires = expires / 1000 ,
52
+ path = path ,
53
+ domain = domain ,
54
+ secure = secure ,
55
+ httponly = httponly ,
56
+ samesite = samesite ,
57
+ )
72
58
73
59
def set_header (self , key : str , value : str ):
74
- if self .response is None :
75
- # TODO in the future the headrs must be validated..
76
- # if not isinstance(value, str):
77
- # raise TypeError("Value should be unicode.")
78
- if "\n " in value or "\r " in value :
79
- raise ValueError (
80
- "Detected newline in header value. This is "
81
- "a potential security problem"
82
- )
83
- self .headers .append ((key , value ))
84
- else :
85
- self .response .headers .add (key , value )
60
+ self .response .headers .add (key , value )
86
61
87
62
def get_header (self , key : str ) -> Union [None , str ]:
88
- if self .response is not None :
89
- return self .response .headers .get (key )
90
- for value in self .headers :
91
- if value [0 ] == key :
92
- return value [1 ]
93
- return None
63
+ return self .response .headers .get (key )
94
64
95
65
def set_status_code (self , status_code : int ):
96
66
if not self .status_set :
@@ -99,8 +69,6 @@ def set_status_code(self, status_code: int):
99
69
self .status_set = True
100
70
101
71
def get_headers (self ):
102
- if self .response is None :
103
- return self .headers
104
72
return self .response .headers
105
73
106
74
def set_json_content (self , content : Dict [str , Any ]):
0 commit comments