11# frozen_string_literal: true
22
3+ require_relative "../../spec_help/http_test_server"
4+
35class CustomError < StandardError ; end
46
57# rubocop:disable RSpec/MultipleMemoizedHelpers
@@ -533,6 +535,31 @@ class CustomError < StandardError; end
533535 end
534536 end
535537
538+ RSpec . shared_examples "verifies proxy functionality" do
539+ context "when a proxy is provided" do
540+ let ( :proxy_server ) { HttpTestServer . spawn ( "proxy_server" ) }
541+ let ( :target_server ) { HttpTestServer . spawn ( "echoed_headers_in_body" ) }
542+ let ( :client ) do
543+ described_class . new (
544+ base_user_agent : base_user_agent ,
545+ proxy : proxy_server . url
546+ )
547+ end
548+ let ( :url ) { target_server . url }
549+
550+ after do
551+ HttpTestServer . stop ( proxy_server . pid )
552+ HttpTestServer . stop ( target_server . pid )
553+ end
554+
555+ it "routes requests through the proxy" , vcr : false do
556+ with_real_http_connections do
557+ expect ( response . fetch ( :body ) ) . to include ( "HTTP_X_PROXIED_BY" )
558+ end
559+ end
560+ end
561+ end
562+
536563 describe "#initialize" do
537564 context "when no logger is given" do
538565 subject ( :default_logger ) do
@@ -552,6 +579,7 @@ class CustomError < StandardError; end
552579
553580 describe "#post" , vcr : Fixture . post_example_org do
554581 include_examples "common HTTP behaviour for" , :post , "example.org"
582+ include_examples "verifies proxy functionality"
555583
556584 let ( :post_body ) { nil }
557585 let ( :post_headers ) { { } }
@@ -600,6 +628,7 @@ class CustomError < StandardError; end
600628
601629 describe "#get" , vcr : Fixture . example_org do
602630 include_examples "common HTTP behaviour for" , :get , "example.org"
631+ include_examples "verifies proxy functionality"
603632
604633 let ( :request_response ) do
605634 client . get ( url )
@@ -692,6 +721,7 @@ class CustomError < StandardError; end
692721
693722 describe "#put" , vcr : Fixture . put_httpbin_org do
694723 include_examples "common HTTP behaviour for" , :put , "https://httpbin.org/put"
724+ include_examples "verifies proxy functionality"
695725
696726 let ( :url ) { "https://httpbin.org/put" }
697727
@@ -742,6 +772,7 @@ class CustomError < StandardError; end
742772
743773 describe "#patch" , vcr : Fixture . patch_httpbin_org do
744774 include_examples "common HTTP behaviour for" , :patch , "https://httpbin.org/patch"
775+ include_examples "verifies proxy functionality"
745776
746777 let ( :url ) { "https://httpbin.org/patch" }
747778
@@ -792,6 +823,7 @@ class CustomError < StandardError; end
792823
793824 describe "#delete" , vcr : Fixture . delete_httpbin_org do
794825 include_examples "common HTTP behaviour for" , :delete , "https://httpbin.org/delete"
826+ include_examples "verifies proxy functionality"
795827
796828 let ( :url ) { "https://httpbin.org/delete" }
797829
0 commit comments