rhebok 0.8.1 → 0.8.2

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
  SHA1:
3
- metadata.gz: d61548093f8e744650e5731c7ab82f72ffa9fcf1
4
- data.tar.gz: 10f9816609bd7c2d2ea3d20c58c8d370322cd51d
3
+ metadata.gz: af0b8d340f3ed54ca6fe772d4898501e3a537065
4
+ data.tar.gz: e3ef8c73675ceee002c70b99f4cee0f8cda5f4d0
5
5
  SHA512:
6
- metadata.gz: da3c44e43ded8df6eb0cd94bc1b63bb5fa98517ebd44dc02102414b396f697d5c669cb716a80a4fec8403d59fab04d63f2d20adac8cdfc643da2a77d691232fa
7
- data.tar.gz: 1dd31b4b30c09ce383143a3c6a32c2d72f83b548f6b1120ee4994eb538ab3704f730754a559e43fc67dc308583fb8b599c5b919fb1a51e88dbc72adb3933d198
6
+ metadata.gz: 017f19ab1116a7066e0ce5d06ff4fea104e7fc6a040c2271caaf57a7a4560062347a46031c3614f0c0c3ca2dd3811b5a190789aeb4e4b662e1eece7c23114c92
7
+ data.tar.gz: 6d153fa1eea81ace6e63e2cc50e668d813c5a6ef3be20ca78ace54c5c4edf59784b437c8d78c2953c0614ff09a0ad46369b9a36df57ef696b470c7fc14739a9f
data/Changes CHANGED
@@ -1,3 +1,7 @@
1
+ 0.8.2 2015-01-22T19:42:49Z
2
+
3
+ - tune around Expect
4
+
1
5
  0.8.1 2015-01-22T16:42:28Z
2
6
 
3
7
  - stringfy body and header values
@@ -18,6 +18,8 @@
18
18
  #define MAX_HEADER_NAME_LEN 1024
19
19
  #define MAX_HEADERS 128
20
20
  #define BAD_REQUEST "HTTP/1.0 400 Bad Request\r\nConnection: close\r\n\r\n400 Bad Request\r\n"
21
+ #define EXPECT_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n"
22
+ #define EXPECT_FAILED "HTTP/1.1 417 Expectation Failed\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\nExpectation Failed\r\n"
21
23
  #define READ_BUF 16384
22
24
  #define TOU(ch) (('a' <= ch && ch <= 'z') ? ch - ('a' - 'A') : ch)
23
25
 
@@ -131,6 +133,8 @@ static VALUE zero_string_val;
131
133
  static VALUE http10_val;
132
134
  static VALUE http11_val;
133
135
 
136
+ static VALUE expect_key;
137
+
134
138
  struct common_header {
135
139
  const char * name;
136
140
  size_t name_len;
@@ -583,6 +587,21 @@ VALUE rhe_accept(VALUE self, VALUE fileno, VALUE timeoutv, VALUE tcp, VALUE env)
583
587
  buf_len += rv;
584
588
  }
585
589
 
590
+ VALUE expect_val = rb_hash_aref(env, expect_key);
591
+ if ( expect_val != Qnil ) {
592
+ if ( strncmp(RSTRING_PTR(expect_val), "100-continue", RSTRING_LEN(expect_val)) == 0 ) {
593
+ rv = _write_timeout(fd, timeout, EXPECT_CONTINUE, sizeof(EXPECT_CONTINUE) - 1);
594
+ if ( rv <= 0 ) {
595
+ close(fd);
596
+ goto badexit;
597
+ }
598
+ } else {
599
+ rv = _write_timeout(fd, timeout, EXPECT_FAILED, sizeof(EXPECT_FAILED) - 1);
600
+ close(fd);
601
+ goto badexit;
602
+ }
603
+ }
604
+
586
605
  req = rb_ary_new2(2);
587
606
  rb_ary_push(req, rb_int_new(fd));
588
607
  rb_ary_push(req, rb_str_new(&read_buf[reqlen],buf_len - reqlen));
