-
Notifications
You must be signed in to change notification settings - Fork 8.1k
sapi/cli: support Expect 100-continue in PHP dev server #23245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sjord
wants to merge
4
commits into
php:master
Choose a base branch
from
Sjord:cli-server-expect-100-continue
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+137
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
sapi/cli/tests/php_cli_server_expect_100_continue_curl.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| --TEST-- | ||
| Expect 100-continue behavior in PHP development server (curl) | ||
| --SKIPIF-- | ||
| <?php | ||
| include "skipif.inc"; | ||
| ?> | ||
| --EXTENSIONS-- | ||
| curl | ||
| --FILE-- | ||
| <?php | ||
| include 'php_cli_server.inc'; | ||
| $server = php_cli_server_start(); | ||
|
|
||
| // Generate a POST body larger than 1MB to trigger Expect: 100-continue | ||
| $body = str_repeat('A', 1024 * 1024 + 1); | ||
|
|
||
| $ch = curl_init(); | ||
| curl_setopt($ch, CURLOPT_URL, PHP_CLI_SERVER_ADDRESS); | ||
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
| curl_setopt($ch, CURLOPT_POSTFIELDS, $body); | ||
|
|
||
| // Set a high timeout for 100-continue response | ||
| curl_setopt($ch, CURLOPT_EXPECT_100_TIMEOUT_MS, 2000); | ||
|
|
||
| curl_exec($ch); | ||
| var_dump(curl_errno($ch)); | ||
|
|
||
| echo "Did the PHP development server send a HTTP/1.1 100 Continue header?\n"; | ||
| $start_transfer_time = curl_getinfo($ch, CURLINFO_STARTTRANSFER_TIME_T); | ||
| var_dump($start_transfer_time < 1_000_000); | ||
| ?> | ||
| --EXPECT-- | ||
| int(0) | ||
| Did the PHP development server send a HTTP/1.1 100 Continue header? | ||
| bool(true) | ||
74 changes: 74 additions & 0 deletions
74
sapi/cli/tests/php_cli_server_expect_100_continue_socket.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --TEST-- | ||
| Expect 100-continue behavior in PHP development server (sockets) | ||
| --SKIPIF-- | ||
| <?php | ||
| include "skipif.inc"; | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
| include "php_cli_server.inc"; | ||
| php_cli_server_start(); | ||
|
|
||
| echo "# Send Expect: 100-continue header, receive 100 Continue response.\n"; | ||
| $fp = php_cli_server_connect(); | ||
| fwrite($fp, "POST / HTTP/1.1\r\nExpect: 100-continue\r\nContent-Length: 4\r\nConnection: close\r\n\r\n"); | ||
| echo fgets($fp); | ||
| echo fgets($fp); | ||
| fwrite($fp, "body"); | ||
| echo fgets($fp); | ||
| fclose($fp); | ||
|
|
||
| echo "# Send Expect: 100-continue header and disconnect.\n"; | ||
| $fp = php_cli_server_connect(); | ||
| if (extension_loaded('sockets')) { | ||
| // Set SO_LINGER timeout to zero so that send fails on the server immediately | ||
| socket_set_option( | ||
| socket_import_stream($fp), | ||
| SOL_SOCKET, | ||
| SO_LINGER, | ||
| [ | ||
| 'l_onoff' => 1, | ||
| 'l_linger' => 0, | ||
| ] | ||
| ); | ||
| } | ||
| stream_socket_shutdown($fp, STREAM_SHUT_RD); | ||
| fwrite($fp, "POST / HTTP/1.1\r\nExpect: 100-continue\r\nContent-Length: 4\r\nConnection: close\r\n\r\n"); | ||
| fclose($fp); | ||
|
|
||
| $fp = php_cli_server_connect(); | ||
| fwrite($fp, "GET / HTTP/1.1\r\nConnection: close\r\n\r\n"); | ||
| echo fgets($fp); | ||
| fclose($fp); | ||
|
|
||
| echo "# GET with Expect header (no body).\n"; | ||
| $fp = php_cli_server_connect(); | ||
| fwrite($fp, "GET / HTTP/1.1\r\nExpect: 100-continue\r\nConnection: close\r\n\r\n"); | ||
| echo fgets($fp); | ||
| fclose($fp); | ||
|
|
||
| echo "# POST with empty body.\n"; | ||
| $fp = php_cli_server_connect(); | ||
| fwrite($fp, "POST / HTTP/1.1\r\nExpect: 100-continue\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"); | ||
| echo fgets($fp); | ||
| fclose($fp); | ||
|
|
||
| echo "# Lower-case expect header.\n"; | ||
| $fp = php_cli_server_connect(); | ||
| fwrite($fp, "POST / HTTP/1.1\r\nexpect: 100-continue\r\nContent-Length: 4\r\nConnection: close\r\n\r\n"); | ||
| echo fgets($fp); | ||
| fclose($fp); | ||
| ?> | ||
| --EXPECT-- | ||
| # Send Expect: 100-continue header, receive 100 Continue response. | ||
| HTTP/1.1 100 Continue | ||
|
|
||
| HTTP/1.1 200 OK | ||
| # Send Expect: 100-continue header and disconnect. | ||
| HTTP/1.1 200 OK | ||
| # GET with Expect header (no body). | ||
| HTTP/1.1 200 OK | ||
| # POST with empty body. | ||
| HTTP/1.1 200 OK | ||
| # Lower-case expect header. | ||
| HTTP/1.1 100 Continue |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.