Skip to content

Commit 1455c35

Browse files
committed
add: utility property source.cookiesObj
1 parent cb97329 commit 1455c35

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var HTTPSnippet = function (req, lang) {
3434
// construct query string object
3535
this.source.queryObj = {}
3636
this.source.headersObj = {}
37+
this.source.cookiesObj = {}
3738
this.source.allHeaders = {}
3839
this.source.postData.jsonObj = false
3940
this.source.postData.paramsObj = false
@@ -54,6 +55,14 @@ var HTTPSnippet = function (req, lang) {
5455
}, {})
5556
}
5657

58+
// construct headers objects
59+
if (this.source.cookies && this.source.cookies.length) {
60+
this.source.cookiesObj = this.source.cookies.reduceRight(function (cookies, cookie) {
61+
cookies[cookie.name] = cookie.value
62+
return cookies
63+
}, {})
64+
}
65+
5766
// construct Cookie header
5867
var cookies = this.source.cookies.map(function (cookie) {
5968
return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value)

0 commit comments

Comments
 (0)