Skip to content

Commit

Permalink
Add parameter documentation for HTTPServerResponse.setCookie and use …
Browse files Browse the repository at this point in the history
…"maxAge" instead of "expires" for clearing a cookie.

"expires" is not a standard field and the date/time format used was not matching the one commonly used for that field. "MaxAge=0" is the standard way to clear a cookie, so this is used here. See also #293.
  • Loading branch information
s-ludwig committed Aug 21, 2013
1 parent 7cdd77d commit 6e072e1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions source/vibe/http/server.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
A HTTP 1.1/1.0 server implementation.
Copyright: © 2012 RejectedSoftware e.K.
Copyright: © 2012-2013 RejectedSoftware e.K.
License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
Authors: Sönke Ludwig, Jan Krüger
*/
Expand Down Expand Up @@ -790,14 +790,19 @@ final class HTTPServerResponse : HTTPResponse {
return m_conn;
}

/// Sets the specified cookie value.
/** Sets the specified cookie value.
Params:
name = Name of the cookie
value = New cookie value - pass null to clear the cookie
path = Path (as seen by the client) of the directory tree in which the cookie is visible
*/
Cookie setCookie(string name, string value, string path = "/")
{
auto cookie = new Cookie();
cookie.path = path;
cookie.value = value;
if( value is null )
cookie.expires = Clock.currTime().add!("months")(-1).toSimpleString();
if (value is null) cookie.maxAge = 0;
cookies[name] = cookie;
return cookie;
}
Expand Down

0 comments on commit 6e072e1

Please sign in to comment.