add CURLINFO_RETRY_AFTER
[m6w6/ext-http] / src / php_http_env.c
index df22d5a7134a29eceb4f43ca107a9d943a9203da..5e14ed21a436cf1dc2c8c1c7435c0d4237ca2bc9 100644 (file)
@@ -414,10 +414,12 @@ ZEND_RESULT_CODE php_http_env_set_response_status_line(long code, php_http_versi
 {
        sapi_header_line h = {NULL, 0, 0};
        ZEND_RESULT_CODE ret;
+       char *line;
 
-       h.line_len = spprintf(&h.line, 0, "HTTP/%u.%u %ld %s", v->major, v->minor, code, php_http_env_get_response_status_for_code(code));
+       h.line_len = spprintf(&line, 0, "HTTP/%u.%u %ld %s", v->major, v->minor, code, php_http_env_get_response_status_for_code(code));
+       h.line = line;
        ret = sapi_header_op(SAPI_HEADER_REPLACE, (void *) &h);
-       efree(h.line);
+       efree(line);
 
        return ret;
 }
@@ -429,10 +431,9 @@ ZEND_RESULT_CODE php_http_env_set_response_protocol_version(php_http_version_t *
 
 ZEND_RESULT_CODE php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace)
 {
-       sapi_header_line h = {estrndup(header_str, header_len), header_len, http_code};
+       sapi_header_line h = {header_str, header_len, http_code};
        ZEND_RESULT_CODE ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h);
 
-       efree(h.line);
        return ret;
 }
 
@@ -440,14 +441,16 @@ ZEND_RESULT_CODE php_http_env_set_response_header_va(long http_code, zend_bool r
 {
        ZEND_RESULT_CODE ret = FAILURE;
        sapi_header_line h = {NULL, 0, http_code};
+       char *line;
 
-       h.line_len = vspprintf(&h.line, 0, fmt, argv);
+       h.line_len = vspprintf(&line, 0, fmt, argv);
+       h.line = line;
 
        if (h.line) {
                if (h.line_len) {
                        ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h);
                }
-               efree(h.line);
+               efree(line);
        }
        return ret;
 }
@@ -496,17 +499,19 @@ ZEND_RESULT_CODE php_http_env_set_response_header_value(long http_code, const ch
                } else {
                        sapi_header_line h;
                        ZEND_RESULT_CODE ret;
+                       char *line;
 
                        if (name_len > INT_MAX) {
                                return FAILURE;
                        }
                        h.response_code = http_code;
-                       h.line_len = spprintf(&h.line, 0, "%.*s: %.*s", (int) name_len, name_str, data->len, data->val);
+                       h.line_len = spprintf(&line, 0, "%s: %s", name_str, data->val);
+                       h.line = line;
 
                        ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h);
 
                        zend_string_release(data);
-                       PTR_FREE(h.line);
+                       PTR_FREE(line);
 
                        return ret;
                }
@@ -555,12 +560,12 @@ static PHP_METHOD(HttpEnv, getRequestBody)
 {
        php_http_message_body_t *body;
        php_http_message_body_object_t *body_obj;
-       zend_class_entry *class_entry = php_http_message_body_class_entry;
+       zend_class_entry *class_entry = php_http_get_message_body_class_entry();
 
        php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|C", &class_entry), invalid_arg, return);
 
        body = php_http_env_get_request_body();
-       if (SUCCESS == php_http_new((void *) &body_obj, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_message_body_class_entry, body)) {
+       if (SUCCESS == php_http_new((void *) &body_obj, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_get_message_body_class_entry(), body)) {
                php_http_message_body_addref(body);
                RETVAL_OBJ(&body_obj->zo);
        }
@@ -795,7 +800,11 @@ static zend_function_entry php_http_env_methods[] = {
        EMPTY_FUNCTION_ENTRY
 };
 
-zend_class_entry *php_http_env_class_entry;
+static zend_class_entry *php_http_env_class_entry;
+zend_class_entry *php_http_env_get_class_entry(void)
+{
+       return php_http_env_class_entry;
+}
 
 PHP_MINIT_FUNCTION(http_env)
 {