angelo 0.1.13 → 0.1.14
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 +4 -4
- data/.gitignore +0 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +63 -0
- data/lib/angelo.rb +1 -1
- data/lib/angelo/base.rb +29 -0
- data/lib/angelo/server.rb +1 -13
- data/lib/angelo/version.rb +1 -1
- data/test/angelo/static_spec.rb +37 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab8dc2d9fc7243d0fafec32530e5509351ecfcec
|
4
|
+
data.tar.gz: 37488c61321c6ffd9d4524371eb295fd2b425a8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07c8b7aef24a27aece1e2d012bfd910598445241943b24714f21739cfbef8ac686c7594c873331fb4f71702af1dd11d7161db74861fdc79464bcea2abb822f81
|
7
|
+
data.tar.gz: 32ffbf2ce2540b29be61110aeaf7b14aef8d21fb50634ee07692e32eac0cb3a25ec7b0a356cdd5804ffb748df7e8e2b7cae5a8d2efaaee867154ba4be54ee616
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
celluloid (0.15.2)
|
5
|
+
timers (~> 1.1.0)
|
6
|
+
celluloid-io (0.15.0)
|
7
|
+
celluloid (>= 0.15.0)
|
8
|
+
nio4r (>= 0.5.0)
|
9
|
+
coderay (1.1.0)
|
10
|
+
ffi (1.9.3-java)
|
11
|
+
http (0.6.1)
|
12
|
+
http_parser.rb (~> 0.6.0)
|
13
|
+
http_parser.rb (0.6.0)
|
14
|
+
http_parser.rb (0.6.0-java)
|
15
|
+
httpclient (2.4.0)
|
16
|
+
method_source (0.8.2)
|
17
|
+
mime-types (2.3)
|
18
|
+
minitest (5.3.5)
|
19
|
+
mustermann (0.2.0)
|
20
|
+
nio4r (1.0.0)
|
21
|
+
nio4r (1.0.0-java)
|
22
|
+
pry (0.9.12.6)
|
23
|
+
coderay (~> 1.0)
|
24
|
+
method_source (~> 0.8)
|
25
|
+
slop (~> 3.4)
|
26
|
+
pry (0.9.12.6-java)
|
27
|
+
coderay (~> 1.0)
|
28
|
+
method_source (~> 0.8)
|
29
|
+
slop (~> 3.4)
|
30
|
+
spoon (~> 0.0)
|
31
|
+
pry-nav (0.2.3)
|
32
|
+
pry (~> 0.9.10)
|
33
|
+
reel (0.5.0)
|
34
|
+
celluloid (>= 0.15.1)
|
35
|
+
celluloid-io (>= 0.15.0)
|
36
|
+
http (>= 0.6.0.pre)
|
37
|
+
http_parser.rb (>= 0.6.0)
|
38
|
+
websocket_parser (>= 0.1.6)
|
39
|
+
ruby-prof (0.15.1)
|
40
|
+
slop (3.5.0)
|
41
|
+
spoon (0.0.4)
|
42
|
+
ffi
|
43
|
+
tilt (2.0.1)
|
44
|
+
timers (1.1.0)
|
45
|
+
websocket-driver (0.3.3)
|
46
|
+
websocket-driver (0.3.3-java)
|
47
|
+
websocket_parser (0.1.6)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
java
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
httpclient
|
55
|
+
mime-types
|
56
|
+
minitest
|
57
|
+
mustermann
|
58
|
+
pry
|
59
|
+
pry-nav
|
60
|
+
reel
|
61
|
+
ruby-prof
|
62
|
+
tilt
|
63
|
+
websocket-driver
|
data/lib/angelo.rb
CHANGED
@@ -21,7 +21,7 @@ module Angelo
|
|
21
21
|
CONTENT_TYPE_HEADER_KEY = 'Content-Type'
|
22
22
|
CONTENT_DISPOSITION_HEADER_KEY = 'Content-Disposition'
|
23
23
|
CONTENT_LENGTH_HEADER_KEY = 'Content-Length'
|
24
|
-
|
24
|
+
ATTACHMENT_CONTENT_DISPOSITION = 'attachment; filename="%s"'
|
25
25
|
ETAG_HEADER_KEY = 'ETag'
|
26
26
|
IF_NONE_MATCH_HEADER_KEY = 'If-None-Match'
|
27
27
|
LOCATION_HEADER_KEY = 'Location'
|
data/lib/angelo/base.rb
CHANGED
@@ -119,6 +119,13 @@ module Angelo
|
|
119
119
|
sleep
|
120
120
|
end
|
121
121
|
|
122
|
+
def local_path path
|
123
|
+
if public_dir
|
124
|
+
lp = File.join(public_dir, path)
|
125
|
+
File.file?(lp) ? lp : nil
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
122
129
|
end
|
123
130
|
|
124
131
|
def async meth, *args
|
@@ -172,6 +179,28 @@ module Angelo
|
|
172
179
|
throw :halt, HALT_STRUCT.new(status, body)
|
173
180
|
end
|
174
181
|
|
182
|
+
def send_file local_file, opts = {}
|
183
|
+
lp = self.class.local_path local_file
|
184
|
+
|
185
|
+
# Content-Type
|
186
|
+
#
|
187
|
+
headers CONTENT_TYPE_HEADER_KEY =>
|
188
|
+
(MIME::Types.type_for(File.extname(lp))[0].content_type rescue HTML_TYPE)
|
189
|
+
|
190
|
+
# Content-Disposition
|
191
|
+
#
|
192
|
+
if opts[:disposition] == :attachment or opts[:filename]
|
193
|
+
headers CONTENT_DISPOSITION_HEADER_KEY =>
|
194
|
+
ATTACHMENT_CONTENT_DISPOSITION % (opts[:filename] or File.basename(lp))
|
195
|
+
end
|
196
|
+
|
197
|
+
# Content-Length
|
198
|
+
#
|
199
|
+
headers CONTENT_LENGTH_HEADER_KEY => File.size(lp)
|
200
|
+
|
201
|
+
halt 200, File.read(lp)
|
202
|
+
end
|
203
|
+
|
175
204
|
end
|
176
205
|
|
177
206
|
end
|
data/lib/angelo/server.rb
CHANGED
@@ -36,7 +36,7 @@ module Angelo
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def dispatch! meth, connection, request
|
39
|
-
if staticable?(meth) and lp = local_path(request.path)
|
39
|
+
if staticable?(meth) and lp = @base.local_path(request.path)
|
40
40
|
static! meth, connection, request, lp
|
41
41
|
else
|
42
42
|
route! meth, connection, request
|
@@ -56,13 +56,6 @@ module Angelo
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
def local_path path
|
60
|
-
if @base.public_dir
|
61
|
-
lp = File.join(@base.public_dir, path)
|
62
|
-
File.file?(lp) ? lp : nil
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
59
|
def staticable? meth
|
67
60
|
STATICABLE.include? meth
|
68
61
|
end
|
@@ -80,11 +73,6 @@ module Angelo
|
|
80
73
|
CONTENT_TYPE_HEADER_KEY =>
|
81
74
|
(MIME::Types.type_for(File.extname(local_path))[0].content_type rescue HTML_TYPE),
|
82
75
|
|
83
|
-
# Content-Disposition
|
84
|
-
#
|
85
|
-
CONTENT_DISPOSITION_HEADER_KEY =>
|
86
|
-
DEFAULT_CONTENT_DISPOSITION + "; filename=#{File.basename local_path}",
|
87
|
-
|
88
76
|
# Content-Length
|
89
77
|
#
|
90
78
|
CONTENT_LENGTH_HEADER_KEY => File.size(local_path),
|
data/lib/angelo/version.rb
CHANGED
data/test/angelo/static_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Angelo::Server do
|
|
5
5
|
|
6
6
|
describe 'serving static files' do
|
7
7
|
|
8
|
-
|
8
|
+
def css_etag
|
9
9
|
fs = File::Stat.new File.join(TEST_APP_ROOT, 'public', 'test.css')
|
10
10
|
OpenSSL::Digest::SHA.hexdigest fs.ino.to_s + fs.size.to_s + fs.mtime.to_s
|
11
11
|
end
|
@@ -18,13 +18,25 @@ describe Angelo::Server do
|
|
18
18
|
'you should not see this'
|
19
19
|
end
|
20
20
|
|
21
|
+
get '/img' do
|
22
|
+
send_file 'what.png'
|
23
|
+
end
|
24
|
+
|
25
|
+
get '/what' do
|
26
|
+
send_file 'what.png', disposition: :attachment
|
27
|
+
end
|
28
|
+
|
29
|
+
get '/attachment.png' do
|
30
|
+
send_file 'what.png', filename: 'attachment.png'
|
31
|
+
end
|
32
|
+
|
21
33
|
end
|
22
34
|
|
23
35
|
it 'serves static files for gets' do
|
24
36
|
get '/test.css'
|
25
37
|
last_response.status.must_equal 200
|
26
38
|
last_response.headers['Content-Type'].must_equal 'text/css'
|
27
|
-
last_response.headers['Content-Disposition'].
|
39
|
+
last_response.headers['Content-Disposition'].must_be_nil
|
28
40
|
last_response.headers['Content-Length'].must_equal '116'
|
29
41
|
last_response.headers['Etag'].must_equal css_etag
|
30
42
|
last_response.body.to_s.length.must_equal 116
|
@@ -35,7 +47,7 @@ describe Angelo::Server do
|
|
35
47
|
head '/test.css'
|
36
48
|
last_response.status.must_equal 200
|
37
49
|
last_response.headers['Content-Type'].must_equal 'text/css'
|
38
|
-
last_response.headers['Content-Disposition'].
|
50
|
+
last_response.headers['Content-Disposition'].must_be_nil
|
39
51
|
last_response.headers['Content-Length'].must_equal '116'
|
40
52
|
last_response.headers['Etag'].must_equal css_etag
|
41
53
|
last_response.body.to_s.length.must_equal 0
|
@@ -45,7 +57,7 @@ describe Angelo::Server do
|
|
45
57
|
get '/test.html'
|
46
58
|
last_response.status.must_equal 200
|
47
59
|
last_response.headers['Content-Type'].must_equal 'text/html'
|
48
|
-
last_response.headers['Content-Disposition'].
|
60
|
+
last_response.headers['Content-Disposition'].must_be_nil
|
49
61
|
last_response.body.to_s.must_equal File.read(File.join TEST_APP_ROOT, 'public', 'test.html')
|
50
62
|
end
|
51
63
|
|
@@ -67,6 +79,26 @@ describe Angelo::Server do
|
|
67
79
|
end
|
68
80
|
end
|
69
81
|
|
70
|
-
|
82
|
+
it 'sends files' do
|
83
|
+
get '/img'
|
84
|
+
last_response.status.must_equal 200
|
85
|
+
last_response.headers['Content-Type'].must_equal 'image/png'
|
86
|
+
last_response.headers['Content-Disposition'].must_be_nil
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'sends files with attachment disposition' do
|
90
|
+
get '/what'
|
91
|
+
last_response.status.must_equal 200
|
92
|
+
last_response.headers['Content-Type'].must_equal 'image/png'
|
93
|
+
last_response.headers['Content-Disposition'].must_equal 'attachment; filename="what.png"'
|
94
|
+
end
|
71
95
|
|
96
|
+
it 'sends files as different filename' do
|
97
|
+
get '/attachment.png'
|
98
|
+
last_response.status.must_equal 200
|
99
|
+
last_response.headers['Content-Type'].must_equal 'image/png'
|
100
|
+
last_response.headers['Content-Disposition'].must_equal 'attachment; filename="attachment.png"'
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
72
104
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angelo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenichi Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reel
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- ".travis.yml"
|
50
50
|
- CHANGELOG.md
|
51
51
|
- Gemfile
|
52
|
+
- Gemfile.lock
|
52
53
|
- LICENSE
|
53
54
|
- README.md
|
54
55
|
- Rakefile
|