funky-simplehttp 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +24 -4
- data/Rakefile +6 -32
- data/funky-simplehttp.gemspec +6 -5
- data/lib/version.rb +5 -0
- metadata +17 -18
- data/lib/funky-simplehttp.rb +0 -255
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91eb1f2def5e71aa35240632d575ecbff9071f3c
|
4
|
+
data.tar.gz: 6feb16d0852cf57f3f813b81135285b459033919
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2880c6336480feab81bde1c999f46b10d63fc9048902e7fcbfcd75ec4566a07295216886b9dfcb0233cabdc003901460a5cbf4c600cffa73b0d4b1e574e038fc
|
7
|
+
data.tar.gz: 323180e1ad0f4d3d5450f44dda266355bdb4cc466d6d710ae38f21e0337520209c47b76b85abd4bdbbf0c2c4d44715a397b6faaa0e20d09502833a83aca90115
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,17 +1,37 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
funky-simplehttp (0.
|
4
|
+
funky-simplehttp (0.5.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
9
|
+
archive-zip (0.10.0)
|
10
|
+
io-like (~> 0.3.0)
|
11
|
+
cloudwalk_handshake (0.12.0)
|
12
|
+
da_funk (1.3.1)
|
13
|
+
archive-zip (~> 0.5)
|
14
|
+
bundler
|
15
|
+
cloudwalk_handshake
|
16
|
+
funky-emv
|
17
|
+
posxml_parser
|
18
|
+
rake
|
19
|
+
funky-emv (0.15.0)
|
20
|
+
funky-tlv (~> 0.2)
|
21
|
+
funky-tlv (0.2.3)
|
22
|
+
io-like (0.3.0)
|
23
|
+
posxml_parser (1.1.0)
|
24
|
+
funky-emv (~> 0.3)
|
25
|
+
rake (12.3.0)
|
10
26
|
|
11
27
|
PLATFORMS
|
12
28
|
ruby
|
13
29
|
|
14
30
|
DEPENDENCIES
|
15
|
-
bundler
|
31
|
+
bundler
|
32
|
+
da_funk (~> 1.3)
|
16
33
|
funky-simplehttp!
|
17
|
-
rake
|
34
|
+
rake
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.16.1
|
data/Rakefile
CHANGED
@@ -1,36 +1,10 @@
|
|
1
1
|
require 'rake'
|
2
|
-
|
2
|
+
require 'fileutils'
|
3
|
+
require 'bundler/setup'
|
3
4
|
|
4
|
-
|
5
|
-
SIMPLEHTTP_OUT = File.join(SIMPLEHTTP_ROOT, "out", "funky-simplehttp.mrb")
|
5
|
+
Bundler.require(:default)
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
if ENV["MRBC"].nil?
|
11
|
-
if system("type cloudwalk > /dev/null 2>&1 ")
|
12
|
-
ENV["MRBC"] = "env cloudwalk compile"
|
13
|
-
elsif system("type mrbc > /dev/null 2>&1 ")
|
14
|
-
ENV["MRBC"] = "env mrbc"
|
15
|
-
else
|
16
|
-
puts "$MRBC isn't set or mrbc/cloudwalk isn't on $PATH"
|
17
|
-
exit 0
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
desc "Compile simplehttp to mrb"
|
23
|
-
task :build => :check do
|
24
|
-
sh "mkdir -p #{File.join(SIMPLEHTTP_ROOT, "out")}"
|
25
|
-
if ENV["MRBC"]
|
26
|
-
sh "#{ENV["MRBC"]} -g -o #{SIMPLEHTTP_OUT} #{File.join(SIMPLEHTTP_ROOT, "lib", "funky-simplehttp.rb")} "
|
27
|
-
else
|
28
|
-
sh "env mrbc -g -o #{SIMPLEHTTP_OUT} #{File.join(SIMPLEHTTP_ROOT, "lib", "funky-simplehttp.rb")} "
|
29
|
-
end
|
7
|
+
DaFunk::RakeTask.new do |t|
|
8
|
+
t.mrbc = "cloudwalk compile"
|
9
|
+
t.mruby = "cloudwalk run -b"
|
30
10
|
end
|
31
|
-
|
32
|
-
desc "Clobber/Clean"
|
33
|
-
task :clean => :check do
|
34
|
-
sh "mkdir -p out"
|
35
|
-
sh "rm -f #{SIMPLEHTTP_OUT}"
|
36
|
-
end
|
data/funky-simplehttp.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'version.rb'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "funky-simplehttp"
|
@@ -12,11 +12,12 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = "Minimal HTTP implementation"
|
13
13
|
spec.homepage = "http://github.com/cloudwalkio/funky-simplehttp"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.files =
|
16
|
-
spec.executables =
|
15
|
+
spec.files = %w(.gitignore Gemfile Gemfile.lock README.md Rakefile funky-simplehttp.gemspec lib/version.rb out/funky-simplehttp/main.mrb)
|
16
|
+
spec.executables = []
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
|
+
spec.required_ruby_version = '>= 1.9.3'
|
19
20
|
|
20
|
-
spec.add_development_dependency "bundler"
|
21
|
-
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake"
|
22
23
|
end
|
data/lib/version.rb
ADDED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: funky-simplehttp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thiago Scalone
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
description: Minimal HTTP implementation
|
42
42
|
email:
|
43
43
|
- thiago@scalone.com.br
|
@@ -45,14 +45,14 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
48
|
+
- ".gitignore"
|
49
49
|
- Gemfile
|
50
50
|
- Gemfile.lock
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- funky-simplehttp.gemspec
|
54
|
-
- lib/
|
55
|
-
- out/funky-simplehttp.mrb
|
54
|
+
- lib/version.rb
|
55
|
+
- out/funky-simplehttp/main.mrb
|
56
56
|
homepage: http://github.com/cloudwalkio/funky-simplehttp
|
57
57
|
licenses:
|
58
58
|
- MIT
|
@@ -63,19 +63,18 @@ require_paths:
|
|
63
63
|
- lib
|
64
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 1.9.3
|
69
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- -
|
71
|
+
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
75
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
76
|
+
rubygems_version: 2.6.14
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: Simplehttp
|
80
80
|
test_files: []
|
81
|
-
has_rdoc:
|
data/lib/funky-simplehttp.rb
DELETED
@@ -1,255 +0,0 @@
|
|
1
|
-
class SimpleHttp
|
2
|
-
DEFAULTPORT = 80
|
3
|
-
DEFAULTHTTPSPORT = 443
|
4
|
-
HTTP_VERSION = "HTTP/1.0"
|
5
|
-
DEFAULT_ACCEPT = "*/*"
|
6
|
-
SEP = "\r\n"
|
7
|
-
|
8
|
-
def self.version
|
9
|
-
"0.4.4"
|
10
|
-
end
|
11
|
-
|
12
|
-
attr_accessor :socket, :socket_tcp, :support_fiber
|
13
|
-
|
14
|
-
def socket_class_exist?
|
15
|
-
c = Module.const_get("TCPSocket")
|
16
|
-
c.is_a?(Class)
|
17
|
-
rescue
|
18
|
-
return false
|
19
|
-
end
|
20
|
-
|
21
|
-
def uv_module_exist?
|
22
|
-
c = Module.const_get("UV")
|
23
|
-
c.is_a?(Module)
|
24
|
-
rescue
|
25
|
-
return false
|
26
|
-
end
|
27
|
-
|
28
|
-
def initialize(schema, address, port = nil)
|
29
|
-
@use_socket = false
|
30
|
-
@use_uv = false
|
31
|
-
if socket_class_exist?
|
32
|
-
@use_socket = true
|
33
|
-
end
|
34
|
-
|
35
|
-
if uv_module_exist?
|
36
|
-
@use_uv = true
|
37
|
-
end
|
38
|
-
@uri = {}
|
39
|
-
if @use_socket
|
40
|
-
# nothing
|
41
|
-
elsif @use_uv
|
42
|
-
ip = ""
|
43
|
-
UV::getaddrinfo(address, "http") do |x, info|
|
44
|
-
if info
|
45
|
-
ip = info.addr
|
46
|
-
end
|
47
|
-
end
|
48
|
-
UV::run()
|
49
|
-
@uri[:ip] = ip
|
50
|
-
else
|
51
|
-
raise "Not found Socket Class or UV Module"
|
52
|
-
end
|
53
|
-
@uri[:schema] = schema
|
54
|
-
@uri[:address] = address
|
55
|
-
if schema == "https"
|
56
|
-
@uri[:port] = port ? port.to_i : DEFAULTHTTPSPORT
|
57
|
-
else
|
58
|
-
@uri[:port] = port ? port.to_i : DEFAULTPORT
|
59
|
-
end
|
60
|
-
self
|
61
|
-
end
|
62
|
-
|
63
|
-
def address; @uri[:address]; end
|
64
|
-
def port; @uri[:port]; end
|
65
|
-
|
66
|
-
def get(path = "/", req = nil)
|
67
|
-
request("GET", path, req)
|
68
|
-
end
|
69
|
-
|
70
|
-
def post(path = "/", req = nil)
|
71
|
-
request("POST", path, req)
|
72
|
-
end
|
73
|
-
|
74
|
-
# private
|
75
|
-
def request(method, path, req)
|
76
|
-
@uri[:path] = path
|
77
|
-
if @uri[:path].nil?
|
78
|
-
@uri[:path] = "/"
|
79
|
-
elsif @uri[:path][0] != "/"
|
80
|
-
@uri[:path] = "/" + @uri[:path]
|
81
|
-
end
|
82
|
-
request_header = create_request_header(method.upcase.to_s, req)
|
83
|
-
response_text = send_request(request_header)
|
84
|
-
SimpleHttpResponse.new(response_text)
|
85
|
-
end
|
86
|
-
|
87
|
-
def read_fiber
|
88
|
-
response_text = ""
|
89
|
-
loop do
|
90
|
-
return "" if (@socket_tcp.nil? || @socket_tcp.closed?)
|
91
|
-
usleep(10000)
|
92
|
-
if (available = socket.bytes_available) > 0
|
93
|
-
usleep(10000)
|
94
|
-
t = socket.read(available)
|
95
|
-
usleep(10000)
|
96
|
-
break if t.nil?
|
97
|
-
response_text << t
|
98
|
-
end
|
99
|
-
finish = Fiber.yield(false)
|
100
|
-
if finish
|
101
|
-
return response_text
|
102
|
-
end
|
103
|
-
end
|
104
|
-
response_text
|
105
|
-
end
|
106
|
-
|
107
|
-
def read_normal
|
108
|
-
response_text = ""
|
109
|
-
while (t = socket.read(1024))
|
110
|
-
response_text += t
|
111
|
-
end
|
112
|
-
response_text
|
113
|
-
end
|
114
|
-
|
115
|
-
def support_fiber?
|
116
|
-
@support_fiber
|
117
|
-
end
|
118
|
-
|
119
|
-
def send_request(request_header)
|
120
|
-
response_text = ""
|
121
|
-
if @socket
|
122
|
-
socket.write(request_header)
|
123
|
-
if support_fiber?
|
124
|
-
response_text = read_fiber
|
125
|
-
else
|
126
|
-
response_text = read_normal
|
127
|
-
end
|
128
|
-
elsif @use_socket
|
129
|
-
@socket = TCPSocket.new(@uri[:address], @uri[:port])
|
130
|
-
if @uri[:schema] == "https"
|
131
|
-
entropy = PolarSSL::Entropy.new
|
132
|
-
ctr_drbg = PolarSSL::CtrDrbg.new entropy
|
133
|
-
ssl = PolarSSL::SSL.new
|
134
|
-
ssl.set_endpoint PolarSSL::SSL::SSL_IS_CLIENT
|
135
|
-
ssl.set_rng ctr_drbg
|
136
|
-
ssl.set_socket socket
|
137
|
-
ssl.handshake
|
138
|
-
ssl.write request_header
|
139
|
-
while chunk = ssl.read(2048)
|
140
|
-
response_text += chunk
|
141
|
-
end
|
142
|
-
ssl.close_notify
|
143
|
-
socket.close
|
144
|
-
ssl.close
|
145
|
-
else
|
146
|
-
socket.write(request_header)
|
147
|
-
while (t = socket.read(1024))
|
148
|
-
response_text += t
|
149
|
-
end
|
150
|
-
socket.close
|
151
|
-
end
|
152
|
-
elsif @use_uv
|
153
|
-
socket = UV::TCP.new()
|
154
|
-
socket.connect(UV.ip4_addr(@uri[:ip].sin_addr, @uri[:port])) do |x|
|
155
|
-
if x == 0
|
156
|
-
socket.write(request_header) do |x|
|
157
|
-
socket.read_start do |b|
|
158
|
-
response_text += b.to_s
|
159
|
-
end
|
160
|
-
end
|
161
|
-
else
|
162
|
-
socket.close()
|
163
|
-
end
|
164
|
-
end
|
165
|
-
UV::run()
|
166
|
-
else
|
167
|
-
raise "Not found Socket Class or UV Module"
|
168
|
-
end
|
169
|
-
response_text
|
170
|
-
end
|
171
|
-
|
172
|
-
def create_request_header(method, req)
|
173
|
-
req = {} unless req
|
174
|
-
str = ""
|
175
|
-
body = ""
|
176
|
-
str += sprintf("%s %s %s", method, @uri[:path], HTTP_VERSION) + SEP
|
177
|
-
header = {}
|
178
|
-
req.each do |key,value|
|
179
|
-
header[key.capitalize] = value
|
180
|
-
end
|
181
|
-
header["Host"] = @uri[:address] unless header.keys.include?("Host")
|
182
|
-
header["Accept"] = DEFAULT_ACCEPT unless header.keys.include?("Accept")
|
183
|
-
header["Connection"] = "close"
|
184
|
-
if header["Body"]
|
185
|
-
body = header["Body"]
|
186
|
-
header.delete("Body")
|
187
|
-
end
|
188
|
-
if method == "POST" && (not header.keys.include?("content-length".capitalize))
|
189
|
-
header["Content-Length"] = (body || '').length
|
190
|
-
end
|
191
|
-
header.keys.sort.each do |key|
|
192
|
-
str += sprintf("%s: %s", key, header[key]) + SEP
|
193
|
-
end
|
194
|
-
str + SEP + body
|
195
|
-
end
|
196
|
-
|
197
|
-
class SimpleHttpResponse
|
198
|
-
SEP = SimpleHttp::SEP
|
199
|
-
def initialize(response_text)
|
200
|
-
@response = {}
|
201
|
-
@headers = {}
|
202
|
-
if response_text.empty?
|
203
|
-
@response["header"] = nil
|
204
|
-
elsif response_text.include?(SEP + SEP)
|
205
|
-
@response["header"], @response["body"] = response_text.split(SEP + SEP, 2)
|
206
|
-
else
|
207
|
-
@response["header"] = response_text
|
208
|
-
end
|
209
|
-
parse_header
|
210
|
-
self
|
211
|
-
end
|
212
|
-
|
213
|
-
def [](key); @response[key]; end
|
214
|
-
def []=(key, value); @response[key] = value; end
|
215
|
-
|
216
|
-
def header; @response['header']; end
|
217
|
-
def headers; @headers; end
|
218
|
-
def body; @response['body']; end
|
219
|
-
def status; @response['status']; end
|
220
|
-
def code; @response['code']; end
|
221
|
-
def date; @response['date']; end
|
222
|
-
def content_type; @response['content-type']; end
|
223
|
-
def content_length; @response['content-length']; end
|
224
|
-
|
225
|
-
def each(&block)
|
226
|
-
if block
|
227
|
-
@response.each do |k,v| block.call(k,v) end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
def each_name(&block)
|
231
|
-
if block
|
232
|
-
@response.each do |k,v| block.call(k) end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
# private
|
237
|
-
def parse_header
|
238
|
-
return unless @response["header"]
|
239
|
-
h = @response["header"].split(SEP)
|
240
|
-
if h[0].include?("HTTP/1")
|
241
|
-
@response["status"] = h[0].split(" ", 2).last
|
242
|
-
@response["code"] = h[0].split(" ", 3)[1].to_i
|
243
|
-
end
|
244
|
-
h.each do |line|
|
245
|
-
if line.include?(": ")
|
246
|
-
k,v = line.split(": ")
|
247
|
-
@response[k.downcase] = v
|
248
|
-
@headers[k.downcase] = v
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
|