@@ -289,6 +289,58 @@ def test_response_as_struct
289289 assert_equal ( "nested_value" , response . body . key . nested_key )
290290 end
291291
292+ def test_rewrites_my_shop_dev_host_headers_when_present
293+ @success_body = { }
294+ shop = "test-shop.my.shop.dev"
295+ session = ShopifyAPI ::Auth ::Session . new ( shop :, access_token : @token )
296+
297+ expected_headers = @expected_headers . dup
298+ expected_headers [ "Host" ] = "app.shop.dev"
299+ expected_headers [ "x-forwarded-host" ] = shop
300+
301+ stub_request ( @request . http_method , "https://#{ shop } #{ @base_path } /#{ @request . path } " )
302+ . with ( body : @request . body . to_json , query : @request . query , headers : expected_headers )
303+ . to_return ( body : "" , headers : @response_headers , status : 204 )
304+
305+ @client = ShopifyAPI ::Clients ::HttpClient . new ( session :, base_path : @base_path )
306+ @request = ShopifyAPI ::Clients ::HttpRequest . new (
307+ http_method : :post ,
308+ path : "some-path" ,
309+ body : { foo : "bar" } ,
310+ body_type : "application/json" ,
311+ query : { id : 1234 } ,
312+ extra_headers : { extra : "header" , "Host" => shop } ,
313+ )
314+
315+ verify_http_request
316+ end
317+
318+ def test_appends_host_headers_for_my_shop_dev_request_url
319+ @success_body = { }
320+ shop = "test-shop.my.shop.dev"
321+ session = ShopifyAPI ::Auth ::Session . new ( shop :, access_token : @token )
322+
323+ expected_headers = @expected_headers . dup
324+ expected_headers [ "Host" ] = "app.shop.dev"
325+ expected_headers [ "x-forwarded-host" ] = shop
326+
327+ stub_request ( @request . http_method , "https://#{ shop } #{ @base_path } /#{ @request . path } " )
328+ . with ( body : @request . body . to_json , query : @request . query , headers : expected_headers )
329+ . to_return ( body : "" , headers : @response_headers , status : 204 )
330+
331+ @client = ShopifyAPI ::Clients ::HttpClient . new ( session :, base_path : @base_path )
332+ @request = ShopifyAPI ::Clients ::HttpRequest . new (
333+ http_method : :post ,
334+ path : "some-path" ,
335+ body : { foo : "bar" } ,
336+ body_type : "application/json" ,
337+ query : { id : 1234 } ,
338+ extra_headers : { extra : "header" } ,
339+ )
340+
341+ verify_http_request
342+ end
343+
292344 private
293345
294346 def simple_http_test ( http_method )
0 commit comments