jellyfish 1.2.0 → 1.2.1
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/CHANGES.md +9 -0
- data/jellyfish.gemspec +3 -3
- data/lib/jellyfish/builder.rb +1 -1
- data/lib/jellyfish/urlmap.rb +12 -2
- data/lib/jellyfish/version.rb +1 -1
- data/test/test_listen.rb +61 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 968788d7fa1a13e68a134a03948a619f2b09e3fb231208db5967039d0bcbaedf
|
4
|
+
data.tar.gz: 15e289eafd91bcc1a29ad3a45aae8eb791f5afa4c638bf5d7faec4452ecc8133
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cf801046630e4fb7752a0c673689b6d4fc137dc33113d740583dd96d2d4c36ad49423b220f4930e1d14e316c8183cc5adac28e6a9240f04f2f443f69ed6a665
|
7
|
+
data.tar.gz: 499291e4a77a571352ad48ea54c667539d1800d12eaa8299fb8ba4f3dfdfe0cc014e10eb3975a573bb1eceafa5749910d73bdaab1bf37d3543b71c067c8e9cc8
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## Jellyfish 1.2.1 -- 2018-07-21
|
4
|
+
|
5
|
+
### Bugs fixed
|
6
|
+
|
7
|
+
* Fixed mapping with host in some cases (longest match goes first)
|
8
|
+
* Fixed scheme matching with https. Now it won't try to map against https
|
9
|
+
because it's not that easy to implement and this is how `Rack::URLMap`
|
10
|
+
works anyway.
|
11
|
+
|
3
12
|
## Jellyfish 1.2.0 -- 2018-07-14
|
4
13
|
|
5
14
|
### Incompatible changes
|
data/jellyfish.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: jellyfish 1.2.
|
2
|
+
# stub: jellyfish 1.2.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "jellyfish".freeze
|
6
|
-
s.version = "1.2.
|
6
|
+
s.version = "1.2.1"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Lin Jen-Shin (godfat)".freeze]
|
11
|
-
s.date = "2018-07-
|
11
|
+
s.date = "2018-07-21"
|
12
12
|
s.description = "Pico web framework for building API-centric web applications.\nFor Rack applications or Rack middleware. Around 250 lines of code.\n\nCheck [jellyfish-contrib][] for extra extensions.\n\n[jellyfish-contrib]: https://github.com/godfat/jellyfish-contrib".freeze
|
13
13
|
s.email = ["godfat (XD) godfat.org".freeze]
|
14
14
|
s.files = [
|
data/lib/jellyfish/builder.rb
CHANGED
data/lib/jellyfish/urlmap.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
|
2
|
+
require 'uri'
|
3
|
+
|
2
4
|
module Jellyfish
|
3
5
|
class URLMap
|
4
6
|
def initialize mapped_not_chomped
|
@@ -6,7 +8,7 @@ module Jellyfish
|
|
6
8
|
keys = mapped.keys
|
7
9
|
@no_host = !keys.any?{ |k| match?(k, %r{\Ahttps?://}) }
|
8
10
|
|
9
|
-
string = keys.
|
11
|
+
string = sort_keys(keys).
|
10
12
|
map{ |k| build_regexp(k) }.
|
11
13
|
join('|')
|
12
14
|
|
@@ -36,7 +38,7 @@ module Jellyfish
|
|
36
38
|
else
|
37
39
|
File.join(host, script_name)
|
38
40
|
end
|
39
|
-
"
|
41
|
+
"http://#{host_with_path}"
|
40
42
|
else
|
41
43
|
script_name
|
42
44
|
end
|
@@ -87,5 +89,13 @@ module Jellyfish
|
|
87
89
|
string =~ regexp
|
88
90
|
end
|
89
91
|
end
|
92
|
+
|
93
|
+
def sort_keys keys
|
94
|
+
keys.sort_by do |k|
|
95
|
+
uri = URI.parse(k)
|
96
|
+
|
97
|
+
[-uri.path.to_s.size, -uri.host.to_s.size]
|
98
|
+
end
|
99
|
+
end
|
90
100
|
end
|
91
101
|
end
|
data/lib/jellyfish/version.rb
CHANGED
data/test/test_listen.rb
CHANGED
@@ -8,8 +8,11 @@ describe Jellyfish::URLMap do
|
|
8
8
|
lam = lambda{ |env| [200, {}, ["lam #{env['HTTP_HOST']}"]] }
|
9
9
|
ram = lambda{ |env| [200, {}, ["ram #{env['HTTP_HOST']}"]] }
|
10
10
|
|
11
|
-
def call app, host, path
|
12
|
-
get('/', app,
|
11
|
+
def call app, host, path: '/', scheme: 'http'
|
12
|
+
get('/', app,
|
13
|
+
'HTTP_HOST' => host,
|
14
|
+
'PATH_INFO' => path,
|
15
|
+
'rack.url_scheme' => scheme).dig(-1, 0)
|
13
16
|
end
|
14
17
|
|
15
18
|
would 'map host' do
|
@@ -25,6 +28,58 @@ describe Jellyfish::URLMap do
|
|
25
28
|
expect(call(app, 'lust')).eq 'ram lust'
|
26
29
|
end
|
27
30
|
|
31
|
+
would 'map host with path' do
|
32
|
+
app = Jellyfish::Builder.app do
|
33
|
+
map '/path', host: 'host' do
|
34
|
+
run lam
|
35
|
+
end
|
36
|
+
|
37
|
+
map '/path' do
|
38
|
+
run ram
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
expect(call(app, 'host', path: '/path')).eq 'lam host'
|
43
|
+
expect(call(app, 'lust', path: '/path')).eq 'ram lust'
|
44
|
+
end
|
45
|
+
|
46
|
+
would 'map longest path first' do
|
47
|
+
app = Jellyfish::Builder.app do
|
48
|
+
map '/long/path' do
|
49
|
+
run lam
|
50
|
+
end
|
51
|
+
|
52
|
+
map '/', host: 'super-long-host' do
|
53
|
+
run ram
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
expect(call(app, 'super-long-host', path: '/long/path')).
|
58
|
+
eq 'lam super-long-host'
|
59
|
+
end
|
60
|
+
|
61
|
+
would 'map host with http or https' do
|
62
|
+
app = Jellyfish::Builder.app do
|
63
|
+
map '/', host: 'host' do
|
64
|
+
run lam
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
expect(call(app, 'host')).eq 'lam host'
|
69
|
+
expect(call(app, 'host', scheme: 'https')).eq 'lam host'
|
70
|
+
end
|
71
|
+
|
72
|
+
would 'map http with http or https' do
|
73
|
+
app = Jellyfish::Builder.app do
|
74
|
+
map 'http://host/' do
|
75
|
+
run lam
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
expect(call(app, 'host')).eq 'lam host'
|
80
|
+
expect(call(app, 'host', scheme: 'https')).eq 'lam host'
|
81
|
+
end
|
82
|
+
|
28
83
|
would 'listen' do
|
29
84
|
app = Jellyfish::Builder.app do
|
30
85
|
listen 'host' do
|
@@ -56,9 +111,9 @@ describe Jellyfish::URLMap do
|
|
56
111
|
end
|
57
112
|
end
|
58
113
|
|
59
|
-
expect(call(app, 'host', '/host')).eq 'lam host'
|
60
|
-
expect(call(app, 'lust', '/lust')).eq 'ram lust'
|
61
|
-
expect(call(app, 'boom', '/host')).eq nil
|
62
|
-
expect(call(app, 'boom', '/lust')).eq nil
|
114
|
+
expect(call(app, 'host', path: '/host')).eq 'lam host'
|
115
|
+
expect(call(app, 'lust', path: '/lust')).eq 'ram lust'
|
116
|
+
expect(call(app, 'boom', path: '/host')).eq nil
|
117
|
+
expect(call(app, 'boom', path: '/lust')).eq nil
|
63
118
|
end
|
64
119
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jellyfish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lin Jen-Shin (godfat)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Pico web framework for building API-centric web applications.
|