Skip to content
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

Added put, patch and delete request_methods plus tests. #1519

Closed
wants to merge 1 commit into from

Conversation

kalaspuffar
Copy link

Summary:

Added support for request methods with the smallest change possible.

History:

HTTP 1.0 had only support for GET, POST and HEAD.
In June of 1999 HTTP 1.1 added the verbs PUT and DELETE and later in 2010 RFC5789 (https://tools.ietf.org/html/rfc5789) added PATCH.

Pull request explaination:

In this pull request I try to add put, patch and delete with changing as few functions as possible. I simply handle the new verbs as POST. As defined in HTTP 1.1 they are similar in input data requirements and differ only in usage.

Known side effects

Because this PR tries to handle PUT, PATCH and DELETE exactly as POST the php://input stream will be read. So as POST one need to set the enable_post_data_reading to fetch the stream from these requests.


After reading discussion linked by Tyrael where the suggestion below already has been discussed in length I'll remove the suggestion so we could focus on the main part of the PR.
More work I could do is add new globals for $_PUT, $_PATCH and $_DELETE but I think this might be more confusing. Or we could move from $_POST to a new global not tied to a verb. Example $_PARSED_INPUT

Mentioned in bugs

https://bugs.php.net/bug.php?id=55815
https://bugs.php.net/bug.php?id=70331

@Tyrael
Copy link
Member

Tyrael commented Sep 14, 2015

@krakjoe
Copy link
Member

krakjoe commented Jan 1, 2017

@kalaspuffar fix conflicts please

!strcmp(SG(request_info).request_method, "PUT") ||
!strcmp(SG(request_info).request_method, "PATCH") ||
!strcmp(SG(request_info).request_method, "DELETE"))
) {
/* HTTP POST may contain form data to be processed into variables
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment needs minor update, as it only/explicitly mentions POST


save_text($tmp_post, $request);
$cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a lot of duplicated code here.

!strcmp(SG(request_info).request_method, "PUT") ||
!strcmp(SG(request_info).request_method, "PATCH") ||
!strcmp(SG(request_info).request_method, "DELETE")
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed tabs and spaces here.

/* For GET/POST/PUT tests, check if cgi sapi is available and if it is, use it. */
if (!empty($section_text['GET']) || !empty($section_text['POST']) || !empty($section_text['GZIP_POST']) || !empty($section_text['DEFLATE_POST']) || !empty($section_text['POST_RAW']) || !empty($section_text['PUT']) || !empty($section_text['COOKIE']) || !empty($section_text['EXPECTHEADERS'])) {
/* For GET/POST/PUT/PATCH/DELETE tests, check if cgi sapi is available and if it is, use it. */
if (!empty($section_text['GET']) || !empty($section_text['POST']) || !empty($section_text['GZIP_POST']) || !empty($section_text['DEFLATE_POST']) || !empty($section_text['POST_RAW']) || !empty($section_text['PUT']) || !empty($section_text['PATCH']) || !empty($section_text['DELETE']) || !empty($section_text['COOKIE']) || !empty($section_text['EXPECTHEADERS'])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have POST, GZIP_POST, DEFLATE_POST, POST_RAW, why only PUT, PATCH and DELETE? I have no idea what this line does, it's just an inconsistency I saw.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we should add all this test facilities for all request-methods. I would add those only when we actually have tests which require them

@@ -37,7 +37,13 @@ static sapi_post_entry php_post_entries[] = {
*/
SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader)
{
if (!strcmp(SG(request_info).request_method, "POST")) {
if (
!strcmp(SG(request_info).request_method, "POST") ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be && instead of ||?

@@ -1770,6 +1770,10 @@ function run_test($php, $file, $env)
$request .= $line;
}

if (empty($env['CONTENT_TYPE'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a unrelated change in old POST logic?

save_text($tmp_post, $request);
$cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";

} elseif (array_key_exists('DELETE', $section_text) && !empty($section_text['DELETE'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesnt it require a similar branch for PUT?

@staabm
Copy link
Contributor

staabm commented Jan 1, 2017

I am not convinced this is a feature which is really required. Most frameworks abstract away the superglobals as those make testing hard and introduce global dependencies.

As this raw-data is also available via stdin [1], this kind of stuff is easy to handle in userland and should not require php-src level changes IMO.

[1] http://php.net/manual/en/features.file-upload.put-method.php

@krakjoe
Copy link
Member

krakjoe commented Feb 22, 2017

Having waited more than a month for feedback, and having received nothing, I'm closing this PR as it would appear abandoned.

@krakjoe krakjoe closed this Feb 22, 2017
@kalaspuffar
Copy link
Author

@ALL @krakjoe because of all the activity since your post it wasn't clear who should do what or if the conflicts where solved. But if your and the community isn't interested then I'm not going to do the work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants