Skip to content

Commit 2f488ae

Browse files
committed
Force https on /2019
1 parent 945af94 commit 2f488ae

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

config/force_https.conf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if ($http_x_forwarded_proto = "http") {
2+
rewrite ^(.*)$ https://$http_host$1 permanent;
3+
}

config/nginx.conf.erb

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ http {
4545
}
4646

4747
proxy_set_header Host $http_x_rko_host;
48+
proxy_set_header X-Forwarded-Proto $http_x_rko_xfp;
4849
proxy_pass http://localhost:<%= ENV["PORT"] %>;
4950
}
5051
}
@@ -273,6 +274,7 @@ http {
273274
}
274275

275276
location ~ ^/2019(.*) {
277+
include force_https.conf;
276278
proxy_pass http://rubykaigi2019.herokuapp.com;
277279
}
278280

@@ -291,6 +293,7 @@ http {
291293
# current rubykaigi
292294
location = / {
293295
return 302 http://rubykaigi.org/2018;
296+
# return 302 https://rubykaigi.org/2019;
294297
}
295298

296299
location ~* /([0-9][0-9][0-9][0-9])?(images|javascripts|stylehseets)/ {

spec/rubykaigi_org_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,22 @@
162162
end
163163
end
164164

165+
describe "/2019" do
166+
context "https" do
167+
let(:res) { http_get("https://rubykaigi.org/2019") }
168+
it "should be 200" do
169+
expect(res.code).to eq("200")
170+
end
171+
end
172+
173+
context "http" do
174+
let(:res) { http_get("https://rubykaigi.org/2019", proto: 'http') }
175+
it "should force https" do
176+
expect(res.code).to eq("301")
177+
expect(res["location"]).to eq("https://rubykaigi.org/2019")
178+
end
179+
end
180+
end
181+
165182
# TODO consider ja locale case
166183
end

spec/support/http_client.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
require 'uri'
44

55
module Helpers
6-
def http_get(url)
6+
def http_get(url, proto: 'https')
77
uri = URI.parse(url)
88
target = URI.parse(ENV.fetch('TARGET_HOST', url))
99

1010
http = Net::HTTP.new(target.host, target.port)
1111
http.use_ssl = true if target.scheme == 'https'
1212

1313
http.start do
14-
http.get(uri.path, {'x-rko-host' => uri.host, 'Host' => target.host})
14+
headers = {
15+
'Host' => target.host,
16+
'x-rko-host' => uri.host,
17+
'x-rko-xfp' => proto,
18+
}
19+
http.get(uri.path, headers)
1520
end
1621
end
1722
end

0 commit comments

Comments
 (0)