Skip to content

Commit 2628cd5

Browse files
author
Arian Stolwijk
committed
Merge pull request #2676 from DimitarChristoff/feature-httponly-cookie
httpOnly cookies
2 parents 91dc077 + 12967ae commit 2628cd5

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Docs/Utilities/Cookie.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Reads and writes a cookie.
88
* path - (*string*: defaults to '/') The path the cookie belongs to.
99
* duration - (*number*: defaults to false) The duration of the cookie (in days) before it expires. If set to false or 0, the cookie will be a session cookie that expires when the browser is closed.
1010
* secure - (*boolean*: defaults to false) Stored cookie information can be accessed only from a secure environment.
11+
* httpOnly - (*boolean*: defaults to false) Stored cookie information can be accessed only on the server.
1112

1213
## Cookie Method: write {#Cookie:write}
1314

Source/Utilities/Cookie.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ var Cookie = new Class({
2727
duration: false,
2828
secure: false,
2929
document: document,
30-
encode: true
30+
encode: true,
31+
httpOnly: false
3132
},
3233

3334
initialize: function(key, options){
@@ -45,6 +46,7 @@ var Cookie = new Class({
4546
value += '; expires=' + date.toGMTString();
4647
}
4748
if (this.options.secure) value += '; secure';
49+
if (this.options.httpOnly) value += '; HttpOnly';
4850
this.options.document.cookie = this.key + '=' + value;
4951
return this;
5052
},

Specs/Utilities/Cookie.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ describe('Cookie', function(){
2828
expect(Cookie.read('key', options)).toBeNull();
2929
});
3030

31+
it('should set HttpCookie flag correctly', function(){
32+
Cookie.write('http-key', 'value', {
33+
httpOnly: true
34+
});
35+
36+
expect(Cookie.read('http-key')).toBeNull();
37+
});
38+
3139
});

0 commit comments

Comments
 (0)