discourse/spec/requests/net_http_header_spec.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

15 lines
480 B
Ruby

# frozen_string_literal: true
# We can use the redeliver event to test the user-agent header
RSpec.describe "Net::HTTPHeader sets a default user-agent" do
it "should set a user-agent when none has been set" do
get "/test_net_http_headers.json"
expect(response).to have_http_status(:success)
parsed_body = JSON.parse(response.body)
expect(parsed_body).to have_key("user-agent")
expect(parsed_body["user-agent"].first).to eq(Discourse.user_agent)
end
end