Skip to content

Commit

Permalink
Override host
Browse files Browse the repository at this point in the history
  • Loading branch information
hack3rvaillant committed Oct 31, 2024
1 parent 44cccfc commit 50929a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

ruby "3.3.5"

source "https://rubygems.org"

gem "jwt", "~> 2.9"
Expand Down
19 changes: 13 additions & 6 deletions proxy_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
require "uri"
require "json"
require "jwt"
require "debug"
require "dotenv/load"
require "openssl/pkey"

if ["development", "test"].include? ENV['RACK_ENV']
require "dotenv/load"
require "debug"
end

class ProxyServer < Sinatra::Base
set :port, 4567
# set :logging, true
Expand Down Expand Up @@ -75,11 +78,15 @@ def forward_request(method)
target_request.body = request.body.read
end

# Override host
target_request["host"] = uri.hostname

# Log the headers for debugging purposes
puts "Forwarding headers to target request:"
target_request.each_header do |header, value|
puts "#{header}: #{value}"
end
# puts "Forwarding headers to target request:"
# target_request.each_header do |header, value|
# puts "#{header}: #{value}"
# end

# Execute the request to the target server
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
response = http.request(target_request)
Expand Down

0 comments on commit 50929a3

Please sign in to comment.