add http parser document. and fix constnats [ci skip]

This commit is contained in:
Shuhei Tanuma 2012-07-15 20:45:34 +09:00
parent 091eef8a6b
commit 2454e91bda
3 changed files with 182 additions and 4 deletions

View File

@ -857,7 +857,95 @@ TODO:
### resource uv_http_parser_init(long $target = UV::HTTP_REQUEST)
##### *Description*
initialize http parser.
##### *Parameters*
*long $target*: this expects UV::HTTP_REQUEST, UV::HTTP_RESPONSE or UV::HTTP_BOTH.
##### *Return Value*
*resource uv_http*:
##### *Example*
````php
<?php
$parser = uv_http_parser_init(UV::HTTP_REQUEST);
````
### bool uv_http_parser_execute(resource $parser, string $body, array &$result)
##### *Description*
execute http parser.
##### *Parameters*
*resource $parser*: uv_http_parser resoruce.
*string $body*: http message.
*array &$result*: result array.
##### *Return Value*
*bool finished*: this parser returns false when specified http message is invalid or not enough message.
##### *Example*
````php
<?php
$parser = uv_http_parser_init(UV::HTTP_REQUEST);
if (uv_http_parser_execute($parser, "GET /img/http-parser.png?key=value#frag HTTP/1.1
Host: chobie.net
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Gecko/20100101 Firefox/12.0
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://chobie.net/
Cookie: key=value
Cache-Control: max-age=0
",$result)) {
var_dump($result);
//array(6) {
// ["headers"]=>
// array(8) {
// ["Host"]=>
// string(10) "chobie.net"
// ["User-Agent"]=>
// string(81) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Gecko/20100101 Firefox/12.0"
// ["Accept-Language"]=>
// string(14) "en-us,en;q=0.5"
// ["Accept-Encoding"]=>
// string(13) "gzip, deflate"
// ["Connection"]=>
// string(10) "keep-alive"
// ["Referer"]=>
// string(18) "http://chobie.net/"
// ["Cookie"]=>
// string(9) "key=value"
// ["Cache-Control"]=>
// string(9) "max-age=0"
// }
// ["QUERY_STRING"]=>
// string(35) "/img/http-parser.png?key=value#frag"
// ["path"]=>
// string(20) "/img/http-parser.png"
// ["query"]=>
// string(9) "key=value"
// ["fragment"]=>
// string(4) "frag"
// ["REQUEST_METHOD"]=>
// string(3) "GET"
//}
}
````

View File

@ -6273,6 +6273,25 @@ ZEND_END_ARG_INFO()
/* {{{ proto resource uv_http_parser_init(long $target = UV::HTTP_REQUEST)
##### *Description*
initialize http parser.
##### *Parameters*
*long $target*: this expects UV::HTTP_REQUEST, UV::HTTP_RESPONSE or UV::HTTP_BOTH.
##### *Return Value*
*resource uv_http*:
##### *Example*
````php
<?php
$parser = uv_http_parser_init(UV::HTTP_REQUEST);
````
*/
PHP_FUNCTION(uv_http_parser_init)
{
@ -6309,6 +6328,77 @@ PHP_FUNCTION(uv_http_parser_init)
}
/* {{{ proto bool uv_http_parser_execute(resource $parser, string $body, array &$result)
##### *Description*
execute http parser.
##### *Parameters*
*resource $parser*: uv_http_parser resoruce.
*string $body*: http message.
*array &$result*: result array.
##### *Return Value*
*bool finished*: this parser returns false when specified http message is invalid or not enough message.
##### *Example*
````php
<?php
$parser = uv_http_parser_init(UV::HTTP_REQUEST);
if (uv_http_parser_execute($parser, "GET /img/http-parser.png?key=value#frag HTTP/1.1
Host: chobie.net
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Gecko/20100101 Firefox/12.0
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://chobie.net/
Cookie: key=value
Cache-Control: max-age=0
",$result)) {
var_dump($result);
//array(6) {
// ["headers"]=>
// array(8) {
// ["Host"]=>
// string(10) "chobie.net"
// ["User-Agent"]=>
// string(81) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Gecko/20100101 Firefox/12.0"
// ["Accept-Language"]=>
// string(14) "en-us,en;q=0.5"
// ["Accept-Encoding"]=>
// string(13) "gzip, deflate"
// ["Connection"]=>
// string(10) "keep-alive"
// ["Referer"]=>
// string(18) "http://chobie.net/"
// ["Cookie"]=>
// string(9) "key=value"
// ["Cache-Control"]=>
// string(9) "max-age=0"
// }
// ["QUERY_STRING"]=>
// string(35) "/img/http-parser.png?key=value#frag"
// ["path"]=>
// string(20) "/img/http-parser.png"
// ["query"]=>
// string(9) "key=value"
// ["fragment"]=>
// string(4) "frag"
// ["REQUEST_METHOD"]=>
// string(3) "GET"
//}
}
````
*/
PHP_FUNCTION(uv_http_parser_execute)
{
@ -6321,7 +6411,7 @@ PHP_FUNCTION(uv_http_parser_execute)
"rs/a",&z_parser, &body, &body_len, &result) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(context, php_http_parser_context*, &z_parser, -1, PHP_UV_HTTPPARSER_RESOURCE_NAME, uv_httpparser_handle);
MAKE_STD_ZVAL(headers);

6
uv.c
View File

@ -69,9 +69,9 @@ static int php_uv_class_init(TSRMLS_D)
zend_declare_class_constant_long(uv_class_entry, "LEAVE_GROUP", sizeof("LEAVE_GROUP")-1, UV_LEAVE_GROUP TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "JOIN_GROUP", sizeof("JOIN_GROUP")-1, UV_JOIN_GROUP TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "HTTP_BOTH", sizeof("HTTP_BOTH"), HTTP_BOTH TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "HTTP_REQUEST", sizeof("HTTP_REQUEST"), HTTP_REQUEST TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "HTTP_RESPONSE", sizeof("HTTP_RESPONSE"), HTTP_RESPONSE TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "HTTP_BOTH", sizeof("HTTP_BOTH")-1, HTTP_BOTH TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "HTTP_REQUEST", sizeof("HTTP_REQUEST")-1, HTTP_REQUEST TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "HTTP_RESPONSE", sizeof("HTTP_RESPONSE")-1, HTTP_RESPONSE TSRMLS_CC);
return 0;
}