apphttp 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/apphttp.rb +116 -10
- metadata +46 -26
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0321c0751594a3b0ac3ea9ac982e4f81f8060edd0668ae4030af6a6556e3c4c
|
4
|
+
data.tar.gz: 2ea8fc4f3feda515b4f2c62e3882a9acaabd2ce78370caa1a433946abf126d4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 546ff95fa168993a9130feaa2cea49ef51494f3ce3a1d4b73ca38c4eb6e6533a9c079b2f781e1de1d7163345b05f43c85a302be7eb902be5e445d9ff8d941889
|
7
|
+
data.tar.gz: e81e5edc7e40d9ca5cb39d6b6e7d3513085d2fb91962c6905c3c711beb18d6640f4fe944fac0fc839743aeb25cf613bc3f1c2a5d857b3f89b225c70cf9874ef4
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/apphttp.rb
CHANGED
@@ -6,12 +6,19 @@
|
|
6
6
|
|
7
7
|
require 'socket'
|
8
8
|
require 'json'
|
9
|
+
require 'c32'
|
10
|
+
require 'kramdown'
|
9
11
|
|
10
12
|
|
11
13
|
class AppHttp
|
14
|
+
using ColouredText
|
12
15
|
|
13
|
-
def initialize(app, host: '0.0.0.0', port: '9232',
|
16
|
+
def initialize(app, host: '0.0.0.0', port: '9232', filepath: '.',
|
17
|
+
headings: true, debug: false)
|
18
|
+
|
14
19
|
@app, @host, @port, @debug = app, host, port, debug
|
20
|
+
@filepath, @headings = filepath, headings
|
21
|
+
|
15
22
|
end
|
16
23
|
|
17
24
|
def start
|
@@ -20,11 +27,13 @@ class AppHttp
|
|
20
27
|
|
21
28
|
while (session = server.accept)
|
22
29
|
|
30
|
+
|
23
31
|
raw_request = session.gets
|
24
32
|
request = raw_request[/.[^\s]+(?= HTTP\/1\.\d)/].strip
|
25
33
|
|
26
|
-
|
27
|
-
|
34
|
+
puts ('request: ' + request.inspect).debug if @debug
|
35
|
+
result, content_type = get(request)
|
36
|
+
puts ('content_type: ' + content_type.inspect).debug if @debug
|
28
37
|
|
29
38
|
if result then
|
30
39
|
response = result
|
@@ -39,6 +48,7 @@ class AppHttp
|
|
39
48
|
session.print "\r\n"
|
40
49
|
session.print response
|
41
50
|
session.close
|
51
|
+
|
42
52
|
end
|
43
53
|
end
|
44
54
|
|
@@ -46,6 +56,15 @@ class AppHttp
|
|
46
56
|
|
47
57
|
def get(s)
|
48
58
|
|
59
|
+
if s == '/' then
|
60
|
+
|
61
|
+
fp = File.join(@filepath, 'index.html')
|
62
|
+
return (File.exists?(fp) ? File.read(fp) : default_index() )
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
return [s.to_s, 'text/plain'] if s =~ /^\/\w+\.\w+/
|
67
|
+
|
49
68
|
args = []
|
50
69
|
|
51
70
|
if s.count('/') > 1 then
|
@@ -53,11 +72,12 @@ class AppHttp
|
|
53
72
|
name, args = *s.split('/')[1..-1]
|
54
73
|
|
55
74
|
else
|
56
|
-
|
75
|
+
puts ('s: ' + s.inspect).debug if @debug
|
57
76
|
name, raw_params = s[/(?<=^\/).*/].split('?',2)
|
58
77
|
|
59
78
|
if raw_params then
|
60
79
|
|
80
|
+
puts ('raw_params: ' + raw_params.inspect).debug if @debug
|
61
81
|
raw_pairs = raw_params.split('&')
|
62
82
|
|
63
83
|
h = raw_pairs.inject({}) do |r,x|
|
@@ -86,21 +106,107 @@ class AppHttp
|
|
86
106
|
if @app.respond_to? name.to_sym then
|
87
107
|
|
88
108
|
begin
|
89
|
-
|
109
|
+
|
110
|
+
method = @app.method(name.to_sym)
|
111
|
+
|
112
|
+
if method.arity > 0 and args.length <= 0 then
|
113
|
+
r = "
|
114
|
+
<form action='#{name}'>
|
115
|
+
<input type='text' name='arg'></input>
|
116
|
+
<input type='submit'/>
|
117
|
+
</form>"
|
118
|
+
else
|
119
|
+
r = method.call(*args)
|
120
|
+
end
|
121
|
+
|
122
|
+
fp = File.join(@filepath, File.basename(name) + '.html')
|
123
|
+
|
124
|
+
content = if File.exists?(fp) then
|
125
|
+
render_html(fp, r)
|
126
|
+
else
|
127
|
+
|
128
|
+
if @headings then
|
129
|
+
markdown = "
|
130
|
+
# #{name.capitalize}
|
131
|
+
|
132
|
+
<output>#{r}</output>
|
133
|
+
"
|
134
|
+
|
135
|
+
Kramdown::Document.new(markdown).to_html
|
136
|
+
else
|
137
|
+
|
138
|
+
r
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
end
|
143
|
+
|
90
144
|
rescue
|
91
|
-
|
145
|
+
content = ($!).inspect
|
92
146
|
end
|
93
147
|
|
94
|
-
case
|
148
|
+
case content.class.to_s
|
95
149
|
when "String"
|
96
|
-
[
|
150
|
+
media = content.lstrip[0] == '<' ? 'html' : 'plain'
|
151
|
+
[content, 'text/' + media]
|
97
152
|
when "Hash"
|
98
|
-
[
|
153
|
+
[content.to_json,'application/json']
|
99
154
|
else
|
100
|
-
[
|
155
|
+
[content.to_s, 'text/plain']
|
101
156
|
end
|
102
157
|
end
|
103
158
|
|
104
159
|
end
|
160
|
+
|
161
|
+
def default_index()
|
162
|
+
|
163
|
+
a = (@app.public_methods - Object.public_methods).sort
|
164
|
+
s = a.map {|x| "* [%s](%s)" % [x,x]}.join("\n")
|
165
|
+
|
166
|
+
markdown = "
|
167
|
+
<html>
|
168
|
+
<head>
|
169
|
+
<title>#{@app.class.to_s}</title>
|
170
|
+
<style>
|
171
|
+
h1 {color: green}
|
172
|
+
h2 {color: orange}
|
173
|
+
div {height: 60%; overflow-y: auto; width: 200px; float: left}
|
174
|
+
</style>
|
175
|
+
</head>
|
176
|
+
<body markdown='1'>
|
177
|
+
|
178
|
+
# #{@app.class.to_s} Index
|
179
|
+
|
180
|
+
## Public Methods
|
181
|
+
|
182
|
+
<div markdown='1'>
|
183
|
+
#{s}
|
184
|
+
</div>
|
185
|
+
<iframe name='i1'></iframe>
|
186
|
+
<div style='clear: both' />
|
187
|
+
<hr/>
|
188
|
+
</body>
|
189
|
+
</html>
|
190
|
+
"
|
191
|
+
#markdown = s
|
192
|
+
doc = Rexle.new(Kramdown::Document.new(markdown).to_html)
|
193
|
+
|
194
|
+
doc.root.xpath('body/div/ul/li/a') do |link|
|
195
|
+
link.attributes[:target] = 'i1'
|
196
|
+
end
|
197
|
+
|
198
|
+
[doc.xml(pretty: true), 'text/html']
|
199
|
+
end
|
200
|
+
|
201
|
+
def render_html(fp, s)
|
202
|
+
|
203
|
+
doc = Rexle.new(File.read fp)
|
204
|
+
e = doc.root.element('//[@class="output"]')
|
205
|
+
e.text = s
|
206
|
+
|
207
|
+
|
208
|
+
doc.xml pretty: true
|
209
|
+
|
210
|
+
end
|
105
211
|
|
106
212
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apphttp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -11,32 +11,52 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjAxMDI1MTgzMDUzWhcN
|
15
|
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peh8d7lpMY0Ar3/iBOJ/CLzPZxnQOO/L8hUx
|
29
|
+
9Y1rU3wrxbq6ZaJazal9FpH/+8TXs4Rk/sHcdYbNJ031gBQuXDnun5JVT++lRv3z
|
30
|
+
AcO+eEweQkY1QvQuQt8YJWM3kR/+iBZEJxZfhVKZ2LT+u7p5qy9PyDbLH3kQf4R+
|
31
|
+
NwTlXYUgqYMFPL6nrzu1gsXwwtjOMW7PV2G5o8zzW90rSJviq6b7h6n9qH1oCGab
|
32
|
+
/osxrMpUUvRl2qSw9DHHM7OgJYM0y4GaEqJxW3p4t4gTxsdBUc1sx4VxPCBWhME6
|
33
|
+
cEYKfr3lvkt7pd36ZrQDLh+e6bUMWosF67in6gkHqEHI+cxDs3bPjmMxO9pMDlLW
|
34
|
+
ET0FcDwN5GiQc5tl1FtwGt55M7s6AsLwIDGxQrxFNJwVQw0x9hfMBebLBtldy1sN
|
35
|
+
fhU7xyc9cI6elrvCBt5DlvbaQn1ZdmYHfPPe4BgcB7hg9ADcQubuuZJy+KvRZADs
|
36
|
+
h/GUx4K959hkyRunR+SmqC7C
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
39
|
-
dependencies:
|
38
|
+
date: 2020-10-25 00:00:00.000000000 Z
|
39
|
+
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: kramdown
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.3.0
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.3'
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.3.0
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '2.3'
|
40
60
|
description:
|
41
61
|
email: james@jamesrobertson.eu
|
42
62
|
executables: []
|
@@ -63,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
83
|
- !ruby/object:Gem::Version
|
64
84
|
version: '0'
|
65
85
|
requirements: []
|
66
|
-
rubygems_version: 3.0.
|
86
|
+
rubygems_version: 3.0.3
|
67
87
|
signing_key:
|
68
88
|
specification_version: 4
|
69
89
|
summary: Makes it trivial to web enable a Ruby project.
|
metadata.gz.sig
CHANGED
Binary file
|