picohttp 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/picohttp/extconf.rb +3 -0
- data/ext/picohttp/picohttp.c +32 -1
- data/lib/picohttp/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8a11d937822d71f87cd78734c038f1a73a25af902b142958208af81b3397f3be
|
|
4
|
+
data.tar.gz: 21d3337883257c321b37c602d52c7ab68896343d856bfafaec329476b43c35fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5e73eead0ddf6378830a445562e827a77f235e1f26d37d18c7956ec790652c9f8efb23b82385d90c512dc47a864b796b8f9f7c2826e5f724dcaae63d45c39d43
|
|
7
|
+
data.tar.gz: 92893c74ac27005fc38891c49ce4c2a5c72e0f7fd453fce38871ab5b626db8cc10f000263c01573b7cceac331dbf4f5089ee413ec71f3839cede7fa0bc29693e
|
data/ext/picohttp/extconf.rb
CHANGED
data/ext/picohttp/picohttp.c
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#include "picohttpparser.h"
|
|
3
3
|
|
|
4
4
|
#define MAX_HEADER_NAME_LEN 256
|
|
5
|
+
#define ENV_HASH_INITIAL_CAPACITY 64
|
|
5
6
|
|
|
6
7
|
VALUE rb_mPicohttp;
|
|
7
8
|
VALUE rb_ePicohttpParseError;
|
|
@@ -12,6 +13,20 @@ static VALUE rb_str_server_protocol;
|
|
|
12
13
|
static VALUE rb_str_path_info;
|
|
13
14
|
static VALUE rb_str_query_string;
|
|
14
15
|
static VALUE rb_str_empty;
|
|
16
|
+
static VALUE rb_str_http_1_0;
|
|
17
|
+
static VALUE rb_str_http_1_1;
|
|
18
|
+
|
|
19
|
+
static VALUE
|
|
20
|
+
http_version_string(int minor_version)
|
|
21
|
+
{
|
|
22
|
+
if (minor_version == 0) {
|
|
23
|
+
return rb_str_http_1_0;
|
|
24
|
+
} else if (minor_version == 1) {
|
|
25
|
+
return rb_str_http_1_1;
|
|
26
|
+
} else {
|
|
27
|
+
return rb_sprintf("HTTP/1.%d", minor_version);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
15
30
|
|
|
16
31
|
static VALUE
|
|
17
32
|
header_name_to_env_key(const char *name, size_t name_len)
|
|
@@ -20,6 +35,14 @@ header_name_to_env_key(const char *name, size_t name_len)
|
|
|
20
35
|
rb_raise(rb_ePicohttpParseError, "Header name too long");
|
|
21
36
|
}
|
|
22
37
|
|
|
38
|
+
// Special cases for Content-Type and Content-Length (no HTTP_ prefix)
|
|
39
|
+
if (name_len == 12 && strncasecmp(name, "content-type", 12) == 0) {
|
|
40
|
+
return rb_interned_str_cstr("CONTENT_TYPE");
|
|
41
|
+
}
|
|
42
|
+
if (name_len == 14 && strncasecmp(name, "content-length", 14) == 0) {
|
|
43
|
+
return rb_interned_str_cstr("CONTENT_LENGTH");
|
|
44
|
+
}
|
|
45
|
+
|
|
23
46
|
char env_name[MAX_HEADER_NAME_LEN + 6]; // "HTTP_" + name + null terminator
|
|
24
47
|
strcpy(env_name, "HTTP_");
|
|
25
48
|
|
|
@@ -102,11 +125,15 @@ picohttp_parse_request_env(VALUE self, VALUE str)
|
|
|
102
125
|
rb_raise(rb_ePicohttpParseError, "Invalid HTTP request");
|
|
103
126
|
}
|
|
104
127
|
|
|
128
|
+
#ifdef HAVE_RB_HASH_NEW_CAPA
|
|
129
|
+
VALUE env = rb_hash_new_capa(ENV_HASH_INITIAL_CAPACITY);
|
|
130
|
+
#else
|
|
105
131
|
VALUE env = rb_hash_new();
|
|
132
|
+
#endif
|
|
106
133
|
|
|
107
134
|
// Standard CGI/Rack environment variables
|
|
108
135
|
rb_hash_aset(env, rb_str_request_method, rb_str_new(method, method_len));
|
|
109
|
-
rb_hash_aset(env, rb_str_server_protocol,
|
|
136
|
+
rb_hash_aset(env, rb_str_server_protocol, http_version_string(minor_version));
|
|
110
137
|
|
|
111
138
|
// Parse path and query string in C
|
|
112
139
|
const char *query_start = memchr(path, '?', path_len);
|
|
@@ -152,6 +179,8 @@ Init_picohttp(void)
|
|
|
152
179
|
rb_str_path_info = rb_interned_str_cstr("PATH_INFO");
|
|
153
180
|
rb_str_query_string = rb_interned_str_cstr("QUERY_STRING");
|
|
154
181
|
rb_str_empty = rb_interned_str_cstr("");
|
|
182
|
+
rb_str_http_1_0 = rb_interned_str_cstr("HTTP/1.0");
|
|
183
|
+
rb_str_http_1_1 = rb_interned_str_cstr("HTTP/1.1");
|
|
155
184
|
|
|
156
185
|
// Prevent garbage collection of constants
|
|
157
186
|
rb_gc_register_address(&rb_str_request_method);
|
|
@@ -159,4 +188,6 @@ Init_picohttp(void)
|
|
|
159
188
|
rb_gc_register_address(&rb_str_path_info);
|
|
160
189
|
rb_gc_register_address(&rb_str_query_string);
|
|
161
190
|
rb_gc_register_address(&rb_str_empty);
|
|
191
|
+
rb_gc_register_address(&rb_str_http_1_0);
|
|
192
|
+
rb_gc_register_address(&rb_str_http_1_1);
|
|
162
193
|
}
|
data/lib/picohttp/version.rb
CHANGED