Commit 3428d92b authored by Terence Lee's avatar Terence Lee Committed by GitHub

Merge pull request #65 from heroku/https_only_proxies

https_only happens over proxies
parents 0aebb10e e31a532f
...@@ -216,6 +216,7 @@ when accessing `/foo`, `X-Foo` will have the value `"foo"` and `X-Bar` will not ...@@ -216,6 +216,7 @@ when accessing `/foo`, `X-Foo` will have the value `"foo"` and `X-Bar` will not
### Route Ordering ### Route Ordering
* HTTPS redirect
* Root Files * Root Files
* Clean URLs * Clean URLs
* Proxies * Proxies
......
...@@ -80,19 +80,6 @@ http { ...@@ -80,19 +80,6 @@ http {
} }
<% end %> <% end %>
<% proxies.each do |location, hash| %>
set $<%= hash['name'] %> <%= hash['host'] %>;
location <%= location %> {
rewrite ^<%= location %>/?(.*) <%= hash['path'] %>/$1 break;
proxy_pass $<%= hash['name'] %>;
proxy_ssl_server_name on;
# handle Location rewrites from the proxy properly
<% %w(http https).each do |scheme| %>
proxy_redirect <%= hash["redirect_#{scheme}"] %> <%= location %>;
<% end %>
}
<% end %>
# need this b/c setting $fallback to =404 will try #{root}=404 instead of returning a 404 # need this b/c setting $fallback to =404 will try #{root}=404 instead of returning a 404
location @404 { location @404 {
return 404; return 404;
...@@ -100,6 +87,7 @@ http { ...@@ -100,6 +87,7 @@ http {
# fallback proxy named match # fallback proxy named match
<% proxies.each do |location, hash| %> <% proxies.each do |location, hash| %>
set $<%= hash['name'] %> <%= hash['host'] %>;
location @<%= location %> { location @<%= location %> {
rewrite ^<%= location %>/?(.*)$ <%= hash['path'] %>/$1 break; rewrite ^<%= location %>/?(.*)$ <%= hash['path'] %>/$1 break;
# can reuse variable set above # can reuse variable set above
......
{
"redirects": {
"/old/gone": {
"url": "/",
"status": 302
}
},
"https_only": true
}
...@@ -129,6 +129,16 @@ RSpec.describe "Simple" do ...@@ -129,6 +129,16 @@ RSpec.describe "Simple" do
expect(response["location"]).to eq("http://#{RouterRunner::HOST_IP}/interpolation.html") expect(response["location"]).to eq("http://#{RouterRunner::HOST_IP}/interpolation.html")
end end
end end
context "https_only" do
let(:name) { "redirects_https_only" }
it "should redirect to https first" do
response = app.get("/old/gone")
expect(response.code).to eq("301")
expect(response["location"]).to eq("https://#{RouterRunner::HOST_IP}/old/gone")
end
end
end end
describe "https only" do describe "https only" do
...@@ -259,6 +269,35 @@ STATIC_JSON ...@@ -259,6 +269,35 @@ STATIC_JSON
end end
end end
context "https_only" do
let(:setup_static_json) do
Proc.new do |path|
File.open(static_json_path, "w") do |file|
file.puts <<STATIC_JSON
{
"proxies": {
"/api/": {
"origin": "http://#{@proxy_ip_address}#{path}"
}
},
"https_only": true
}
STATIC_JSON
end
end
end
before do
setup_static_json.call("/")
end
it "should not redirect direct to the proxy" do
response = app.get("/api/bar")
expect(response.code).to eq("301")
expect(response["Location"]).to eq("https://#{RouterRunner::HOST_IP}/api/bar")
end
end
context "env var substitution" do context "env var substitution" do
let(:proxy) do let(:proxy) do
<<CONFIG_RU <<CONFIG_RU
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment