ry / ebb fork watch download tarball
public this repo is viewable by everyone
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
Content-Type and Content-Length headers are special (so says rack)

"The environment must not contain the keys HTTP_CONTENT_TYPE or 
HTTP_CONTENT_LENGTH (use the versions without HTTP_). The CGI keys (named 
without a period) must have String values."
ryah (author)
about 1 month ago
commit  c124a82348ab9278d4e48408033fc88fcbe3209e
tree    6fc519534297485e636d25acee1ef3241a1b0859
parent  d5014ad2da264096a076bbe5f6898095eff38749
...
19
20
21
22
 
 
23
24
25
...
132
133
134
135
 
 
136
137
138
...
241
242
243
 
 
244
245
246
...
249
250
251
252
253
254
255
...
19
20
21
 
22
23
24
25
26
...
133
134
135
 
136
137
138
139
140
...
243
244
245
246
247
248
249
250
...
253
254
255
 
256
257
258
0
@@ -19,7 +19,8 @@ static VALUE global_request_method;
0
 static VALUE global_request_path;
0
 static VALUE global_request_uri;
0
 static VALUE global_server_port;
0
-static VALUE global_http_content_length;
0
+static VALUE global_content_length;
0
+static VALUE global_content_type;
0
 static VALUE global_http_prefix;
0
 static VALUE global_http_version;
0
 
0
@@ -132,7 +133,8 @@ VALUE env_field(struct ebb_env_item *item)
0
     return f;
0
   }
0
   switch(item->type) {
0
- case MONGREL_CONTENT_LENGTH: return global_http_content_length;
0
+ case MONGREL_CONTENT_LENGTH: return global_content_length;
0
+ case MONGREL_CONTENT_TYPE: return global_content_type;
0
     case MONGREL_FRAGMENT: return global_fragment;
0
     case MONGREL_HTTP_VERSION: return global_http_version;
0
     case MONGREL_QUERY_STRING: return global_query_string;
0
@@ -241,6 +243,8 @@ void Init_ebb_ext()
0
   
0
   /** Defines global strings in the init method. */
0
 #define DEF_GLOBAL(N, val) global_##N = rb_obj_freeze(rb_str_new2(val)); rb_global_variable(&global_##N)
0
+ DEF_GLOBAL(content_length, "CONTENT_LENGTH");
0
+ DEF_GLOBAL(content_type, "CONTENT_TYPE");
0
   DEF_GLOBAL(fragment, "FRAGMENT");
0
   DEF_GLOBAL(path_info, "PATH_INFO");
0
   DEF_GLOBAL(query_string, "QUERY_STRING");
0
@@ -249,7 +253,6 @@ void Init_ebb_ext()
0
   DEF_GLOBAL(request_path, "REQUEST_PATH");
0
   DEF_GLOBAL(request_uri, "REQUEST_URI");
0
   DEF_GLOBAL(server_port, "SERVER_PORT");
0
- DEF_GLOBAL(http_content_length, "HTTP_CONTENT_LENGTH");
0
   DEF_GLOBAL(http_prefix, "HTTP_");
0
   DEF_GLOBAL(http_version, "HTTP_VERSION");
0
   
...
13
14
15
 
16
17
18
...
13
14
15
16
17
18
19
0
@@ -13,6 +13,7 @@
0
 #endif
0
 
0
 enum { MONGREL_CONTENT_LENGTH
0
+ , MONGREL_CONTENT_TYPE
0
      , MONGREL_FRAGMENT
0
      , MONGREL_HTTP_VERSION
0
      , MONGREL_QUERY_STRING
...
37
38
39
40
 
41
42
43
44
45
 
 
 
 
 
46
47
48
...
122
123
124
125
126
 
 
 
 
127
128
 
129
130
131
...
37
38
39
 
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
127
128
129
 
 
130
131
132
133
134
 
135
136
137
138
0
@@ -37,12 +37,17 @@
0
     }
0
   }
0
   
0
- action http_content_length {
0
+ action content_length {
0
     if(!apply_element(parser, MONGREL_CONTENT_LENGTH, PTR_TO(mark), fpc, 20))
0
       fbreak;
0
     set_content_length(parser, PTR_TO(mark), LEN(mark, fpc));
0
   }
0
   
0
+ action content_type {
0
+ if(!apply_element(parser, MONGREL_CONTENT_TYPE, PTR_TO(mark), fpc, 10*1024))
0
+ fbreak;
0
+ }
0
+
0
   action fragment {
0
     if(!apply_element(parser, MONGREL_FRAGMENT, PTR_TO(mark), fpc, 10*1024))
0
       fbreak;
0
@@ -122,10 +127,12 @@
0
 
0
   field_value = any* >start_value %write_value;
0
   
0
- content_length = "Content-Length:"i " "* (digit+ >mark %http_content_length) :> CRLF;
0
- unknown_header = (field_name ":" " "* field_value :> CRLF) -- content_length;
0
+ known_headers = ( ("Content-Length:"i " "* (digit+ >mark %content_length))
0
+ | ("Content-Type:"i " "* (any* >mark %content_type))
0
+ ) :> CRLF;
0
+ unknown_header = (field_name ":" " "* field_value :> CRLF) -- known_headers;
0
   
0
- Request = Request_Line (content_length | unknown_header)* ( CRLF @done );
0
+ Request = Request_Line (known_headers | unknown_header)* ( CRLF @done );
0
 
0
 main := Request;
0
 
...
32
33
34
 
 
35
36
37
...
49
50
51
52
 
53
54
55
...
57
58
59
 
60
61
62
...
32
33
34
35
36
37
38
39
...
51
52
53
 
54
55
56
57
...
59
60
61
62
63
64
65
0
@@ -32,6 +32,8 @@ void init_test(void)
0
 void parse_simple_element_cb(void *_, int type, const char *at, size_t length)
0
 {
0
   switch(type) {
0
+ case MONGREL_CONTENT_LENGTH: assertStrEquals("12", at); break;
0
+ case MONGREL_CONTENT_TYPE: assertStrEquals("text/html", at); break;
0
   case MONGREL_HTTP_VERSION: assertStrEquals("HTTP/1.1", at); break;
0
   case MONGREL_REQUEST_PATH: assertStrEquals("/", at); break;
0
   case MONGREL_REQUEST_METHOD: assertStrEquals("GET", at); break;
0
@@ -49,7 +51,7 @@ void parse_simple_field_cb(void *_, const char *field, size_t flen, const char *
0
 
0
 void parse_simple_test(void)
0
 {
0
- const char *simple = "GET / HTTP/1.1\r\n\r\n";
0
+ const char *simple = "GET / HTTP/1.1\r\nconTENT-length: 12\r\ncontent-TYPE: text/html\r\n\r\n";
0
   int nread;
0
   http_parser_init(&parser);
0
   parser.on_element = parse_simple_element_cb;
0
@@ -57,6 +59,7 @@ void parse_simple_test(void)
0
   nread = http_parser_execute(&parser, simple, strlen(simple), 0);
0
   assertEquals(nread, strlen(simple));
0
   assertTrue(http_parser_is_finished(&parser));
0
+ assertEquals(parser.content_length, 12);
0
 }
0
 
0
 

Comments

    No one has commented yet.