@@ -916,6 +935,9 @@ void Init_rhebok()
916
935
  http11_val = rb_obj_freeze(rb_str_new2("HTTP/1.1"));
917
936
  rb_gc_register_address(&http11_val);
918
937
 
938
+ expect_key = rb_obj_freeze(rb_str_new2("HTTP_EXPECT"));
939
+ rb_gc_register_address(&expect_key);
940
+
919
941
  set_common_header("ACCEPT",sizeof("ACCEPT") - 1, 0);
920
942
  set_common_header("ACCEPT-ENCODING",sizeof("ACCEPT-ENCODING") - 1, 0);
921
943
  set_common_header("ACCEPT-LANGUAGE",sizeof("ACCEPT-LANGUAGE") - 1, 0);
@@ -239,12 +239,7 @@ module Rack
239
239
  begin
240
240
  proc_req_count += 1
241
241
  @can_exit = false
242
- # expect
243
- if env.key?("HTTP_EXPECT") && env.delete("HTTP_EXPECT") == "100-continue"
244
- ::Rhebok.write_all(connection, "HTTP/1.1 100 Continue\015\012\015\012", 0, @options[:Timeout])
245
- end
246
242
  # handle request
247
- is_chunked = env.key?("HTTP_TRANSFER_ENCODING") && env.delete("HTTP_TRANSFER_ENCODING") == 'chunked'
248
243
  if env.key?("CONTENT_LENGTH") && env["CONTENT_LENGTH"].to_i > 0
249
244
  cl = env["CONTENT_LENGTH"].to_i
250
245
  buffer = ::Rhebok::Buffered.new(cl,MAX_MEMORY_BUFFER_SIZE)
@@ -263,7 +258,7 @@ module Rack
263
258
  cl -= chunk.bytesize
264
259
  end
265
260
  env["rack.input"] = buffer.rewind
266
- elsif is_chunked
261
+ elsif env.key?("HTTP_TRANSFER_ENCODING") && env.delete("HTTP_TRANSFER_ENCODING") == 'chunked'
267
262
  buffer = ::Rhebok::Buffered.new(0,MAX_MEMORY_BUFFER_SIZE)
268
263
  chunked_buffer = '';
269
264
  complete = false
@@ -303,15 +298,15 @@ module Rack
303
298
 
304
299
  use_chunked = env["SERVER_PROTOCOL"] != "HTTP/1.1" ||
305
300
  headers.key?("Transfer-Encoding") ||
306
- headers.key?("Content-Length") ? false : true
307
-
301
+ headers.key?("Content-Length") ? 0 : 1
302
+
308
303
  if body.instance_of?(Array)
309
- ::Rhebok.write_response(connection, @options[:Timeout], status_code.to_i, headers, body, use_chunked ? 1 : 0)
304
+ ::Rhebok.write_response(connection, @options[:Timeout], status_code.to_i, headers, body, use_chunked)
310
305
  else
311
- ::Rhebok.write_response(connection, @options[:Timeout], status_code.to_i, headers, [], use_chunked ? 1 : 0)
306
+ ::Rhebok.write_response(connection, @options[:Timeout], status_code.to_i, headers, [], use_chunked)
312
307
  body.each do |part|
313
308
  ret = nil
314
- if use_chunked
309
+ if use_chunked == 1
315
310
  ret = ::Rhebok.write_all(connection, part.bytesize.to_s(16) + "\015\012" + part + "\015\012", 0, @options[:Timeout])
316
311
  else
317
312
  ret = ::Rhebok.write_all(connection, part, 0, @options[:Timeout])
@@ -320,7 +315,7 @@ module Rack
320
315
  break
321
316
  end
322
317
  end #body.each
323
- ::Rhebok.write_all(connection, "0\015\012\015\012", 0, @options[:Timeout]) if use_chunked
318
+ ::Rhebok.write_all(connection, "0\015\012\015\012", 0, @options[:Timeout]) if use_chunked == 1
324
319
  body.respond_to?(:close) and body.close
325
320
  end
326
321
  #p [env,status_code,headers,body]
@@ -1,3 +1,3 @@
1
1
  class Rhebok
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhebok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro Nagano