-
-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathforward_host.rb
More file actions
27 lines (21 loc) · 790 Bytes
/
Copy pathforward_host.rb
File metadata and controls
27 lines (21 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true
class ForwardHost < Rack::Proxy
def rewrite_env(env)
env["HTTP_HOST"] = "example.com"
env
end
def rewrite_response(triplet)
_, headers, _ = triplet
# example of inserting an additional header
headers["X-Foo"] = "Bar"
# if you rewrite env, it appears that content-length isn't calculated correctly
# resulting in only partial responses being sent to users
# you can remove it or recalculate it here
headers["content-length"] = nil
triplet
end
end
# Only wire into the middleware stack when running inside a booted Rails app.
if defined?(Rails) && Rails.respond_to?(:application) && Rails.application
Rails.application.config.middleware.use ForwardHost, backend: "http://example.com", streaming: false
end