- make request_exec() always succeed (picky curl)
[m6w6/ext-http] / http_headers_api.c
index 0be9b2c018c763b2a6ad002d780ba64ce696174a..4c3c5025aa67d27f21665ca8b51953859d3e4589 100644 (file)
@@ -433,24 +433,38 @@ PHP_HTTP_API void _http_get_request_headers_ex(HashTable *headers, zend_bool pre
 {
        char *key = NULL;
        ulong idx = 0;
+       uint keylen = 0;
        zval array, **hsv;
        HashPosition pos;
 
        Z_ARRVAL(array) = headers;
 
        if (SUCCESS == zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &hsv)) {
-               FOREACH_KEY(pos, *hsv, key, idx) {
-                       if (key && !strncmp(key, "HTTP_", 5)) {
-                               zval **header;
+               FOREACH_KEYLEN(pos, *hsv, key, keylen, idx) {
+                       if (key && keylen > 6 && !strncmp(key, "HTTP_", 5)) {
+                               zval **header, *orig;
        
                                key += 5;
+                               keylen -= 6;
                                if (prettify) {
-                                       key = pretty_key(key, strlen(key), 1, 1);
+                                       key = pretty_key(estrndup(key, keylen), keylen, 1, 1);
                                }
        
                                zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv), (void **) &header, &pos);
+                               
+                               orig = *header;
+                               convert_to_string_ex(header);
                                add_assoc_stringl(&array, key, Z_STRVAL_PP(header), Z_STRLEN_PP(header), 1);
+                               if (orig != *header) {
+                                       zval_ptr_dtor(header);
+                               }
+                               
+                               if (prettify) {
+                                       efree(key);
+                               }
+                               
                                key = NULL;
+                               keylen = 0;
                        }
                }
        }
@@ -460,27 +474,19 @@ PHP_HTTP_API void _http_get_request_headers_ex(HashTable *headers, zend_bool pre
 /* {{{ zend_bool http_match_request_header(char *, char *) */
 PHP_HTTP_API zend_bool _http_match_request_header_ex(const char *header, const char *value, zend_bool match_case TSRMLS_DC)
 {
-       char *name, *key = NULL;
-       ulong idx;
+       char *name;
+       uint name_len = strlen(header);
        zend_bool result = 0;
        HashTable headers;
-       HashPosition pos;
+       zval **data;
 
-       name = pretty_key(estrdup(header), strlen(header), 1, 1);
+       name = pretty_key(estrndup(header, name_len), name_len, 1, 1);
        zend_hash_init(&headers, 0, NULL, ZVAL_PTR_DTOR, 0);
        http_get_request_headers_ex(&headers, 1);
 
-       FOREACH_HASH_KEY(pos, &headers, key, idx) {
-               if (key && (!strcmp(key, name))) {
-                       zval **data;
-
-                       if (SUCCESS == zend_hash_get_current_data_ex(&headers, (void **) &data, &pos)) {
-                               result = (match_case ? strcmp(Z_STRVAL_PP(data), value) : strcasecmp(Z_STRVAL_PP(data), value)) ? 0 : 1;
-                       }
-                       break;
-               }
+       if (SUCCESS == zend_hash_find(&headers, name, name_len+1, (void **) &data)) {
+               result = (match_case ? strcmp(Z_STRVAL_PP(data), value) : strcasecmp(Z_STRVAL_PP(data), value)) ? 0 : 1;
        }
-
        zend_hash_destroy(&headers);
        efree(name);