Skip to content

Commit

Permalink
1.0.1: handle httpOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelzhang committed Aug 17, 2017
1 parent 9f1971a commit 7e5e274
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ handler.get('foo').value
// 'a'
```

## cs.from({domain, path, nonHTTP}) : Handler
## cs.from({domain, path, http}) : Handler

- **domain** `String`
- **path** `String`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cookie-store",
"version": "1.0.0",
"version": "1.0.1",
"description": "An RFC-6265 cookie store to implement the mechanism of HTTP cookie and Set-Cookie header fields as a browser do.",
"main": "lib/index.js",
"module": "src/index.js",
Expand Down
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ class SubStore {
this._store = store
this._http = http

this._match = cookie => cookie.match(this._domain, this._path)
this._match = this._match.bind(this)
}

_match (cookie) {
// domain and path should match
return cookie.match(this._domain, this._path)
// handle http-only-flag
&& (this._http || !cookie.httpOnly)
}

set (name, value, options) {
Expand Down Expand Up @@ -111,6 +118,7 @@ export default class CookieStore {
return new SubStore({
domain,
path,
http,
store: this._store
})
}
Expand Down
60 changes: 60 additions & 0 deletions test/cookie-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,66 @@ const testReturnType = (t, expect, to, description) => {
value: 'bar'
}
}
},

{
d: 'non-http apis',
s: [{
from: DEFAULT_FROM,
c: {
name: 'foo',
value: 'bar',
httpOnly: true
}
}, {
from: {
...DEFAULT_FROM,
http: false
},
c: [{
// try to override a httpOnly cookie
name: 'foo',
value: 'bar2',
returnNull: true
}, {
// try to create a httpOnly cookie
name: 'foo2',
value: 'bar',
httpOnly: true,
returnNull: true
}, {
name: 'foo3',
value: 'bar'
}]
}],
r: [{
from: DEFAULT_FROM,
c: [{
name: 'foo',
value: 'bar'
}, {
name: 'foo2',
isNull: true
}, {
name: 'foo3',
value: 'bar'
}]
}, {
from: {
...DEFAULT_FROM,
http: false
},
c: [{
name: 'foo',
isNull: true
}, {
name: 'foo2',
isNull: true
}, {
name: 'foo3',
value: 'bar'
}]
}]
}

].forEach(({
Expand Down

0 comments on commit 7e5e274

Please sign in to comment.