File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -301,6 +301,47 @@ You can use the `MAX_HEADER_SIZE` environment variable to set a maximum header s
301301docker run -d --rm -e MAX_HEADER_SIZE=1000 -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:39
302302```
303303
304+ ## Cookies and Signed Cookies
305+
306+ Make a request with a ` Cookie ` header and the response will include the cookies:
307+
308+ ``` bash
309+ docker run -d --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:39
310+ ```
311+
312+ Then make a request with a cookie header:
313+
314+ ``` bash
315+ curl -s http://localhost:8080/ -H " Cookie: foo=bar; baz=qux"
316+ ```
317+
318+ To enable signed cookie support, set the ` COOKIE_SECRET ` environment variable. Signed cookies appear in the ` signedCookies ` section of the response:
319+
320+ ``` bash
321+ docker run -d --rm -e COOKIE_SECRET=mysecretkey123 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:39
322+ ```
323+
324+ Now you need to generate a signed cookie, and send it in the header. Here's a convenience node snippet:
325+
326+ ``` bash
327+
328+ SIGNED_COOKIE=$( node -e " var crypto = require('crypto');
329+
330+ function sign(val, secret){
331+ return val + '.' + crypto
332+ .createHmac('sha256', secret)
333+ .update(val)
334+ .digest('base64')
335+ .replace(/=+$/, '');
336+ };
337+
338+ console.log(sign('my-value','mysecretkey123'));" )
339+
340+ curl -s http://localhost:8080/ -H " Cookie: mysigned=s:$SIGNED_COOKIE " | jq ' .signedCookies'
341+ ```
342+
343+ Notice the ` s: ` prefix in the cookie value, that is important.
344+
304345
305346## Prometheus Metrics
306347
You can’t perform that action at this time.
0 commit comments