php_stripcslashes(Z_STRVAL_P(zv), &Z_STRLEN_P(zv));
}
-static inline void prepare_escaped(zval *zv TSRMLS_DC)
+static inline void quote_string(zval *zv, zend_bool force TSRMLS_DC)
{
- if (Z_TYPE_P(zv) == IS_STRING) {
- int len = Z_STRLEN_P(zv);
+ int len = Z_STRLEN_P(zv);
- Z_STRVAL_P(zv) = php_addcslashes(Z_STRVAL_P(zv), Z_STRLEN_P(zv), &Z_STRLEN_P(zv), 1,
- ZEND_STRL("\0..\37\173\\\"") TSRMLS_CC);
+ Z_STRVAL_P(zv) = php_addcslashes(Z_STRVAL_P(zv), Z_STRLEN_P(zv), &Z_STRLEN_P(zv), 1,
+ ZEND_STRL("\0..\37\173\\\"") TSRMLS_CC);
- if (len != Z_STRLEN_P(zv) || strpbrk(Z_STRVAL_P(zv), "()<>@,;:\"[]?={} ")) {
- zval tmp = *zv;
- int len = Z_STRLEN_P(zv) + 2;
- char *str = emalloc(len + 1);
+ if (force || len != Z_STRLEN_P(zv) || strpbrk(Z_STRVAL_P(zv), "()<>@,;:\"[]?={} ")) {
+ zval tmp = *zv;
+ int len = Z_STRLEN_P(zv) + 2;
+ char *str = emalloc(len + 1);
- str[0] = '"';
- memcpy(&str[1], Z_STRVAL_P(zv), Z_STRLEN_P(zv));
- str[len-1] = '"';
- str[len] = '\0';
+ str[0] = '"';
+ memcpy(&str[1], Z_STRVAL_P(zv), Z_STRLEN_P(zv));
+ str[len-1] = '"';
+ str[len] = '\0';
- zval_dtor(&tmp);
- ZVAL_STRINGL(zv, str, len, 0);
- }
+ zval_dtor(&tmp);
+ ZVAL_STRINGL(zv, str, len, 0);
+ }
+}
+
+static inline void prepare_escaped(zval *zv TSRMLS_DC)
+{
+ if (Z_TYPE_P(zv) == IS_STRING) {
+ quote_string(zv, 0 TSRMLS_CC);
} else {
zval_dtor(zv);
ZVAL_EMPTY_STRING(zv);
php_trim(str, len, " ><", 3, zv, 3 TSRMLS_CC);
}
+static inline void prepare_rfc5988(zval *zv TSRMLS_DC)
+{
+ if (Z_TYPE_P(zv) != IS_STRING) {
+ zval_dtor(zv);
+ ZVAL_EMPTY_STRING(zv);
+ }
+}
+
static void utf8encode(zval *zv)
{
size_t pos, len = 0;
}
if (flags & PHP_HTTP_PARAMS_ESCAPED) {
- prepare_escaped(&zv TSRMLS_CC);
+ if (flags & PHP_HTTP_PARAMS_RFC5988) {
+ prepare_rfc5988(&zv TSRMLS_CC);
+ } else {
+ prepare_escaped(&zv TSRMLS_CC);
+ }
}
*new_key = Z_STRVAL(zv);
efree(str);
}
+static inline void shift_rfc5988_val(php_http_buffer_t *buf, zval *zv, const char *vss, size_t vsl, unsigned flags TSRMLS_DC)
+{
+ zval *tmp = php_http_zsep(1, IS_STRING, zv);
+
+ quote_string(tmp, 1 TSRMLS_CC);
+ php_http_buffer_append(buf, vss, vsl);
+ php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
+
+ zval_ptr_dtor(&tmp);
+}
+
static inline void shift_val(php_http_buffer_t *buf, zval *zvalue, const char *vss, size_t vsl, unsigned flags TSRMLS_DC)
{
if (Z_TYPE_P(zvalue) != IS_BOOL) {
}
} else {
shift_key(buf, key_str, key_len, ass, asl, flags TSRMLS_CC);
+
+ if (flags & PHP_HTTP_PARAMS_RFC5988) {
+ switch (key_len) {
+ case lenof("rel"):
+ case lenof("title"):
+ case lenof("anchor"):
+ /* some args must be quoted */
+ if (0 <= php_http_select_str(key_str, 3, "rel", "title", "anchor")) {
+ shift_rfc5988_val(buf, zvalue, vss, vsl, flags TSRMLS_CC);
+ return;
+ }
+ break;
+ }
+ }
+
shift_val(buf, zvalue, vss, vsl, flags TSRMLS_CC);
}
}
--FILE--
<?php
-
+include "helper/dump.inc";
include "helper/server.inc";
echo "Test\n";
$client = new http\Client();
$client->enqueue($request);
$client->send();
- echo $client->getResponse();
+ dump_message(null, $client->getResponse());
});
?>
Test
HTTP/1.1 200 OK
Accept-Ranges: bytes
+Content-Length: %d
Etag: "%s"
X-Original-Transfer-Encoding: chunked
-Content-Length: %d
GET / HTTP/1.1
-User-Agent: %s
-Host: localhost:%d
Accept: */*
-Content-Type: text/plain
Content-Length: 3
+Content-Type: text/plain
+Host: localhost:%d
+User-Agent: %s
X-Original-Content-Length: 3
foo
Test
Server on port %d
CONNECT www.example.com:80 HTTP/1.1
+Hello: there!
Host: www.example.com:80
-User-Agent: PECL_HTTP/%s PHP/%s libcurl/%s
Proxy-Connection: Keep-Alive
-Hello: there!
+User-Agent: PECL_HTTP/%s PHP/%s libcurl/%s
+
===DONE===
Test
Server on port %d
GET / HTTP/1.1
-User-Agent: PECL_HTTP/%s PHP/%s libcurl/%s
-Host: localhost:%d
Accept: */*
+Host: localhost:%d
+User-Agent: PECL_HTTP/%s PHP/%s libcurl/%s
+
===DONE===
--FILE--
<?php
+include "helper/dump.inc";
include "helper/server.inc";
echo "Test\n";
$request = new http\Client\Request("PUT", "http://localhost:$port");
$request->setOptions(array("resume" => 1, "expect_100_timeout" => 0));
$request->getBody()->append("123");
- echo $client->enqueue($request)->send()->getResponse();
+ dump_message(null, $client->enqueue($request)->send()->getResponse());
});
// Content-length is 2 instead of 3 in older libcurls
?>
Test
HTTP/1.1 200 OK
Accept-Ranges: bytes
+Content-Length: %d
Etag: "%x"
X-Original-Transfer-Encoding: chunked
-Content-Length: %d
PUT / HTTP/1.1
-Content-Range: bytes 1-2/3
-User-Agent: %s
-Host: localhost:%d
Accept: */*
Content-Length: %d
+Content-Range: bytes 1-2/3
Expect: 100-continue
+Host: localhost:%d
+User-Agent: %s
X-Original-Content-Length: %d
23===DONE===
--- /dev/null
+<?php
+
+function dump_message($stream, http\Message $msg, $parent = false) {
+ if (!is_resource($stream)) {
+ $stream = fopen("php://output", "w");
+ }
+ fprintf($stream, "%s\n", $msg->getInfo());
+ $headers = $msg->getHeaders();
+ ksort($headers);
+ foreach ($headers as $key => $val) {
+ fprintf($stream, "%s: %s\n", $key, $val);
+ }
+ fprintf($stream, "\n");
+ $msg->getBody()->toStream($stream);
+
+ if ($parent && ($msg = $msg->getParentMessage())) {
+ dump_message($stream, $msg, true);
+ }
+}
+
+?>
\ No newline at end of file
<?php
+include "dump.inc";
include "server.inc";
serve(function($client) {
/* return the initial message as response body */
$response = new http\Env\Response;
/* avoid OOM with $response->getBody()->append($request); */
- $request->toStream($response->getBody()->getResource());
+ dump_message($response->getBody()->getResource(), $request);
$response->send($client);
});
<?php
+include "dump.inc";
include "server.inc";
serve(function($client) {
/* return the initial message as response body */
$response = new http\Env\Response;
/* avoid OOM with $response->getBody()->append($request); */
- $request->toStream($response->getBody()->getResource());
+ dump_message($response->getBody()->getResource(), $request);
$response->send($client);
});
--- /dev/null
+--TEST--
+header params rfc5988
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$link = <<<EOF
+<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=2>; rel="next", <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34>; rel="last"
+EOF;
+
+$p = new http\Params($link, ",", ";", "=",
+ http\Params::PARSE_RFC5988 | http\Params::PARSE_ESCAPED);
+var_dump($p->params);
+var_dump((string)$p);
+?>
+===DONE===
+--EXPECT--
+Test
+array(2) {
+ ["https://api.github.com/search/code?q=addClass+user%3Amozilla&page=2"]=>
+ array(2) {
+ ["value"]=>
+ bool(true)
+ ["arguments"]=>
+ array(1) {
+ ["rel"]=>
+ string(4) "next"
+ }
+ }
+ ["https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34"]=>
+ array(2) {
+ ["value"]=>
+ bool(true)
+ ["arguments"]=>
+ array(1) {
+ ["rel"]=>
+ string(4) "last"
+ }
+ }
+}
+string(162) "<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=2>;rel="next",<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34>;rel="last""
+===DONE===
--- /dev/null
+--TEST--
+header params rfc5988
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$link = <<<EOF
+Link: </TheBook/chapter2>;
+ rel="previous"; title*=UTF-8'de'letztes%20Kapitel,
+ </TheBook/chapter4>;
+ rel="next"; title*=UTF-8'de'n%c3%a4chstes%20Kapitel
+EOF;
+
+$p = current(http\Header::parse($link, "http\\Header"))->getParams(
+ http\Params::DEF_PARAM_SEP,
+ http\Params::DEF_ARG_SEP,
+ http\Params::DEF_VAL_SEP,
+ http\Params::PARSE_RFC5988 | http\Params::PARSE_ESCAPED
+);
+var_dump($p->params);
+var_dump((string)$p);
+?>
+===DONE===
+--EXPECTF--
+Test
+array(2) {
+ ["/TheBook/chapter2"]=>
+ array(2) {
+ ["value"]=>
+ bool(true)
+ ["arguments"]=>
+ array(2) {
+ ["rel"]=>
+ string(8) "previous"
+ ["*rfc5987*"]=>
+ array(1) {
+ ["title"]=>
+ array(1) {
+ ["de"]=>
+ string(15) "letztes Kapitel"
+ }
+ }
+ }
+ }
+ ["/TheBook/chapter4"]=>
+ array(2) {
+ ["value"]=>
+ bool(true)
+ ["arguments"]=>
+ array(2) {
+ ["rel"]=>
+ string(4) "next"
+ ["*rfc5987*"]=>
+ array(1) {
+ ["title"]=>
+ array(1) {
+ ["de"]=>
+ string(17) "nächstes Kapitel"
+ }
+ }
+ }
+ }
+}
+string(139) "</TheBook/chapter2>;rel="previous";title*=utf-8'de'letztes%20Kapitel,</TheBook/chapter4>;rel="next";title*=utf-8'de'n%C3%A4chstes%20Kapitel"
+===DONE===