projects
/
m6w6
/
ext-http
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
- allow passing request options to the ctor
[m6w6/ext-http]
/
http_request_object.c
diff --git
a/http_request_object.c
b/http_request_object.c
index 7b1d82bec99ac92b1c4d3a909bea9d8f87a041af..479e0b699978fcffd017a281be207d28ad1995af 100644
(file)
--- a/
http_request_object.c
+++ b/
http_request_object.c
@@
-23,6
+23,8
@@
#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
+#include "zend_interfaces.h"
+
#include "php_http_std_defs.h"
#include "php_http_request_object.h"
#include "php_http_request_api.h"
#include "php_http_std_defs.h"
#include "php_http_request_object.h"
#include "php_http_request_api.h"
@@
-52,6
+54,7
@@
HTTP_EMPTY_ARGS(__destruct, 0);
HTTP_BEGIN_ARGS(__construct, 0, 0)
HTTP_ARG_VAL(url, 0)
HTTP_ARG_VAL(method, 0)
HTTP_BEGIN_ARGS(__construct, 0, 0)
HTTP_ARG_VAL(url, 0)
HTTP_ARG_VAL(method, 0)
+ HTTP_ARG_VAL(options, 0)
HTTP_END_ARGS;
HTTP_EMPTY_ARGS(getOptions, 0);
HTTP_END_ARGS;
HTTP_EMPTY_ARGS(getOptions, 0);
@@
-501,13
+504,13
@@
STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
if (status == SUCCESS) {
zval *qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData));
if (status == SUCCESS) {
zval *qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData));
- if (Z_STRLEN_P(qdata)
&& (strlen(request_uri) < HTTP_URI_MAXLEN)
) {
+ if (Z_STRLEN_P(qdata)) {
if (!strchr(request_uri, '?')) {
if (!strchr(request_uri, '?')) {
- str
cat(request_uri, "?"
);
+ str
lcat(request_uri, "?", HTTP_URI_MAXLEN
);
} else {
} else {
- str
cat(request_uri, "&"
);
+ str
lcat(request_uri, "&", HTTP_URI_MAXLEN
);
}
}
- str
ncat(request_uri, Z_STRVAL_P(qdata), HTTP_URI_MAXLEN - strlen(request_uri)
);
+ str
lcat(request_uri, Z_STRVAL_P(qdata), HTTP_URI_MAXLEN
);
}
status = http_request_init(obj->ch, Z_LVAL_P(meth), request_uri, body, Z_ARRVAL_P(GET_PROP(obj, options)));
}
status = http_request_init(obj->ch, Z_LVAL_P(meth), request_uri, body, Z_ARRVAL_P(GET_PROP(obj, options)));
@@
-646,13
+649,14
@@
static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS,
/* ### USERLAND ### */
/* ### USERLAND ### */
-/* {{{ proto void HttpRequest::__construct([string url[, int request_method = HTTP_METH_GET]])
+/* {{{ proto void HttpRequest::__construct([string url[, int request_method = HTTP_METH_GET
[, array options]
]])
*
* Instantiate a new HttpRequest object.
*
* Accepts a string as optional parameter containing the target request url.
* Additianally accepts an optional int parameter specifying the request method
*
* Instantiate a new HttpRequest object.
*
* Accepts a string as optional parameter containing the target request url.
* Additianally accepts an optional int parameter specifying the request method
- * to use.
+ * to use and an associative array as optional third parameter which will be
+ * passed to HttpRequest::setOptions().
*
* Throws HttpException.
*/
*
* Throws HttpException.
*/
@@
-661,10
+665,11
@@
PHP_METHOD(HttpRequest, __construct)
char *URL = NULL;
int URL_len;
long meth = -1;
char *URL = NULL;
int URL_len;
long meth = -1;
+ zval *options = NULL;
getObject(http_request_object, obj);
SET_EH_THROW_HTTP();
getObject(http_request_object, obj);
SET_EH_THROW_HTTP();
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl
", &URL, &URL_len, &meth
)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl
a", &URL, &URL_len, &meth, &options
)) {
INIT_PARR(obj, options);
INIT_PARR(obj, responseInfo);
INIT_PARR(obj, responseData);
INIT_PARR(obj, options);
INIT_PARR(obj, responseInfo);
INIT_PARR(obj, responseData);
@@
-677,6
+682,9
@@
PHP_METHOD(HttpRequest, __construct)
if (meth > -1) {
UPD_PROP(obj, long, method, meth);
}
if (meth > -1) {
UPD_PROP(obj, long, method, meth);
}
+ if (options) {
+ zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setoptions", NULL, options);
+ }
}
SET_EH_NORMAL();
}
}
SET_EH_NORMAL();
}