don't limit header length to 1k
[m6w6/ext-http] / http_request_api.c
index 2a5f68e7ab1c5e564ba4d0200b38972aa4167ccd..d328161e13eca231b8dd48a601290d93e695f800 100644 (file)
@@ -6,7 +6,7 @@
     | modification, are permitted provided that the conditions mentioned |
     | in the accompanying LICENSE file are met.                          |
     +--------------------------------------------------------------------+
-    | Copyright (c) 2004-2007, Michael Wallner <mike@php.net>            |
+    | Copyright (c) 2004-2010, Michael Wallner <mike@php.net>            |
     +--------------------------------------------------------------------+
 */
 
@@ -531,8 +531,9 @@ PHP_HTTP_API void _http_request_defaults(http_request *request)
                HTTP_CURL_OPT(CURLOPT_HTTPHEADER, NULL);
                HTTP_CURL_OPT(CURLOPT_COOKIE, NULL);
                HTTP_CURL_OPT(CURLOPT_COOKIESESSION, 0L);
+               /* these options would enable curl's cookie engine by default which we don't want
                HTTP_CURL_OPT(CURLOPT_COOKIEFILE, NULL);
-               HTTP_CURL_OPT(CURLOPT_COOKIEJAR, NULL);
+               HTTP_CURL_OPT(CURLOPT_COOKIEJAR, NULL); */
 #if HTTP_CURL_VERSION(7,14,1)
                HTTP_CURL_OPT(CURLOPT_COOKIELIST, NULL);
 #endif
@@ -845,31 +846,37 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
                HashKey header_key = initHashKey(0);
                zval **header_val;
                HashPosition pos;
-
+               phpstr header;
+               
+               phpstr_init(&header);
                FOREACH_KEYVAL(pos, zoption, header_key, header_val) {
                        if (header_key.type == HASH_KEY_IS_STRING) {
-                               char header[1024];
                                zval *header_cpy = http_zsep(IS_STRING, *header_val);
                                
                                if (!strcasecmp(header_key.str, "range")) {
                                        range_req = 1;
                                }
-                               snprintf(header, sizeof(header), "%s: %s", header_key.str, Z_STRVAL_P(header_cpy));
-                               request->_cache.headers = curl_slist_append(request->_cache.headers, header);
+
+                               phpstr_appendf(&header, "%s: %s", header_key.str, Z_STRVAL_P(header_cpy));
+                               phpstr_fix(&header);
+                               request->_cache.headers = curl_slist_append(request->_cache.headers, PHPSTR_VAL(&header));
+                               phpstr_reset(&header);
+                               
                                zval_ptr_dtor(&header_cpy);
                        }
                }
+               phpstr_dtor(&header);
        }
        /* etag */
        if ((zoption = http_request_option(request, options, "etag", IS_STRING)) && Z_STRLEN_P(zoption)) {
-               char match_header[1024], *quoted_etag = NULL;
+               zend_bool is_quoted = !((Z_STRVAL_P(zoption)[0] != '"') || (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] != '"'));
+               phpstr header;
                
-               if ((Z_STRVAL_P(zoption)[0] != '"') || (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] != '"')) {
-                       spprintf(&quoted_etag, 0, "\"%s\"", Z_STRVAL_P(zoption));
-               }
-               snprintf(match_header, sizeof(match_header), "%s: %s", range_req?"If-Match":"If-None-Match", quoted_etag?quoted_etag:Z_STRVAL_P(zoption));
-               request->_cache.headers = curl_slist_append(request->_cache.headers, match_header);
-               STR_FREE(quoted_etag);
+               phpstr_init(&header);
+               phpstr_appendf(&header, is_quoted?"%s: %s":"%s: \"%s\"", range_req?"If-Match":"If-None-Match", Z_STRVAL_P(zoption));
+               phpstr_fix(&header);
+               request->_cache.headers = curl_slist_append(request->_cache.headers, PHPSTR_VAL(&header));
+               phpstr_dtor(&header);
        }
        /* compression */
        if ((zoption = http_request_option(request, options, "compress", IS_BOOL)) && Z_LVAL_P(zoption)) {
@@ -1084,6 +1091,11 @@ PHP_HTTP_API void _http_request_exec(http_request *request)
 retry:
        if (CURLE_OK != (result = curl_easy_perform(request->ch))) {
                http_error_ex(HE_WARNING, HTTP_E_REQUEST, "%s; %s (%s)", curl_easy_strerror(result), http_request_storage_get(request->ch)->errorbuffer, request->url);
+#ifdef ZEND_ENGINE_2
+               if ((HTTP_G->only_exceptions || GLOBAL_ERROR_HANDLING == EH_THROW) && EG(exception)) {
+                       add_property_long(EG(exception), "curlCode", result);
+               }
+#endif
                
                if (request->_retry.count > tries++) {
                        switch (result) {