whiplash-app 0.9.0 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/whiplash/app/canonical_host.rb +25 -0
- data/lib/whiplash/app/railtie.rb +14 -0
- data/lib/whiplash/app/version.rb +1 -1
- data/lib/whiplash/app.rb +27 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90618c9787cb8660f4fcb0be146bdb14736ce8635274f9b262f68813268bd35d
|
4
|
+
data.tar.gz: a26cca38e01f5c5642b94afe39cbc0be6ea08f05c9ccf446d0d802e5548aa100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d67a3f4a633319407cb8dd9a6717a92b57480825dab3fa36b4e77fda280f58c16089aa833a39fade900dee77efeaa169b868e3ba5f0e25832e37105da40ad53b
|
7
|
+
data.tar.gz: 94df31ed65be70e565fb5ea8ba2744dbfbbfe386500d8ae5c57bce4bd72474ff0af70f4ea9620e02f2a108282d24821c6477b0107d0b55146249c690010f8d07
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Whiplash
|
3
|
+
class App
|
4
|
+
module CanonicalHost
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def require_canonical_host!
|
10
|
+
canonical_host = ENV.fetch('CANONICAL_HOST', false).in?([true, 'true', 1, '1'])
|
11
|
+
return unless canonical_host
|
12
|
+
application_host = URI.parse(Rails.configuration.app_url).host
|
13
|
+
return if application_host == request.host
|
14
|
+
return unless request.method_symbol == :get # can't redirect PUT, POST, DELETE
|
15
|
+
|
16
|
+
redirect_to_canonical_host request.query_parameters
|
17
|
+
end
|
18
|
+
|
19
|
+
def redirect_to_canonical_host(query_params, status=301)
|
20
|
+
redirect_to "#{Rails.configuration.app_url}#{request.path}#{'?' if query_params.to_query.present?}#{query_params.to_query}", status: status
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Whiplash
|
4
|
+
module Logs
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
initializer "whiplash_app.action_controller" do
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
puts "Extending #{self} with YourGemsModuleName::Controller"
|
9
|
+
include Whiplash::App::CanonicalHost
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/whiplash/app/version.rb
CHANGED
data/lib/whiplash/app.rb
CHANGED
@@ -7,6 +7,12 @@ require "errors/whiplash_api_error"
|
|
7
7
|
require "oauth2"
|
8
8
|
require "faraday"
|
9
9
|
|
10
|
+
# Rails app stuff
|
11
|
+
if defined?(Rails::Railtie)
|
12
|
+
require "whiplash/app/canonical_host"
|
13
|
+
require "whiplash/app/railtie"
|
14
|
+
end
|
15
|
+
|
10
16
|
module Whiplash
|
11
17
|
class App
|
12
18
|
include Whiplash::App::ApiConfig
|
@@ -78,3 +84,24 @@ module Whiplash
|
|
78
84
|
|
79
85
|
end
|
80
86
|
end
|
87
|
+
|
88
|
+
module Net
|
89
|
+
class HTTPResponse
|
90
|
+
class << self
|
91
|
+
private
|
92
|
+
|
93
|
+
def read_status_line(sock)
|
94
|
+
str = sock.readline
|
95
|
+
og = str.dup
|
96
|
+
str.gsub!(/.*?(?=HTTP)/im, "")
|
97
|
+
if og.size > str.size
|
98
|
+
Rails.logger.warn "[WhiplashApp] Failed to read header status for #{og.inspect}"
|
99
|
+
end
|
100
|
+
m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?\z/in.match(str) or
|
101
|
+
raise Net::HTTPBadResponse, "wrong status line: #{str.dump}"
|
102
|
+
m.captures
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whiplash-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Don Sullivan, Mark Dickson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -115,8 +115,10 @@ files:
|
|
115
115
|
- lib/errors/whiplash_api_error.rb
|
116
116
|
- lib/whiplash/app.rb
|
117
117
|
- lib/whiplash/app/api_config.rb
|
118
|
+
- lib/whiplash/app/canonical_host.rb
|
118
119
|
- lib/whiplash/app/connections.rb
|
119
120
|
- lib/whiplash/app/finder_methods.rb
|
121
|
+
- lib/whiplash/app/railtie.rb
|
120
122
|
- lib/whiplash/app/signing.rb
|
121
123
|
- lib/whiplash/app/version.rb
|
122
124
|
- whiplash-app.gemspec
|