Skip to content

Commit 82b1208

Browse files
authored
Merge pull request #11 from mransan/add_cookie_parser_middleware
Add Cookie Parser support + `Request.{cookies|signedCookies}` API
2 parents bd26c38 + bf51a4e commit 82b1208

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/express.re

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ module Request = {
3636
external baseUrl: t => string = "" [@@bs.get];
3737
/** [baseUrl request] returns the 'baseUrl' property */
3838

39+
external cookies : t => option (Js.Dict.t Js.Json.t) = ""
40+
[@@bs.get][@@bs.return null_undefined_to_opt];
41+
/** When using cookie-parser middleware, this property is an object
42+
that contains cookies sent by the request. If the request contains
43+
no cookies, it defaults to {}.*/
44+
45+
external signedCookies: t => option (Js.Dict.t Js.Json.t) = ""
46+
[@@bs.get][@@bs.return null_undefined_to_opt];
47+
/** When using cookie-parser middleware, this property contains signed cookies
48+
sent by the request, unsigned and ready for use. Signed cookies reside in
49+
a different object to show developer intent; otherwise, a malicious attack
50+
could be placed on req.cookie values (which are easy to spoof).
51+
Note that signing a cookie does not make it “hidden” or encrypted;
52+
but simply prevents tampering (because the secret used to
53+
sign is private). **/
54+
3955
external hostname : t => string = "" [@@bs.get];
4056
/** [hostname request] Contains the hostname derived from the Host
4157
HTTP header.*/

tests/test.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ run_header_test 'Accepts Charsets' 'GET' 'Accept-Charset: UTF-8' \
6161
run_header_test 'Get' 'GET' 'key: value' \
6262
'/get'
6363

64-
# run_cookie_test() {
65-
# print_test_title "$1"
66-
# curl -X "$2" --cookie "$3" http://localhost:3000$4 2>&1 >> $TEST_DATA
67-
# }
68-
#
69-
# run_cookie_test 'Cookies' 'GET' 'key=value' '/cookies'
70-
7164
# compare test output to reference data
7265

7366
REFERENCE_DATA=reference.data

0 commit comments

Comments
 (0)