#include "php_http_api.h"
#include "php_http_send_api.h"
#include "php_http_cache_api.h"
-#include "php_http_headers_api.h"
+#include "php_http_send_api.h"
#include "php_http_message_api.h"
#include "php_http_request_method_api.h"
#ifdef HTTP_HAVE_CURL
REGISTER_INI_ENTRIES();
if ( (SUCCESS != PHP_MINIT_CALL(http_support)) ||
- (SUCCESS != PHP_MINIT_CALL(http_headers)) ||
+ (SUCCESS != PHP_MINIT_CALL(http_send)) ||
#ifdef HTTP_HAVE_CURL
(SUCCESS != PHP_MINIT_CALL(http_request)) ||
#endif /* HTTP_HAVE_CURL */
{
time_t now;
struct tm nowtm;
- char datetime[128];
-
- HTTP_CHECK_OPEN_BASEDIR(file, return);
+ char datetime[20] = {0};
time(&now);
strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", php_localtime_r(&now, &nowtm));
* The HTTP response code will be set according to status.
* You can use one of the following constants for convenience:
* - HTTP_REDIRECT 302 Found
+ * - HTTP_REDIRECT_AUTO 303 See Other for POST, else 302 Found
* - HTTP_REDIRECT_PERM 301 Moved Permanently
* - HTTP_REDIRECT_POST 303 See Other
* - HTTP_REDIRECT_TEMP 307 Temporary Redirect
size_t query_len = 0;
zend_bool session = 0, free_params = 0;
zval *params = NULL;
- long status = 302;
+ long status = 0;
char *query = NULL, *url = NULL, *URI, *LOC, *RED = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sa!/bl", &url, &url_len, ¶ms, &session, &status) != SUCCESS) {
# define HTTP_DBG_NEG 0
#endif
-/* {{{ */
-PHP_MINIT_FUNCTION(http_headers)
-{
- HTTP_LONG_CONSTANT("HTTP_REDIRECT", HTTP_REDIRECT);
- HTTP_LONG_CONSTANT("HTTP_REDIRECT_PERM", HTTP_REDIRECT_PERM);
- HTTP_LONG_CONSTANT("HTTP_REDIRECT_POST", HTTP_REDIRECT_POST);
- HTTP_LONG_CONSTANT("HTTP_REDIRECT_TEMP", HTTP_REDIRECT_TEMP);
-
- return SUCCESS;
-}
-/* }}} */
-
/* {{{ static int http_sort_q(const void *, const void *) */
static int http_sort_q(const void *a, const void *b TSRMLS_DC)
{
HTTP_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST);
HTTP_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM);
HTTP_LONG_CONSTANT("HTTP_AUTH_ANY", CURLAUTH_ANY);
+
+ HTTP_LONG_CONSTANT("HTTP_VERSION_NONE", CURL_HTTP_VERSION_NONE);
+ HTTP_LONG_CONSTANT("HTTP_VERSION_1_0", CURL_HTTP_VERSION_1_0);
+ HTTP_LONG_CONSTANT("HTTP_VERSION_1_1", CURL_HTTP_VERSION_1_1);
return SUCCESS;
}
/* proxy */
if ((zoption = http_request_option(request, options, "proxyhost", IS_STRING))) {
- HTTP_CURL_OPT(PROXY, (Z_STRLEN_P(zoption) ? Z_STRVAL_P(zoption) : NULL));
+ if (Z_STRLEN_P(zoption)) {
+ HTTP_CURL_OPT(PROXY, Z_STRVAL_P(zoption));
+ }
+
/* port */
if ((zoption = http_request_option(request, options, "proxyport", IS_LONG))) {
HTTP_CURL_OPT(PROXYPORT, Z_LVAL_P(zoption));
}
/* user:pass */
- if ((zoption = http_request_option(request, options, "proxyauth", IS_STRING))) {
- HTTP_CURL_OPT(PROXYUSERPWD, (Z_STRLEN_P(zoption) ? Z_STRVAL_P(zoption) : NULL));
+ if ((zoption = http_request_option(request, options, "proxyauth", IS_STRING)) && Z_STRLEN_P(zoption)) {
+ HTTP_CURL_OPT(PROXYUSERPWD, Z_STRVAL_P(zoption));
}
/* auth method */
if ((zoption = http_request_option(request, options, "proxyauthtype", IS_LONG))) {
}
/* auth */
- if ((zoption = http_request_option(request, options, "httpauth", IS_STRING))) {
- HTTP_CURL_OPT(USERPWD, (Z_STRLEN_P(zoption) ? Z_STRVAL_P(zoption) : NULL));
+ if ((zoption = http_request_option(request, options, "httpauth", IS_STRING)) && Z_STRLEN_P(zoption)) {
+ HTTP_CURL_OPT(USERPWD, Z_STRVAL_P(zoption));
}
if ((zoption = http_request_option(request, options, "httpauthtype", IS_LONG))) {
HTTP_CURL_OPT(HTTPAUTH, Z_LVAL_P(zoption));
}
/* referer */
- if ((zoption = http_request_option(request, options, "referer", IS_STRING))) {
- HTTP_CURL_OPT(REFERER, (Z_STRLEN_P(zoption) ? Z_STRVAL_P(zoption) : NULL));
+ if ((zoption = http_request_option(request, options, "referer", IS_STRING)) && Z_STRLEN_P(zoption)) {
+ HTTP_CURL_OPT(REFERER, Z_STRVAL_P(zoption));
}
/* useragent, default "PECL::HTTP/version (PHP/version)" */
- if ((zoption = http_request_option(request, options, "useragent", IS_STRING))) {
- HTTP_CURL_OPT(USERAGENT, (Z_STRLEN_P(zoption) ? Z_STRVAL_P(zoption) : NULL));
+ if ((zoption = http_request_option(request, options, "useragent", IS_STRING)) && Z_STRLEN_P(zoption)) {
+ HTTP_CURL_OPT(USERAGENT, Z_STRVAL_P(zoption));
}
/* additional headers, array('name' => 'value') */
phpstr_fix(&request->_cache.cookies);
HTTP_CURL_OPT(COOKIE, request->_cache.cookies.data);
}
- } else {
- HTTP_CURL_OPT(COOKIE, NULL);
}
}
}
/* }}} */
+/* {{{ */
+PHP_MINIT_FUNCTION(http_send)
+{
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT", HTTP_REDIRECT);
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT_AUTO", HTTP_REDIRECT_AUTO);
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT_PERM", HTTP_REDIRECT_PERM);
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT_POST", HTTP_REDIRECT_POST);
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT_TEMP", HTTP_REDIRECT_TEMP);
+
+ return SUCCESS;
+}
+/* }}} */
+
/* {{{ STATUS http_send_header(char *, char *, zend_bool) */
PHP_HTTP_API STATUS _http_send_header_ex(const char *name, size_t name_len, const char *value, size_t value_len, zend_bool replace, char **sent_header TSRMLS_DC)
#include "php_http_info_api.h"
-#define HTTP_REDIRECT 302L
-#define HTTP_REDIRECT_PERM 301L
-#define HTTP_REDIRECT_POST 303L
-#define HTTP_REDIRECT_TEMP 307L
-
typedef enum {
RANGE_OK,
RANGE_NO,
RANGE_ERR
} http_range_status;
-extern PHP_MINIT_FUNCTION(http_headers);
-
#define http_parse_headers(h, a) _http_parse_headers_ex((h), Z_ARRVAL_P(a), 1, http_info_default_callback, NULL TSRMLS_CC)
#define http_parse_headers_ex(h, ht, p) _http_parse_headers_ex((h), (ht), (p), http_info_default_callback, NULL TSRMLS_CC)
#define http_parse_headers_cb(h, ht, p, f, d) _http_parse_headers_ex((h), (ht), (p), (f), (d) TSRMLS_CC)
SEND_RSRC
} http_send_mode;
+#define HTTP_REDIRECT 302L
+#define HTTP_REDIRECT_AUTO 0L
+#define HTTP_REDIRECT_PERM 301L
+#define HTTP_REDIRECT_POST 303L
+#define HTTP_REDIRECT_TEMP 307L
+
+extern PHP_MINIT_FUNCTION(http_send);
+
#define http_send_status(s) sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) (s) TSRMLS_CC)
#define http_send_header(n, v, r) _http_send_header_ex((n), strlen(n), (v), strlen(v), (r) TSRMLS_CC)
#define http_send_header_ex(n, nl, v, vl, r, s) _http_send_header_ex((n), (nl), (v), (vl), (r), (s) TSRMLS_CC)
?>
--EXPECTF--
%sTEST
-string(467) "PUT /.print_request.php HTTP/1.1
-User-Agent: PECL::HTTP/0.21.0dev (PHP/5.1.2-dev)
+string(%d) "PUT /.print_request.php HTTP/1.1
+User-Agent: %s
Host: dev.iworks.at
Accept: */*
content-type: text/plain
--EXPECTF--
%sTEST
int(200)
-string(189) "FOOBAR /.print_request.php HTTP/1.1
+string(%d) "FOOBAR /.print_request.php HTTP/1.1
User-Agent: %s
Host: dev.iworks.at
Accept: */*