net-http-server 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/ChangeLog.md +27 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +1 -1
- data/README.md +29 -17
- data/Rakefile +11 -28
- data/gemspec.yml +10 -4
- data/lib/net/http/server/chunked_stream.rb +4 -5
- data/lib/net/http/server/daemon.rb +17 -17
- data/lib/net/http/server/parser.rb +18 -18
- data/lib/net/http/server/requests.rb +5 -10
- data/lib/net/http/server/responses.rb +2 -2
- data/lib/net/http/server/server.rb +16 -13
- data/lib/net/http/server/version.rb +1 -1
- data/lib/rack/handler/http.rb +16 -17
- data/net-http-server.gemspec +40 -109
- data/spec/net/http/server/chunked_stream_spec.rb +10 -10
- data/spec/net/http/server/daemon_spec.rb +9 -11
- data/spec/net/http/server/parser_spec.rb +23 -23
- data/spec/net/http/server/requests_spec.rb +12 -26
- data/spec/net/http/server/responses_spec.rb +17 -17
- data/spec/net/http/server/stream_spec.rb +6 -6
- data/spec/rack/handler/helpers/test_request.rb +12 -3
- data/spec/rack/handler/http_spec.rb +27 -26
- data/spec/spec_helper.rb +0 -1
- metadata +49 -46
- data/.gemtest +0 -0
@@ -6,6 +6,15 @@ class TestRequest
|
|
6
6
|
def call(env)
|
7
7
|
status = env["QUERY_STRING"] =~ /secret/ ? 403 : 200
|
8
8
|
env["test.postdata"] = env["rack.input"].read
|
9
|
+
# clean out complex objects that won't translate over anyways.
|
10
|
+
env.keys.each do |key|
|
11
|
+
case env[key]
|
12
|
+
when String, Fixnum, Bignum
|
13
|
+
# leave it
|
14
|
+
else
|
15
|
+
env[key] = nil
|
16
|
+
end
|
17
|
+
end
|
9
18
|
body = env.to_yaml
|
10
19
|
size = body.respond_to?(:bytesize) ? body.bytesize : body.size
|
11
20
|
[status, {"Content-Type" => "text/yaml", "Content-Length" => size.to_s}, [body]]
|
@@ -31,7 +40,7 @@ class TestRequest
|
|
31
40
|
passwd = header.delete(:passwd)
|
32
41
|
|
33
42
|
get = Net::HTTP::Get.new(path, header)
|
34
|
-
get.basic_auth user, passwd
|
43
|
+
get.basic_auth user, passwd if user && passwd
|
35
44
|
http.request(get) { |response|
|
36
45
|
@status = response.code.to_i
|
37
46
|
if response.content_type == "text/yaml"
|
@@ -50,14 +59,14 @@ class TestRequest
|
|
50
59
|
|
51
60
|
post = Net::HTTP::Post.new(path, header)
|
52
61
|
post.form_data = formdata
|
53
|
-
post.basic_auth user, passwd
|
62
|
+
post.basic_auth user, passwd if user && passwd
|
54
63
|
http.request(post) { |response|
|
55
64
|
@status = response.code.to_i
|
56
65
|
@response = YAML.load(response.body)
|
57
66
|
}
|
58
67
|
}
|
59
68
|
end
|
60
|
-
|
69
|
+
|
61
70
|
def load_yaml(response)
|
62
71
|
begin
|
63
72
|
@response = YAML.load(response.body)
|
@@ -12,7 +12,8 @@ describe Rack::Handler::HTTP do
|
|
12
12
|
before(:all) do
|
13
13
|
app = Rack::Builder.app do
|
14
14
|
use Rack::Lint
|
15
|
-
use Rack::Static, :urls => ["/
|
15
|
+
use Rack::Static, :urls => ["/images"],
|
16
|
+
:root => TestRequest::Helpers::ROOT
|
16
17
|
run TestRequest.new
|
17
18
|
end
|
18
19
|
|
@@ -31,56 +32,56 @@ describe Rack::Handler::HTTP do
|
|
31
32
|
|
32
33
|
it "should respond to a simple get request" do
|
33
34
|
GET "/"
|
34
|
-
status.
|
35
|
+
expect(status).to eq(200)
|
35
36
|
end
|
36
37
|
|
37
38
|
it "should have CGI headers on GET" do
|
38
39
|
GET("/")
|
39
|
-
response["REQUEST_METHOD"].
|
40
|
-
response["SCRIPT_NAME"].
|
41
|
-
response["PATH_INFO"].
|
42
|
-
response["QUERY_STRING"].
|
43
|
-
response["test.postdata"].
|
40
|
+
expect(response["REQUEST_METHOD"]).to eq("GET")
|
41
|
+
expect(response["SCRIPT_NAME"]).to eq('')
|
42
|
+
expect(response["PATH_INFO"]).to eq("/")
|
43
|
+
expect(response["QUERY_STRING"]).to eq("")
|
44
|
+
expect(response["test.postdata"]).to eq("")
|
44
45
|
|
45
46
|
GET("/test/foo?quux=1")
|
46
|
-
response["REQUEST_METHOD"].
|
47
|
-
response["SCRIPT_NAME"].
|
48
|
-
response["REQUEST_URI"].
|
49
|
-
response["PATH_INFO"].
|
50
|
-
response["QUERY_STRING"].
|
47
|
+
expect(response["REQUEST_METHOD"]).to eq("GET")
|
48
|
+
expect(response["SCRIPT_NAME"]).to eq('')
|
49
|
+
expect(response["REQUEST_URI"]).to eq("/test/foo")
|
50
|
+
expect(response["PATH_INFO"]).to eq("/test/foo")
|
51
|
+
expect(response["QUERY_STRING"]).to eq("quux=1")
|
51
52
|
end
|
52
53
|
|
53
54
|
it "should have CGI headers on POST" do
|
54
55
|
POST("/", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
|
55
|
-
status.
|
56
|
-
response["REQUEST_METHOD"].
|
57
|
-
response["REQUEST_URI"].
|
58
|
-
response["QUERY_STRING"].
|
59
|
-
response["HTTP_X_TEST_HEADER"].
|
60
|
-
response["test.postdata"].
|
56
|
+
expect(status).to eq(200)
|
57
|
+
expect(response["REQUEST_METHOD"]).to eq("POST")
|
58
|
+
expect(response["REQUEST_URI"]).to eq("/")
|
59
|
+
expect(response["QUERY_STRING"]).to eq("")
|
60
|
+
expect(response["HTTP_X_TEST_HEADER"]).to eq("42")
|
61
|
+
expect(response["test.postdata"]).to eq("rack-form-data=23")
|
61
62
|
end
|
62
63
|
|
63
64
|
it "should support HTTP auth" do
|
64
65
|
GET("/test", {:user => "ruth", :passwd => "secret"})
|
65
|
-
response["HTTP_AUTHORIZATION"].
|
66
|
+
expect(response["HTTP_AUTHORIZATION"]).to eq("Basic cnV0aDpzZWNyZXQ=")
|
66
67
|
end
|
67
68
|
|
68
69
|
it "should set status" do
|
69
70
|
GET("/test?secret")
|
70
|
-
status.
|
71
|
-
response["rack.url_scheme"].
|
71
|
+
expect(status).to eq(403)
|
72
|
+
expect(response["rack.url_scheme"]).to eq("http")
|
72
73
|
end
|
73
74
|
|
74
75
|
it "should not set content-type to '' in requests" do
|
75
76
|
GET("/test", 'Content-Type' => '')
|
76
|
-
response['Content-Type'].
|
77
|
+
expect(response['Content-Type']).to eq(nil)
|
77
78
|
end
|
78
79
|
|
79
80
|
it "should serve images" do
|
80
81
|
file_size = File.size(File.join(File.dirname(__FILE__), 'images', 'image.jpg'))
|
81
|
-
GET("/
|
82
|
-
status.
|
83
|
-
response.content_length.
|
84
|
-
response.body.size.
|
82
|
+
GET("/images/image.jpg")
|
83
|
+
expect(status).to eq(200)
|
84
|
+
expect(response.content_length).to eq(file_size)
|
85
|
+
expect(response.body.size).to eq(file_size)
|
85
86
|
end
|
86
87
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,72 +1,72 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-http-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Postmodern
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2022-06-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: parslet
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: ore-tasks
|
27
|
-
requirement: &16920560 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
23
|
requirements:
|
30
|
-
- - ~>
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *16920560
|
26
|
+
version: '1.0'
|
36
27
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement:
|
39
|
-
none: false
|
28
|
+
name: gserver
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
40
30
|
requirements:
|
41
|
-
- - ~>
|
31
|
+
- - "~>"
|
42
32
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
44
|
-
type: :
|
33
|
+
version: '0.0'
|
34
|
+
type: :runtime
|
45
35
|
prerelease: false
|
46
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.0'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
49
|
-
requirement:
|
50
|
-
none: false
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
51
44
|
requirements:
|
52
|
-
- - ~>
|
45
|
+
- - "~>"
|
53
46
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
47
|
+
version: '2.0'
|
55
48
|
type: :development
|
56
49
|
prerelease: false
|
57
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
58
55
|
description: A Rack compatible pure Ruby HTTP Server.
|
59
56
|
email: postmodern.mod3@gmail.com
|
60
57
|
executables: []
|
61
58
|
extensions: []
|
62
|
-
extra_rdoc_files:
|
59
|
+
extra_rdoc_files:
|
60
|
+
- ChangeLog.md
|
61
|
+
- LICENSE.txt
|
62
|
+
- README.md
|
63
63
|
files:
|
64
|
-
- .document
|
65
|
-
- .
|
66
|
-
- .
|
67
|
-
- .
|
68
|
-
- .yardopts
|
64
|
+
- ".document"
|
65
|
+
- ".gitignore"
|
66
|
+
- ".rspec"
|
67
|
+
- ".yardopts"
|
69
68
|
- ChangeLog.md
|
69
|
+
- Gemfile
|
70
70
|
- LICENSE.txt
|
71
71
|
- README.md
|
72
72
|
- Rakefile
|
@@ -95,30 +95,33 @@ files:
|
|
95
95
|
- spec/rack/handler/http_spec.rb
|
96
96
|
- spec/rack/handler/images/image.jpg
|
97
97
|
- spec/spec_helper.rb
|
98
|
-
homepage:
|
98
|
+
homepage: https://github.com/postmodern/net-http-server#readme
|
99
99
|
licenses:
|
100
100
|
- MIT
|
101
|
-
|
101
|
+
metadata:
|
102
|
+
documentation_uri: https://rubydoc.info/gems/net-http-server
|
103
|
+
source_code_uri: https://github.com/postmodern/net-http-server
|
104
|
+
bug_tracker_uri: https://github.com/postmodern/net-http-server/issues
|
105
|
+
changelog_uri: https://github.com/postmodern/net-http-server/blob/master/ChangeLog.md
|
106
|
+
rubygems_mfa_required: 'true'
|
107
|
+
post_install_message:
|
102
108
|
rdoc_options: []
|
103
109
|
require_paths:
|
104
110
|
- lib
|
105
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
112
|
requirements:
|
108
|
-
- -
|
113
|
+
- - ">="
|
109
114
|
- !ruby/object:Gem::Version
|
110
115
|
version: '0'
|
111
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
-
none: false
|
113
117
|
requirements:
|
114
|
-
- -
|
118
|
+
- - ">="
|
115
119
|
- !ruby/object:Gem::Version
|
116
120
|
version: '0'
|
117
121
|
requirements: []
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
specification_version: 3
|
122
|
+
rubygems_version: 3.2.33
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
122
125
|
summary: A pure Ruby HTTP Server
|
123
126
|
test_files:
|
124
127
|
- spec/net/http/server/chunked_stream_spec.rb
|
data/.gemtest
DELETED
File without changes
|