X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http.c;h=6efc142e9745cf43fd8ff9be481736e480d1626c;hp=e432ef02abc5730e3df1648c7f9ec8f93b3c185d;hb=96d32e2bd4a5d2b0741addf6f59b46d7d8749937;hpb=f8f0fd4dc265150a309824448b08249151d2ec45 diff --git a/http.c b/http.c index e432ef0..6efc142 100644 --- a/http.c +++ b/http.c @@ -71,6 +71,7 @@ function_entry http_functions[] = { PHP_FE(http_send_stream, NULL) PHP_FE(http_chunked_decode, NULL) PHP_FE(http_split_response, NULL) + PHP_FE(http_parse_headers, NULL) #ifdef HTTP_HAVE_CURL PHP_FE(http_get, NULL) PHP_FE(http_head, NULL) @@ -677,7 +678,10 @@ PHP_FUNCTION(http_split_response) MAKE_STD_ZVAL(zheaders); array_init(zheaders); - http_split_response(zresponse, zheaders, zbody); + if (SUCCESS != http_split_response(zresponse, zheaders, zbody)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP response"); + RETURN_FALSE; + } array_init(return_value); add_index_zval(return_value, 0, zheaders); @@ -685,6 +689,29 @@ PHP_FUNCTION(http_split_response) } /* }}} */ +/* {{{ proto array http_parse_headers(string header) */ +PHP_FUNCTION(http_parse_headers) +{ + char *header, *rnrn; + int header_len; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header, &header_len)) { + RETURN_FALSE; + } + + array_init(return_value); + + if (rnrn = strstr(header, HTTP_CRLF HTTP_CRLF)) { + header_len = rnrn - header + 2; + } + if (SUCCESS != http_parse_headers(header, header_len, return_value)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP header"); + zval_dtor(return_value); + RETURN_FALSE; + } +} +/* }}}*/ + /* {{{ HAVE_CURL */ #ifdef HTTP_HAVE_CURL