Skip to content

Commit 4ebd9a5

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
2 parents 11740ab + 5f8c22d commit 4ebd9a5

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed

ext/soap/php_http.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,15 +617,34 @@ int make_http_soap_request(zval *this_ptr,
617617
smart_str_append_smart_str(&soap_headers, &soap_headers_z);
618618

619619
if (soap_version == SOAP_1_2) {
620-
smart_str_append_const(&soap_headers,"Content-Type: application/soap+xml; charset=utf-8");
620+
if (context &&
621+
(tmp = php_stream_context_get_option(context, "http", "content_type")) != NULL &&
622+
Z_TYPE_P(tmp) == IS_STRING &&
623+
Z_STRLEN_P(tmp) > 0
624+
) {
625+
smart_str_append_const(&soap_headers, "Content-Type: ");
626+
smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
627+
} else {
628+
smart_str_append_const(&soap_headers, "Content-Type: application/soap+xml; charset=utf-8");
629+
}
621630
if (soapaction) {
622631
smart_str_append_const(&soap_headers,"; action=\"");
623632
smart_str_appends(&soap_headers, soapaction);
624633
smart_str_append_const(&soap_headers,"\"");
625634
}
626635
smart_str_append_const(&soap_headers,"\r\n");
627636
} else {
628-
smart_str_append_const(&soap_headers,"Content-Type: text/xml; charset=utf-8\r\n");
637+
if (context &&
638+
(tmp = php_stream_context_get_option(context, "http", "content_type")) != NULL &&
639+
Z_TYPE_P(tmp) == IS_STRING &&
640+
Z_STRLEN_P(tmp) > 0
641+
) {
642+
smart_str_append_const(&soap_headers, "Content-Type: ");
643+
smart_str_appendl(&soap_headers, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
644+
smart_str_append_const(&soap_headers, "\r\n");
645+
} else {
646+
smart_str_append_const(&soap_headers, "Content-Type: text/xml; charset=utf-8\r\n");
647+
}
629648
if (soapaction) {
630649
smart_str_append_const(&soap_headers, "SOAPAction: \"");
631650
smart_str_appends(&soap_headers, soapaction);
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
--TEST--
2+
SOAP customized Content-Type, eg. SwA use case
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
7+
if (!file_exists(__DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc")) {
8+
echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
9+
}
10+
?>
11+
--FILE--
12+
<?php
13+
14+
include __DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc";
15+
16+
$args = substr(PHP_OS, 0, 3) == 'WIN' ? "-d extension_dir=" . ini_get("extension_dir") . " -d extension=php_soap.dll" : "";
17+
$code = <<<'PHP'
18+
/* Receive */
19+
$content = trim(file_get_contents("php://input")) . PHP_EOL;
20+
PHP;
21+
22+
php_cli_server_start($code, false, $args);
23+
24+
$client = new soapclient(NULL, [
25+
'location' => 'http://' . PHP_CLI_SERVER_ADDRESS,
26+
'uri' => 'misc-uri',
27+
'soap_version' => SOAP_1_2,
28+
'user_agent' => 'Vincent JARDIN, test headers',
29+
'trace' => true, /* record the headers before sending */
30+
'stream_context' => stream_context_create([
31+
'http' => [
32+
'header' => sprintf("MIME-Version: 1.0\r\n"),
33+
'content_type' => sprintf("Multipart/Related")
34+
],
35+
]),
36+
]);
37+
38+
$client->__soapCall("foo", [ 'arg1' => "XXXbar"]);
39+
40+
$headers = $client->__getLastRequestHeaders();
41+
42+
if (strpos($headers, 'Multipart/Related; action="misc-uri#foo"') === FALSE)
43+
printf("Content-Type NOK %s" . PHP_EOL, $headers);
44+
else
45+
printf("Content-Type OK" . PHP_EOL);
46+
47+
/*
48+
* In case of an empty content-type, let's fallback to the default content.
49+
*/
50+
$client2 = new soapclient(NULL, [
51+
'location' => 'http://' . PHP_CLI_SERVER_ADDRESS,
52+
'uri' => 'misc-uri',
53+
'soap_version' => SOAP_1_2,
54+
'user_agent' => 'Vincent JARDIN, test headers',
55+
'trace' => true, /* record the headers before sending */
56+
'stream_context' => stream_context_create([
57+
'http' => [
58+
'header' => sprintf("MIME-Version: 1.0\r\n"),
59+
'content_type' => sprintf("")
60+
],
61+
]),
62+
]);
63+
64+
$client2->__soapCall("foo", [ 'arg1' => "XXXbar"]);
65+
66+
$headers = $client2->__getLastRequestHeaders();
67+
68+
if (strpos($headers, 'Content-Type: application/soap+xml; charset=utf-8; action="misc-uri#foo"') === FALSE)
69+
printf("Content-Type Default NOK %s" . PHP_EOL, $headers);
70+
else
71+
printf("Content-Type Default OK" . PHP_EOL);
72+
?>
73+
==DONE==
74+
--EXPECT--
75+
Content-Type OK
76+
Content-Type Default OK
77+
==DONE==

0 commit comments

Comments
 (0)