1 /******************************************************************************
2 
3     HTTP session "cookie" attribute name constants as defined in RFC 2109
4 
5     @see http://www.w3.org/Protocols/rfc2109/rfc2109.txt
6 
7     Note: CookieAttributeNames contains the "expires" instead of the "max-age"
8     cookie attribute name as defined in RFC 2109. The reason is that,
9     unfortunately, the cross-browser compatibility of "expires" is much better
10     than of "max-age".
11 
12     Copyright:
13         Copyright (c) 2009-2016 dunnhumby Germany GmbH.
14         All rights reserved.
15 
16     License:
17         Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
18         Alternatively, this file may be distributed under the terms of the Tango
19         3-Clause BSD License (see LICENSE_BSD.txt for details).
20 
21  ******************************************************************************/
22 
23 module ocean.net.http.consts.CookieAttributeNames;
24 
25 
26 
27 import ocean.meta.types.Qualifiers;
28 
29 version (unittest) import ocean.core.Test;
30 
31 /******************************************************************************/
32 
33 struct CookieAttributeNames
34 {
35     istring Comment, Domain,
36            Expires,
37            Path, Secure, Version;
38 
39     alias .CookieAttributeNameStrings   Names;
40     alias .CookieAttributeNameList      NameList;
41 }
42 
43 static immutable CookieAttributeNames CookieAttributeNameStrings =
44 {
45     Comment: "comment",
46     Domain:  "domain",
47     Expires: "expires",
48     Path:    "path",
49     Secure:  "secure",
50     Version: "version"
51 };
52 
53 istring[] CookieAttributeNameList ( )
54 {
55     return _CookieAttributeNameList;
56 }
57 
58 private istring[] _CookieAttributeNameList;
59 
60 private istring[CookieAttributeNames.tupleof.length] CookieAttributeNameList_;
61 
62 static this ( )
63 {
64     foreach (i, name; CookieAttributeNameStrings.tupleof)
65     {
66         CookieAttributeNameList_[i] = name;
67     }
68 
69     _CookieAttributeNameList = CookieAttributeNameList_;
70 }
71 
72 /******************************************************************************/
73 
74 unittest
75 {
76     static assert(CookieAttributeNames.Names.Comment == "comment");
77     static assert(CookieAttributeNames.Names.Domain  == "domain");
78     static assert(CookieAttributeNames.Names.Expires == "expires");
79     static assert(CookieAttributeNames.Names.Path    == "path");
80     static assert(CookieAttributeNames.Names.Secure  == "secure");
81     static assert(CookieAttributeNames.Names.Version == "version");
82 
83     foreach (i, attribute_name; CookieAttributeNames.Names.tupleof)
84     {
85         test(_CookieAttributeNameList[i] == attribute_name,
86                "mismatch of CookieAttributeNameList[" ~ i.stringof ~ ']');
87     }
88 }