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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bba60b163b964308fafcdb14504076d28df6831bb2ebf80c9c3b8676f29f4734
4
- data.tar.gz: 43ac8f3c3273fb49360d55d765c5c3ade646b3c503bb18eb23c211f7e4c4109a
3
+ metadata.gz: 8a11d937822d71f87cd78734c038f1a73a25af902b142958208af81b3397f3be
4
+ data.tar.gz: 21d3337883257c321b37c602d52c7ab68896343d856bfafaec329476b43c35fe
5
5
  SHA512:
6
- metadata.gz: 65d914a80ec411ddc53b7e0982f6896f8f1315cd07a8daa01a50cc8d8183fefed315ee51525cef2131a28de00809ed5a1d719cebb5df0785bf03bc218bdc945d
7
- data.tar.gz: 9229f345ba7d0945066dd60b81b3fbfbeb3c04e8e4ab1f7b7edc13636654d9f6be562ead8e1a5b3ac479f744342395e6d65f3e5a833522f7787e8fc161318df4
6
+ metadata.gz: 5e73eead0ddf6378830a445562e827a77f235e1f26d37d18c7956ec790652c9f8efb23b82385d90c512dc47a864b796b8f9f7c2826e5f724dcaae63d45c39d43
7
+ data.tar.gz: 92893c74ac27005fc38891c49ce4c2a5c72e0f7fd453fce38871ab5b626db8cc10f000263c01573b7cceac331dbf4f5089ee413ec71f3839cede7fa0bc29693e
@@ -10,4 +10,7 @@ append_cflags("-fvisibility=hidden")
10
10
  # Check for Ractor support
11
11
  have_func("rb_ext_ractor_safe", "ruby.h")
12
12
 
13
+ # Check for rb_hash_new_capa (Ruby 3.2+)
14
+ have_func("rb_hash_new_capa", "ruby.h")
15
+
13
16
  create_makefile("picohttp/picohttp")
@@ -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, rb_sprintf("HTTP/1.%d", minor_version));
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
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Picohttp
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picohttp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn