Skip to content

[HttpClient] Unable to set $info['redirect_url'] via MockResponse #59324

Open
@defunctl

Description

@defunctl

Symfony version(s) affected

5.x+

Description

Setting 'redirect_url' => 'http://www.mysite.test/final/' as part of the $info array in a MockResponse results in:

Symfony\Component\HttpClient\Exception\TransportException] The response factory iterator passed to MockHttpClient is empty.  
$responses = [
	new MockResponse(
		'',
		[
			'http_code'        => 301,
			'redirect_url'     => 'http://www.mysite.test/final/',
			'response_headers' => [
				'HTTP/2 301 ',
				'location: http://www.mysite.test/final/',
			],
		]
	),
];

It seems to be force info['redirect_url'] to null here.

How to reproduce

I am using a decorator in my code, but this PHPUnit test should fail regardless:

$responses = [
	new MockResponse(
		'',
		[
			'http_code'        => 301,
			'redirect_url'     => 'http://www.mysite.test/final/',
			'response_headers' => [
				'HTTP/2 301 ',
				'location: http://www.mysite.test/final/',
			],
		]
	),
];

$this->http_client->setResponseFactory( $responses );

try {
	$response = $this->client->request( 'GET', '/redirect/' );

	$response->getHeaders();

	$this->fail( 'A RedirectionException should have been thrown' );
} catch ( RedirectionExceptionInterface $e ) {
	$info = $e->getResponse()->getInfo();

	$this->assertSame( 'http://www.mysite.test/final/', $info['redirect_url'] );
}

Possible Solution

Either allow us to set $info['redirect_url'] on MockResponse, or it should populate it automatically based on the response_headers?

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy