Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set X-Forwarded-* headers #29

Merged
merged 1 commit into from
May 8, 2024
Merged

Conversation

3v0k4
Copy link
Contributor

@3v0k4 3v0k4 commented May 6, 2024

Fixes #25

For context, you may want to read:

Manual test:

cd ~/code/thruster
cd cmd/thrust
make build
cd ~/code
rails new myapp
cd myapp
bin/rails g controller home index
mv ../thruster/bin/thrust .
HTTP_PORT=8080 DEBUG=1 ./thrust bin/rails server
class HomeController < ApplicationController
  def index
    puts ["Host", request.headers["Host"]].inspect
    puts ["XFor", request.headers["X-Forwarded-For"]].inspect
    puts ["XHost", request.headers["X-Forwarded-Host"]].inspect
    puts ["XProto", request.headers["X-Forwarded-Proto"]].inspect
    head :ok
  end
end
open http://127.0.0.1:3000/home/index
# ["Host", "127.0.0.1:3000"]
# ["XFor", nil]
# ["XHost", nil]
# ["XProto", nil]


http://127.0.0.1:8080/home/index
# ["Host", "127.0.0.1:8080"]
# ["XFor", "127.0.0.1"]
# ["XHost", "127.0.0.1:8080"]
# ["XProto", "http"]
# config/environments/development.rb
config.hosts << "example.com"
curl -H "Host: example.com" -H "X-Forwarded-For: 1.2.3.4" http://localhost:8080/home/index   
# ["Host", "example.com"]
# ["XFor", "1.2.3.4, 127.0.0.1"]
# ["XHost", "example.com"]
# ["XProto", "http"]

@3v0k4 3v0k4 marked this pull request as ready for review May 7, 2024 09:23
@kevinmcconnell
Copy link
Collaborator

This looks perfect, @3v0k4! Thanks again for tackling it! 🙏

@kevinmcconnell kevinmcconnell merged commit ec8c5f6 into basecamp:main May 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rails.config.force_ssl causes infinite redirect
2 participants