1 #include <ngx_http.h>
2 #include "nchan_defs.h"
3 
4 //string constants
5 //headers
6 const  ngx_str_t NCHAN_HEADER_ETAG = ngx_string("Etag");
7 const  ngx_str_t NCHAN_HEADER_IF_NONE_MATCH = ngx_string("If-None-Match");
8 const  ngx_str_t NCHAN_HEADER_VARY = ngx_string("Vary");
9 const  ngx_str_t NCHAN_HEADER_ALLOW = ngx_string("Allow");
10 const  ngx_str_t NCHAN_HEADER_CACHE_CONTROL = ngx_string("Cache-Control");
11 const  ngx_str_t NCHAN_HEADER_PRAGMA = ngx_string("Pragma");
12 const  ngx_str_t NCHAN_HEADER_ORIGIN = ngx_string("Origin");
13 
14 const  ngx_str_t NCHAN_HEADER_ACCESS_CONTROL_ALLOW_HEADERS = ngx_string("Access-Control-Allow-Headers");
15 const  ngx_str_t NCHAN_HEADER_ACCESS_CONTROL_ALLOW_METHODS = ngx_string("Access-Control-Allow-Methods");
16 const  ngx_str_t NCHAN_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = ngx_string("Access-Control-Allow-Origin");
17 const  ngx_str_t NCHAN_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS = ngx_string("Access-Control-Expose-Headers");
18 const  ngx_str_t NCHAN_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS = ngx_string("Access-Control-Allow-Credentials");
19 
20 const  ngx_str_t NCHAN_HEADER_EVENTSOURCE_EVENT = ngx_string("X-EventSource-Event");
21 
22 //websocket headers
23 
24 const ngx_str_t NCHAN_HEADER_CONNECTION = ngx_string("Connection");
25 const ngx_str_t NCHAN_HEADER_UPGRADE = ngx_string("Upgrade");
26 const ngx_str_t NCHAN_HEADER_SEC_WEBSOCKET_KEY = ngx_string("Sec-WebSocket-Key");
27 const ngx_str_t NCHAN_HEADER_SEC_WEBSOCKET_ACCEPT = ngx_string("Sec-WebSocket-Accept");
28 const ngx_str_t NCHAN_HEADER_SEC_WEBSOCKET_VERSION = ngx_string("Sec-WebSocket-Version");
29 const ngx_str_t NCHAN_HEADERS_SEC_WEBSOCKET_PROTOCOL = ngx_string("Sec-WebSocket-Protocol");
30 const ngx_str_t NCHAN_HEADER_SEC_WEBSOCKET_EXTENSIONS = ngx_string("Sec-WebSocket-Extensions");
31 
32 //and some wobsockety values
33 const ngx_str_t NCHAN_UPGRADE = ngx_string("Upgrade");
34 const ngx_str_t NCHAN_WEBSOCKET = ngx_string("websocket");
35 
36 
37 //header values
38 const  ngx_str_t NCHAN_CACHE_CONTROL_VALUE = ngx_string("no-cache");
39 
40 //status strings
41 const  ngx_str_t NCHAN_HTTP_STATUS_101 = ngx_string("101 Switching Protocols");
42 const  ngx_str_t NCHAN_HTTP_STATUS_204 = ngx_string("204 No Content");
43 const  ngx_str_t NCHAN_HTTP_STATUS_304 = ngx_string("304 Not Modified");
44 const  ngx_str_t NCHAN_HTTP_STATUS_400 = ngx_string("400 Bad Request");
45 const  ngx_str_t NCHAN_HTTP_STATUS_408 = ngx_string("408 Request Timeout");
46 const  ngx_str_t NCHAN_HTTP_STATUS_409 = ngx_string("409 Conflict");
47 const  ngx_str_t NCHAN_HTTP_STATUS_410 = ngx_string("410 Gone");
48 
49 //other stuff
50 const  ngx_str_t NCHAN_SUBSCRIBER_TIMEOUT= ngx_string("Subscriber Timeout");
51 const  ngx_str_t NCHAN_ANYSTRING= ngx_string("*");
52 const  ngx_str_t NCHAN_ACCESS_CONTROL_ALLOWED_GROUP_HEADERS = ngx_string("Accept, Content-Type");
53 const  ngx_str_t NCHAN_ACCESS_CONTROL_ALLOWED_PUBLISHER_HEADERS = ngx_string("Content-Type");
54 const  ngx_str_t NCHAN_ACCESS_CONTROL_ALLOWED_SUBSCRIBER_HEADERS = ngx_string("If-None-Match, If-Modified-Since, Content-Type, Cache-Control, X-EventSource-Event");
55 const  ngx_str_t NCHAN_ACCESS_CONTROL_ALLOWED_PUBSUB_HEADERS = ngx_string("If-None-Match, If-Modified-Since, Content-Type, Cache-Control, X-EventSource-Event");
56 const  ngx_str_t NCHAN_ALLOW_GET_POST_PUT_DELETE= ngx_string("GET, POST, PUT, DELETE");
57 const  ngx_str_t NCHAN_ALLOW_GET= ngx_string("GET");
58 const  ngx_str_t NCHAN_ALLOW_GET_POST_DELETE= ngx_string("GET, POST, DELETE");
59 
60 
61 const  ngx_str_t NCHAN_VARY_HEADER_VALUE = ngx_string("If-None-Match, If-Modified-Since");
62 const  ngx_str_t NCHAN_MSG_RESPONSE_ALLOWED_HEADERS = ngx_string("Last-Modified, Etag, Content-Type");
63 const  char *NCHAN_MSG_RESPONSE_ALLOWED_CUSTOM_ETAG_HEADERS_STRF = "Last-Modified, %V, Content-Type";
64 
65 const ngx_str_t  NCHAN_CONTENT_TYPE_TEXT_PLAIN = ngx_string("text/plain");
66 
67 const ngx_str_t NCHAN_CHANNEL_INFO_PLAIN = ngx_string(
68   "queued messages: %ui" CRLF
69   "last requested: %d sec. ago" CRLF
70   "active subscribers: %ui" CRLF
71   "last message id: %V"
72   "\0");
73 
74 const ngx_str_t NCHAN_CHANNEL_INFO_JSON = ngx_string(
75   "{\"messages\": %ui, "
76   "\"requested\": %d, "
77   "\"subscribers\": %ui, "
78   "\"last_message_id\": \"%V\" }"
79   "\0");
80 
81 const ngx_str_t NCHAN_CHANNEL_INFO_XML = ngx_string(
82   "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" CRLF
83   "<channel>" CRLF
84   "  <messages>%ui</messages>" CRLF
85   "  <requested>%d</requested>" CRLF
86   "  <subscribers>%ui</subscribers>" CRLF
87   "  <last_message_id>%V</last_message_id>" CRLF
88   "</channel>"
89   "\0");
90 
91 const ngx_str_t NCHAN_CHANNEL_INFO_YAML = ngx_string(
92   "---" CRLF
93   "messages: %ui" CRLF
94   "requested: %d" CRLF
95   "subscribers: %ui" CRLF
96   "last_message_id: \"%V\"" CRLF
97   CRLF
98   "\0");
99