forked from soveran/cuba
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add assume_ssl plugin for making request ssl? method always return true
- Loading branch information
1 parent
5b5e30b
commit 0848bca
Showing
4 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen-string-literal: true | ||
|
||
# | ||
class Roda | ||
module RodaPlugins | ||
# The assume_ssl plugin makes the request ssl? method always return | ||
# true. This is useful when using an SSL-terminating reverse proxy | ||
# that doesn't set the X-Forwarded-Proto or similar header to notify | ||
# Rack that it is forwarding an SSL request. | ||
# | ||
# The sessions and sinatra_helpers plugins that ship with Roda both | ||
# use the ssl? method internally and can be affected by use of the | ||
# plugin. It's recommended that you use this plugin if you are | ||
# using either plugin and an SSL-terminating proxy as described above. | ||
# | ||
# plugin :assume_ssl | ||
module AssumeSSL | ||
module RequestMethods | ||
# Assume all requests are protected by SSL. | ||
def ssl? | ||
true | ||
end | ||
end | ||
end | ||
|
||
register_plugin(:assume_ssl, AssumeSSL) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require_relative "../spec_helper" | ||
|
||
describe "assume_ssl plugin" do | ||
it "makes r.ssl? always return true" do | ||
app(:assume_ssl) do |r| | ||
r.ssl?.to_s | ||
end | ||
|
||
body.must_equal 'true' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters