Files
discourse/app/controllers/test_requests_controller.rb
Gary Pendergast 8615fc6cbb DEV: Add a user agent to all HTTP requests that Discourse makes. (#31555)
This change standardises the `User-Agent` header that Discourse will send when talking to other sites.

`Discourse.user_agent` is now the authority on what the user agent value should be. For Onebox requests, this changes the user agent from their existing value to match the new value (unless overridden).

For all other requests, `Net::HTTPHeader` is monkey-patched to add a default `User-Agent` header when one hasn't been provided.
2025-03-03 16:32:25 +11:00

24 lines
690 B
Ruby

# frozen_string_literal: true
# This controller's actions are only available in the test environment to help with more complex testing requirements
class TestRequestsController < ApplicationController
if Rails.env.test?
def test_net_http_timeouts
net_http = Net::HTTP.new("example.com")
render json: {
open_timeout: net_http.open_timeout,
read_timeout: net_http.read_timeout,
write_timeout: net_http.write_timeout,
max_retries: net_http.max_retries,
}
end
def test_net_http_headers
net_http_get = Net::HTTP::Get.new("example.com")
render json: net_http_get
end
end
end