rhebok 0.8.5 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changes +4 -0
- data/ext/rhebok/rhebok.c +58 -1
- data/lib/rack/handler/rhebok.rb +1 -1
- data/lib/rhebok/version.rb +1 -1
- data/test/spec_06_curl.rb +93 -23
- data/test/testrequest.rb +27 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dbfe9f10796f8d8851faa4f2a642d8e462fed15
|
4
|
+
data.tar.gz: 865e2b6464856104ad2cba761e2a82c1967a30f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bdea8576b3aff0eaec288a7e8613e47d8e7efa7a1b54a55f5e84eb5148e9781896b90b559c4e117104d4ea795a36e80a09e7f23c315ff0188fa845f43717216
|
7
|
+
data.tar.gz: a7973f26793013d7c208b6578076738102df80e42e8eaf5c8b6a379416fbb10247564de242f6986de9d749e50332df615d46fb8818b78aaf437dbf62065d9a20
|
data/Changes
CHANGED
data/ext/rhebok/rhebok.c
CHANGED
@@ -637,7 +637,7 @@ static
|
|
637
637
|
VALUE rhe_write_timeout(VALUE self, VALUE fileno, VALUE buf, VALUE len, VALUE offset, VALUE timeout) {
|
638
638
|
char* d;
|
639
639
|
ssize_t rv;
|
640
|
-
|
640
|
+
buf = rb_String(buf);
|
641
641
|
d = RSTRING_PTR(buf);
|
642
642
|
rv = _write_timeout(NUM2INT(fileno), NUM2DBL(timeout), &d[NUM2LONG(offset)], NUM2LONG(len));
|
643
643
|
if ( rv < 0 ) {
|
@@ -654,6 +654,7 @@ VALUE rhe_write_all(VALUE self, VALUE fileno, VALUE buf, VALUE offsetv, VALUE ti
|
|
654
654
|
ssize_t rv = 0;
|
655
655
|
ssize_t written = 0;
|
656
656
|
|
657
|
+
buf = rb_String(buf);
|
657
658
|
d = RSTRING_PTR(buf);
|
658
659
|
buf_len = RSTRING_LEN(buf);
|
659
660
|
|
@@ -671,6 +672,61 @@ VALUE rhe_write_all(VALUE self, VALUE fileno, VALUE buf, VALUE offsetv, VALUE ti
|
|
671
672
|
return rb_int_new(written);
|
672
673
|
}
|
673
674
|
|
675
|
+
static
|
676
|
+
VALUE rhe_write_chunk(VALUE self, VALUE fileno, VALUE buf, VALUE offsetv, VALUE timeout) {
|
677
|
+
ssize_t buf_len;
|
678
|
+
ssize_t rv = 0;
|
679
|
+
ssize_t written = 0;
|
680
|
+
ssize_t vec_offset = 0;
|
681
|
+
int count =0;
|
682
|
+
ssize_t iovcnt = 3;
|
683
|
+
char chunked_header_buf[18];
|
684
|
+
|
685
|
+
buf = rb_String(buf);
|
686
|
+
buf_len = RSTRING_LEN(buf);
|
687
|
+
|
688
|
+
if ( buf_len == 0 ){
|
689
|
+
return rb_int_new(0);
|
690
|
+
}
|
691
|
+
|
692
|
+
{
|
693
|
+
struct iovec v[iovcnt]; // Needs C99 compiler
|
694
|
+
v[0].iov_len = _chunked_header(chunked_header_buf,buf_len);
|
695
|
+
v[0].iov_base = chunked_header_buf;
|
696
|
+
v[1].iov_len = buf_len;
|
697
|
+
v[1].iov_base = RSTRING_PTR(buf);
|
698
|
+
v[2].iov_base = "\r\n";
|
699
|
+
v[2].iov_len = sizeof("\r\n") -1;
|
700
|
+
|
701
|
+
vec_offset = 0;
|
702
|
+
written = 0;
|
703
|
+
while ( iovcnt - vec_offset > 0 ) {
|
704
|
+
count = (iovcnt > IOV_MAX) ? IOV_MAX : iovcnt;
|
705
|
+
rv = _writev_timeout(NUM2INT(fileno), NUM2DBL(timeout), &v[vec_offset], count - vec_offset, (vec_offset == 0) ? 0 : 1);
|
706
|
+
if ( rv <= 0 ) {
|
707
|
+
// error or disconnected
|
708
|
+
break;
|
709
|
+
}
|
710
|
+
written += rv;
|
711
|
+
while ( rv > 0 ) {
|
712
|
+
if ( (unsigned int)rv >= v[vec_offset].iov_len ) {
|
713
|
+
rv -= v[vec_offset].iov_len;
|
714
|
+
vec_offset++;
|
715
|
+
}
|
716
|
+
else {
|
717
|
+
v[vec_offset].iov_base = (char*)v[vec_offset].iov_base + rv;
|
718
|
+
v[vec_offset].iov_len -= rv;
|
719
|
+
rv = 0;
|
720
|
+
}
|
721
|
+
}
|
722
|
+
}
|
723
|
+
}
|
724
|
+
if ( rv < 0 ) {
|
725
|
+
return Qnil;
|
726
|
+
}
|
727
|
+
return rb_int_new(written);
|
728
|
+
}
|
729
|
+
|
674
730
|
static
|
675
731
|
int header_to_array(VALUE key_obj, VALUE val_obj, VALUE ary) {
|
676
732
|
ssize_t val_len;
|
@@ -963,6 +1019,7 @@ void Init_rhebok()
|
|
963
1019
|
rb_define_module_function(cRhebok, "read_timeout", rhe_read_timeout, 5);
|
964
1020
|
rb_define_module_function(cRhebok, "write_timeout", rhe_write_timeout, 5);
|
965
1021
|
rb_define_module_function(cRhebok, "write_all", rhe_write_all, 4);
|
1022
|
+
rb_define_module_function(cRhebok, "write_chunk", rhe_write_chunk, 4);
|
966
1023
|
rb_define_module_function(cRhebok, "close_rack", rhe_close, 1);
|
967
1024
|
rb_define_module_function(cRhebok, "write_response", rhe_write_response, 7);
|
968
1025
|
}
|
data/lib/rack/handler/rhebok.rb
CHANGED
@@ -307,7 +307,7 @@ module Rack
|
|
307
307
|
body.each do |part|
|
308
308
|
ret = nil
|
309
309
|
if use_chunked == 1
|
310
|
-
ret = ::Rhebok.
|
310
|
+
ret = ::Rhebok.write_chunk(connection, part, 0, @options[:Timeout])
|
311
311
|
else
|
312
312
|
ret = ::Rhebok.write_all(connection, part, 0, @options[:Timeout])
|
313
313
|
end
|
data/lib/rhebok/version.rb
CHANGED
data/test/spec_06_curl.rb
CHANGED
@@ -4,27 +4,32 @@ require 'timeout'
|
|
4
4
|
require 'socket'
|
5
5
|
require 'rack/handler/rhebok'
|
6
6
|
|
7
|
+
class ZeroStreamBody
|
8
|
+
def self.each
|
9
|
+
yield "Content"
|
10
|
+
yield ""
|
11
|
+
yield "Again"
|
12
|
+
yield nil
|
13
|
+
yield 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class VacantStreamBody
|
18
|
+
def self.each
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
7
23
|
describe Rhebok do
|
8
24
|
extend TestRequest::Helpers
|
9
|
-
begin
|
10
|
-
|
11
|
-
@host = '127.0.0.1'
|
12
|
-
@port = 9202
|
13
|
-
#@app = Rack::Lint.new(TestRequest.new) Lint requires Content-Length or Transfer-Eoncoding
|
14
|
-
@app = TestRequest.new
|
15
|
-
@pid = fork
|
16
|
-
if @pid == nil
|
17
|
-
#child
|
18
|
-
Rack::Handler::Rhebok.run(@app, :Host=>'127.0.0.1', :Port=>9202, :MaxWorkers=>1,
|
19
|
-
:BeforeFork => proc { ENV["TEST_FOO"] = "FOO" },
|
20
|
-
:AfterFork => proc { ENV["TEST_BAR"] = "BAR" },
|
21
|
-
)
|
22
|
-
exit!(true)
|
23
|
-
end
|
24
25
|
|
26
|
+
@host = '127.0.0.1'
|
27
|
+
@port = 9202
|
28
|
+
|
29
|
+
test_rhebok(TestRequest.new, proc {
|
25
30
|
command = 'curl --stderr - -sv -X POST -T "'+File.expand_path('../testrequest.rb', __FILE__)+'" -H "Content-type: text/plain" --header "Transfer-Encoding: chunked" http://127.0.0.1:9202/remove_length'
|
26
|
-
|
27
|
-
should "with curl" do
|
31
|
+
curl_yaml(command)
|
32
|
+
should "chunked with curl" do
|
28
33
|
@request["Transfer-Encoding"].should.equal "chunked"
|
29
34
|
@request["Expect"].should.equal "100-continue"
|
30
35
|
@response.key?("Transfer-Encoding").should.equal false
|
@@ -35,12 +40,77 @@ describe Rhebok do
|
|
35
40
|
@header.key?("HTTP/1.1 100 Continue").should.equal true
|
36
41
|
end
|
37
42
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
command = 'curl --stderr - --http1.0 -sv -X POST -T "'+File.expand_path('../testrequest.rb', __FILE__)+'" -H "Content-type: text/plain" --header "Transfer-Encoding: chunked" http://127.0.0.1:9202/remove_length'
|
44
|
+
curl_yaml(command)
|
45
|
+
should "chunked with curl http1.0" do
|
46
|
+
@response.key?("Transfer-Encoding").should.equal false
|
47
|
+
@request.key?("Expect").should.equal false
|
48
|
+
@response["CONTENT_LENGTH"].should.equal File.stat(File.expand_path('../testrequest.rb', __FILE__)).size.to_s
|
49
|
+
@response["test.postdata"].bytesize.should.equal File.stat(File.expand_path('../testrequest.rb', __FILE__)).size
|
50
|
+
@header.key?("Transfer-Encoding").should.equal false
|
51
|
+
@header["Connection"].should.equal "close"
|
52
|
+
@header.key?("HTTP/1.1 100 Continue").should.equal false
|
53
|
+
end
|
54
|
+
})
|
55
|
+
|
56
|
+
test_rhebok( proc {
|
57
|
+
[200,{"Content-Type"=>"text/plain"},["Content","","Again",nil,0]]
|
58
|
+
}, proc {
|
59
|
+
command = 'curl --stderr - -sv http://127.0.0.1:9202/'
|
60
|
+
curl_request(command)
|
61
|
+
should "zero length with curl" do
|
62
|
+
@body.should.equal "ContentAgain0"
|
43
63
|
end
|
44
|
-
|
64
|
+
command = 'curl --stderr - -sv --http1.0 http://127.0.0.1:9202/'
|
65
|
+
curl_request(command)
|
66
|
+
should "zero length with curl http/1.0" do
|
67
|
+
@body.should.equal "ContentAgain0"
|
68
|
+
end
|
69
|
+
})
|
70
|
+
|
71
|
+
test_rhebok( proc {
|
72
|
+
[200,{"Content-Type"=>"text/plain"},[]]
|
73
|
+
}, proc {
|
74
|
+
command = 'curl --stderr - -sv http://127.0.0.1:9202/'
|
75
|
+
curl_request(command)
|
76
|
+
should "vacant res with curl" do
|
77
|
+
@body.should.equal ""
|
78
|
+
end
|
79
|
+
command = 'curl --stderr - -sv --http1.0 http://127.0.0.1:9202/'
|
80
|
+
curl_request(command)
|
81
|
+
should "vacant rew with curl http/1.0" do
|
82
|
+
@body.should.equal ""
|
83
|
+
end
|
84
|
+
})
|
85
|
+
|
86
|
+
test_rhebok( proc {
|
87
|
+
[200,{"Content-Type"=>"text/plain"},ZeroStreamBody]
|
88
|
+
}, proc {
|
89
|
+
command = 'curl --stderr - -sv http://127.0.0.1:9202/'
|
90
|
+
curl_request(command)
|
91
|
+
should "zerostream length with curl" do
|
92
|
+
@body.should.equal "ContentAgain0"
|
93
|
+
end
|
94
|
+
command = 'curl --stderr - -sv --http1.0 http://127.0.0.1:9202/'
|
95
|
+
curl_request(command)
|
96
|
+
should "zerostream length with curl http/1.0" do
|
97
|
+
@body.should.equal "ContentAgain0"
|
98
|
+
end
|
99
|
+
})
|
100
|
+
|
101
|
+
test_rhebok( proc {
|
102
|
+
[200,{"Content-Type"=>"text/plain"},VacantStreamBody]
|
103
|
+
}, proc {
|
104
|
+
command = 'curl --stderr - -sv http://127.0.0.1:9202/'
|
105
|
+
curl_request(command)
|
106
|
+
should "vacantstream length with curl" do
|
107
|
+
@body.should.equal ""
|
108
|
+
end
|
109
|
+
command = 'curl --stderr - -sv --http1.0 http://127.0.0.1:9202/'
|
110
|
+
curl_request(command)
|
111
|
+
should "vacantstream length with curl http/1.0" do
|
112
|
+
@body.should.equal ""
|
113
|
+
end
|
114
|
+
})
|
45
115
|
|
46
116
|
end
|
data/test/testrequest.rb
CHANGED
@@ -78,7 +78,26 @@ class TestRequest
|
|
78
78
|
}
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
81
|
+
def test_rhebok(app,cb)
|
82
|
+
begin
|
83
|
+
@pid = fork
|
84
|
+
if @pid == nil
|
85
|
+
# child
|
86
|
+
Rack::Handler::Rhebok.run(app, :Host=>@host, :Port=>@port, :MaxWorkers=>1)
|
87
|
+
exit!(true)
|
88
|
+
end
|
89
|
+
cb.call
|
90
|
+
ensure
|
91
|
+
sleep 1
|
92
|
+
if @pid != nil
|
93
|
+
Process.kill(:TERM, @pid)
|
94
|
+
Process.wait()
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def curl_request(command)
|
82
101
|
body = ""
|
83
102
|
header = {}
|
84
103
|
request = {}
|
@@ -104,9 +123,15 @@ class TestRequest
|
|
104
123
|
end
|
105
124
|
}
|
106
125
|
@request = request
|
107
|
-
@
|
126
|
+
@body = body
|
108
127
|
@header = header
|
109
128
|
end
|
129
|
+
|
130
|
+
def curl_yaml(command)
|
131
|
+
curl_request(command)
|
132
|
+
@response = YAML.load(@body)
|
133
|
+
end
|
134
|
+
|
110
135
|
end
|
111
136
|
end
|
112
137
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhebok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro Nagano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|