Skip to content

Commit

Permalink
Well, Rack doesn't support matching against https anyway...
Browse files Browse the repository at this point in the history
  • Loading branch information
godfat committed Jul 15, 2018
1 parent 541d02d commit e518d77
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/jellyfish/urlmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def call env
else
File.join(host, script_name)
end
"#{env['rack.url_scheme']}://#{host_with_path}"
"http://#{host_with_path}"
else
script_name
end
Expand Down
43 changes: 34 additions & 9 deletions test/test_listen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
lam = lambda{ |env| [200, {}, ["lam #{env['HTTP_HOST']}"]] }
ram = lambda{ |env| [200, {}, ["ram #{env['HTTP_HOST']}"]] }

def call app, host, path='/'
get('/', app, 'HTTP_HOST' => host, 'PATH_INFO' => path).dig(-1, 0)
def call app, host, path: '/', scheme: 'http'
get('/', app,
'HTTP_HOST' => host,
'PATH_INFO' => path,
'rack.url_scheme' => scheme).dig(-1, 0)
end

would 'map host' do
Expand All @@ -36,8 +39,8 @@ def call app, host, path='/'
end
end

expect(call(app, 'host', '/path')).eq 'lam host'
expect(call(app, 'lust', '/path')).eq 'ram lust'
expect(call(app, 'host', path: '/path')).eq 'lam host'
expect(call(app, 'lust', path: '/path')).eq 'ram lust'
end

would 'map longest path first' do
Expand All @@ -51,10 +54,32 @@ def call app, host, path='/'
end
end

expect(call(app, 'super-long-host', '/long/path')).
expect(call(app, 'super-long-host', path: '/long/path')).
eq 'lam super-long-host'
end

would 'map host with http or https' do
app = Jellyfish::Builder.app do
map '/', host: 'host' do
run lam
end
end

expect(call(app, 'host')).eq 'lam host'
expect(call(app, 'host', scheme: 'https')).eq 'lam host'
end

would 'map http with http or https' do
app = Jellyfish::Builder.app do
map 'http://host/' do
run lam
end
end

expect(call(app, 'host')).eq 'lam host'
expect(call(app, 'host', scheme: 'https')).eq 'lam host'
end

would 'listen' do
app = Jellyfish::Builder.app do
listen 'host' do
Expand Down Expand Up @@ -86,9 +111,9 @@ def call app, host, path='/'
end
end

expect(call(app, 'host', '/host')).eq 'lam host'
expect(call(app, 'lust', '/lust')).eq 'ram lust'
expect(call(app, 'boom', '/host')).eq nil
expect(call(app, 'boom', '/lust')).eq nil
expect(call(app, 'host', path: '/host')).eq 'lam host'
expect(call(app, 'lust', path: '/lust')).eq 'ram lust'
expect(call(app, 'boom', path: '/host')).eq nil
expect(call(app, 'boom', path: '/lust')).eq nil
end
end

0 comments on commit e518d77

Please sign in to comment.