Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
heroku-buildpack-static
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Python-Dev
heroku-buildpack-static
Commits
fb0a4954
Commit
fb0a4954
authored
Mar 15, 2017
by
Terence Lee
Committed by
GitHub
Mar 15, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #61 from heroku/proxy_redirect
handle proxy redirects even if the scheme doesn't match
parents
a2e3a022
7ff0ea22
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
2 deletions
+32
-2
nginx_config.rb
scripts/config/lib/nginx_config.rb
+3
-0
nginx.conf.erb
scripts/config/templates/nginx.conf.erb
+4
-0
simple_spec.rb
spec/simple_spec.rb
+25
-2
No files found.
scripts/config/lib/nginx_config.rb
View file @
fb0a4954
...
@@ -29,6 +29,9 @@ class NginxConfig
...
@@ -29,6 +29,9 @@ class NginxConfig
json
[
"proxies"
][
loc
][
"path"
]
=
uri
.
path
json
[
"proxies"
][
loc
][
"path"
]
=
uri
.
path
uri
.
path
=
""
uri
.
path
=
""
json
[
"proxies"
][
loc
][
"host"
]
=
uri
.
to_s
json
[
"proxies"
][
loc
][
"host"
]
=
uri
.
to_s
redirect_scheme
=
uri
.
scheme
==
"https"
?
"http"
:
"https"
json
[
"proxies"
][
loc
][
"redirect"
]
=
uri
.
dup
.
tap
{
|
u
|
u
.
scheme
=
redirect_scheme
}.
to_s
json
[
"proxies"
][
loc
][
"redirect"
]
+=
"/"
if
!
uri
.
to_s
.
end_with?
(
"/"
)
end
end
json
[
"clean_urls"
]
||=
DEFAULT
[
:clean_urls
]
json
[
"clean_urls"
]
||=
DEFAULT
[
:clean_urls
]
...
...
scripts/config/templates/nginx.conf.erb
View file @
fb0a4954
...
@@ -81,6 +81,8 @@ http {
...
@@ -81,6 +81,8 @@ http {
location
<%=
location
%>
{
location
<%=
location
%>
{
proxy_pass
<%=
hash
[
'origin'
]
%>
;
proxy_pass
<%=
hash
[
'origin'
]
%>
;
proxy_ssl_server_name on;
proxy_ssl_server_name on;
proxy_redirect default;
proxy_redirect
<%=
hash
[
"redirect"
]
%>
<%=
location
%>
;
}
}
<%
end
%>
<%
end
%>
...
@@ -95,6 +97,8 @@ http {
...
@@ -95,6 +97,8 @@ http {
rewrite ^
<%=
location
%>
(.*)$
<%=
hash
[
'path'
]
%>
/$1 break;
rewrite ^
<%=
location
%>
(.*)$
<%=
hash
[
'path'
]
%>
/$1 break;
proxy_pass
<%=
hash
[
'host'
]
%>
;
proxy_pass
<%=
hash
[
'host'
]
%>
;
proxy_ssl_server_name on;
proxy_ssl_server_name on;
proxy_redirect default;
proxy_redirect
<%=
hash
[
"redirect"
]
%>
<%=
location
%>
;
}
}
<%
end
%>
<%
end
%>
...
...
spec/simple_spec.rb
View file @
fb0a4954
...
@@ -383,6 +383,7 @@ STATIC_JSON
...
@@ -383,6 +383,7 @@ STATIC_JSON
include
PathHelper
include
PathHelper
let
(
:name
)
{
"proxies"
}
let
(
:name
)
{
"proxies"
}
let
(
:proxy_scheme
)
{
"http"
}
let
(
:static_json_path
)
{
fixtures_path
(
"proxies/static.json"
)
}
let
(
:static_json_path
)
{
fixtures_path
(
"proxies/static.json"
)
}
let
(
:proxy
)
do
let
(
:proxy
)
do
<<
PROXY
<<
PROXY
...
@@ -393,6 +394,16 @@ end
...
@@ -393,6 +394,16 @@ end
get "/foo/baz/" do
get "/foo/baz/" do
"baz"
"baz"
end
end
get "/foo/http_redirect/" do
uri = URI("http://
\#
{request.host}/foo/redirect")
redirect URI(uri), 307
end
get "/foo/https_redirect/" do
uri = URI("https://
\#
{request.host}/foo/redirect")
redirect URI(uri), 307
end
PROXY
PROXY
end
end
let
(
:setup_static_json
)
do
let
(
:setup_static_json
)
do
...
@@ -402,7 +413,7 @@ PROXY
...
@@ -402,7 +413,7 @@ PROXY
{
{
"proxies": {
"proxies": {
"/api/": {
"/api/": {
"origin": "
http
://
#{
@proxy_ip_address
}#{
path
}
"
"origin": "
#{
proxy_scheme
}
://
#{
@proxy_ip_address
}#{
path
}
"
}
}
},
},
"headers": {
"headers": {
...
@@ -419,7 +430,7 @@ STATIC_JSON
...
@@ -419,7 +430,7 @@ STATIC_JSON
before
do
before
do
@proxy_ip_address
=
app
.
proxy
.
ip_address
@proxy_ip_address
=
app
.
proxy
.
ip_address
setup_static_json
.
call
(
"/foo
/
"
)
setup_static_json
.
call
(
"/foo"
)
end
end
after
do
after
do
...
@@ -439,6 +450,18 @@ STATIC_JSON
...
@@ -439,6 +450,18 @@ STATIC_JSON
expect
(
response
[
"X-Header"
]).
to
be_nil
expect
(
response
[
"X-Header"
]).
to
be_nil
end
end
end
end
it
"should hanadle redirects regardless of scheme"
do
app
.
run
do
response
=
app
.
get
(
"/api/http_redirect/"
)
expect
(
response
.
code
).
to
eq
(
"307"
)
expect
(
response
[
"Location"
]).
not_to
include
(
@proxy_ip_address
)
response
=
app
.
get
(
"/api/https_redirect/"
)
expect
(
response
.
code
).
to
eq
(
"307"
)
expect
(
response
[
"Location"
]).
not_to
include
(
@proxy_ip_address
)
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment