Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to pass option into unstate. #2105

Merged
merged 1 commit into from
Nov 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1955,8 +1955,10 @@ It provides the following methods:
- `msec` - the time-to-live value in milliseconds.
- `type(mimeType)` - sets the HTTP 'Content-Type' header where:
- `value` - is the mime type. Should only be used to override the built-in default for each response type.
- `unstate(name)` - clears the HTTP cookie by setting an expired value where:
- `unstate(name, [options])` - clears the HTTP cookie by setting an expired value where:
- `name` - the cookie name.
- `options` - optional configuration for expiring cookie. If the state was previously registered with the server using [`server.state()`](#serverstatename-options),
the specified keys in `options` override those same keys in the server definition (but not others).
- `vary(header)` - adds the provided header to the list of inputs affected the response generation via the HTTP 'Vary' header where:
- `header` - the HTTP request header name.

Expand Down
10 changes: 5 additions & 5 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,15 +459,15 @@ internals.Request.prototype._setState = function (name, value, options) {
};


internals.Request.prototype._clearState = function (name) {
internals.Request.prototype._clearState = function (name, options) {

var state = {
name: name,
options: {
ttl: 0
}
name: name
};

state.options = Hoek.clone(options || {});
state.options.ttl = 0;

this._states[name] = state;
};

Expand Down
4 changes: 2 additions & 2 deletions lib/response/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ internals.Message.prototype.state = function (name, value, options) { /
};


internals.Message.prototype.unstate = function (name) {
internals.Message.prototype.unstate = function (name, options) {

this.request._clearState(name);
this.request._clearState(name, options);
return this;
};

Expand Down
18 changes: 18 additions & 0 deletions test/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -3306,6 +3306,24 @@ describe('Response', function () {
});
});

it('allows options into unstage()', function (done) {

var handler = function (request, reply) {

reply().unstate('session', { path: '/unset', isSecure: true });
};

var server = new Hapi.Server();
server.route({ method: 'GET', path: '/', handler: handler });

server.inject('/', function (unset) {

expect(unset.statusCode).to.equal(200);
expect(unset.headers['set-cookie']).to.deep.equal(['session=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Secure; Path=/unset']);
done();
});
});

describe('Payload', function () {

it('handles undefined data', function (done) {
Expand Down