Skip to content

gzopen() does not use the default stream context when opening HTTP URLs #16883

@TimWolla

Description

@TimWolla

Description

The following code:

<?php
stream_context_set_default([
	'http' => array(
		'user_agent' => 'dummy',
	)
]);

$f = fopen("http://example.com", 'r');
var_dump(stream_get_contents($f));

$f = gzopen("http://example.com", 'r');
var_dump(stream_get_contents($f));

Resulted in these HTTP requests being sent:

sendto(4, "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\nUser-Agent: dummy\r\n\r\n", 75, MSG_DONTWAIT, NULL, 0) = 75
[…]
sendto(5, "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n", 56, MSG_DONTWAIT, NULL, 0) = 56

But I expected these HTTP requests to be sent:

sendto(4, "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\nUser-Agent: dummy\r\n\r\n", 75, MSG_DONTWAIT, NULL, 0) = 75
[…]
sendto(5, "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\nUser-Agent: dummy\r\n\r\n", 75, MSG_DONTWAIT, NULL, 0) = 75

The user-agent is missing from the gzopen() call.

PHP Version

PHP 8.3.13

Operating System

Ubuntu 24.04

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