]> granicus.if.org Git - php/commitdiff
Merged GitHub PR #190: Support for the HTTP PATCH method in CLI webserver
authorLars Strojny <lstrojny@php.net>
Tue, 18 Sep 2012 20:16:51 +0000 (22:16 +0200)
committerLars Strojny <lstrojny@php.net>
Tue, 18 Sep 2012 20:16:51 +0000 (22:16 +0200)
NEWS
sapi/cli/php_http_parser.c
sapi/cli/php_http_parser.h
sapi/cli/tests/php_cli_server_018.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 339d6814c0fcc07c45cc6c3b87f7f28c3c490408..e769b356a60458c648c0fae7b11860263c6384fd 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ PHP                                                                        NEWS
 - CLI server:
   . Changed response to unknown HTTP method to 501 according to RFC.
     (Niklas Lindgren).
+  . Support HTTP PATCH method. Patch by Niklas Lindgren, GitHub PR #190.
+    (Lars)
 
 - Core:
   . Added optional second argument for assert() to specify custom message. Patch
index 4a95f8257546ee1933e609bef7d21201e30eab20..d3bc496f4e3dd9afe8d6af653d2c31a4f6699871 100644 (file)
@@ -81,6 +81,7 @@ static const char *method_strings[] =
   , "HEAD"
   , "POST"
   , "PUT"
+  , "PATCH"
   , "CONNECT"
   , "OPTIONS"
   , "TRACE"
@@ -627,6 +628,8 @@ size_t php_http_parser_execute (php_http_parser *parser,
           parser->method = PHP_HTTP_PROPFIND; /* or HTTP_PROPPATCH */
         } else if (index == 1 && parser->method == PHP_HTTP_POST && ch == 'U') {
           parser->method = PHP_HTTP_PUT;
+        } else if (index == 1 && parser->method == PHP_HTTP_POST && ch == 'A') {
+          parser->method = PHP_HTTP_PATCH;
         } else if (index == 2 && parser->method == PHP_HTTP_UNLOCK && ch == 'S') {
           parser->method = PHP_HTTP_UNSUBSCRIBE;
         } else if (index == 4 && parser->method == PHP_HTTP_PROPFIND && ch == 'P') {
index 0f6c13dd354fb124b3ca6f6901ccaf6427b4ced1..2bf2356725a29f1abd58034edc208a1d1a37cf9a 100644 (file)
@@ -80,6 +80,7 @@ enum php_http_method
   , PHP_HTTP_HEAD
   , PHP_HTTP_POST
   , PHP_HTTP_PUT
+  , PHP_HTTP_PATCH
   /* pathological */
   , PHP_HTTP_CONNECT
   , PHP_HTTP_OPTIONS
diff --git a/sapi/cli/tests/php_cli_server_018.phpt b/sapi/cli/tests/php_cli_server_018.phpt
new file mode 100644 (file)
index 0000000..deb9348
--- /dev/null
@@ -0,0 +1,44 @@
+--TEST--
+Implement Req #61679 (Support HTTP PATCH method)
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+include "php_cli_server.inc";
+php_cli_server_start(<<<'PHP'
+var_dump($_SERVER['REQUEST_METHOD']);
+PHP
+);
+
+list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
+$port = intval($port)?:80;
+
+$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
+if (!$fp) {
+  die("connect failed");
+}
+
+if(fwrite($fp, <<<HEADER
+PATCH / HTTP/1.1
+Host: {$host}
+
+
+HEADER
+)) {
+    while (!feof($fp)) {
+        echo fgets($fp);
+    }
+}
+
+fclose($fp);
+?>
+--EXPECTF--
+HTTP/1.1 200 OK
+Host: %s
+Connection: close
+X-Powered-By: %s
+Content-type: text/html
+
+string(5) "PATCH"