|
| 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