@@ -85,6 +85,11 @@ class SetCookie implements MultipleHeaderInterface
85
85
*/
86
86
protected $ httponly ;
87
87
88
+ /**
89
+ * @var bool
90
+ */
91
+ protected $ encodeValue = true ;
92
+
88
93
/**
89
94
* @static
90
95
* @throws Exception\InvalidArgumentException
@@ -99,6 +104,7 @@ public static function fromString($headerLine, $bypassHeaderFieldName = false)
99
104
if ($ setCookieProcessor === null ) {
100
105
$ setCookieClass = get_called_class ();
101
106
$ setCookieProcessor = function ($ headerLine ) use ($ setCookieClass ) {
107
+ /** @var SetCookie $header */
102
108
$ header = new $ setCookieClass ();
103
109
$ keyValuePairs = preg_split ('#;\s*# ' , $ headerLine );
104
110
@@ -115,6 +121,11 @@ public static function fromString($headerLine, $bypassHeaderFieldName = false)
115
121
if ($ header ->getName () === null ) {
116
122
$ header ->setName ($ headerKey );
117
123
$ header ->setValue (urldecode ($ headerValue ));
124
+
125
+ // set no encode value if raw and encoded values are the same
126
+ if (urldecode ($ headerValue ) === $ headerValue ) {
127
+ $ header ->setEncodeValue (false );
128
+ }
118
129
continue ;
119
130
}
120
131
@@ -213,6 +224,22 @@ public function __construct(
213
224
->setHttpOnly ($ httponly );
214
225
}
215
226
227
+ /**
228
+ * @return bool
229
+ */
230
+ public function getEncodeValue ()
231
+ {
232
+ return $ this ->encodeValue ;
233
+ }
234
+
235
+ /**
236
+ * @param bool $encodeValue
237
+ */
238
+ public function setEncodeValue ($ encodeValue )
239
+ {
240
+ $ this ->encodeValue = (bool ) $ encodeValue ;
241
+ }
242
+
216
243
/**
217
244
* @return string 'Set-Cookie'
218
245
*/
@@ -231,7 +258,7 @@ public function getFieldValue()
231
258
return '' ;
232
259
}
233
260
234
- $ value = urlencode ($ this ->getValue ());
261
+ $ value = $ this -> encodeValue ? urlencode ($ this ->getValue ()) : $ this -> getValue ( );
235
262
if ($ this ->hasQuoteFieldValue ()) {
236
263
$ value = '" ' . $ value . '" ' ;
237
264
}
0 commit comments