allow parsing messages consiting of headers only; fetch content-type and content...
authorMichael Wallner <mike@php.net>
Wed, 29 Feb 2012 08:28:06 +0000 (08:28 +0000)
committerMichael Wallner <mike@php.net>
Wed, 29 Feb 2012 08:28:06 +0000 (08:28 +0000)
php_http_header_parser.c
php_http_message.c
php_http_message_parser.c

index 0dbaf84..1dcd97b 100644 (file)
@@ -156,7 +156,7 @@ PHP_HTTP_API STATUS php_http_header_parser_parse(php_http_header_parser_t *parse
                                        
                                        if ((eol_str = php_http_locate_bin_eol(buffer->data, buffer->used, &eol_len))) {
                                                if (eol_str + eol_len - buffer->data < buffer->used) {
-                                                       char *nextline = eol_str + eol_len;
+                                                       const char *nextline = eol_str + eol_len;
 
                                                        if (*nextline == '\t' || *nextline == ' ') {
                                                                while (nextline < buffer->data + buffer->used && (*nextline == '\t' || *nextline == ' ')) {
@@ -188,6 +188,10 @@ PHP_HTTP_API STATUS php_http_header_parser_parse(php_http_header_parser_t *parse
                                if (parser->_key.str && parser->_val.str) {
                                        zval array, **exist;
 
+                                       if (!headers && callback_func) {
+                                               callback_func(callback_arg, &headers, NULL TSRMLS_CC);
+                                       }
+
                                        INIT_PZVAL_ARRAY(&array, headers);
                                        php_http_pretty_key(parser->_key.str, parser->_key.len, 1, 1);
                                        if (SUCCESS == zend_symtable_find(headers, parser->_key.str, parser->_key.len + 1, (void *) &exist)) {
index ab2c862..0322a4a 100644 (file)
@@ -23,7 +23,9 @@ PHP_HTTP_API zend_bool php_http_message_info_callback(php_http_message_t **messa
                (*headers) = &((*message)->hdrs);
        }
 
-       php_http_message_set_info(*message, info);
+       if (info) {
+               php_http_message_set_info(*message, info);
+       }
 
        return old != *message;
 }
@@ -65,6 +67,14 @@ PHP_HTTP_API php_http_message_t *php_http_message_init_env(php_http_message_t *m
                        if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_URI"), 1 TSRMLS_CC))) {
                                message->http.info.request.url = estrdup(Z_STRVAL_P(sval));
                        }
+                       if ((sval = php_http_env_get_server_var(ZEND_STRL("CONTENT_TYPE"), 1 TSRMLS_CC))) {
+                               Z_ADDREF_P(sval);
+                               zend_hash_update(&message->hdrs, "Content-Type", sizeof("Content-Type"), (void *) &sval, sizeof(zval *), NULL);
+                       }
+                       if ((sval = php_http_env_get_server_var(ZEND_STRL("CONTENT_LENGTH"), 1 TSRMLS_CC))) {
+                               Z_ADDREF_P(sval);
+                               zend_hash_update(&message->hdrs, "Content-Length", sizeof("Content-Length"), (void *) &sval, sizeof(zval *), NULL);
+                       }
                        
                        php_http_env_get_request_headers(&message->hdrs TSRMLS_CC);
 
index 4162e37..319f089 100644 (file)
@@ -213,7 +213,7 @@ PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_parse(php_h
                        {
                                unsigned header_parser_flags = (flags & PHP_HTTP_MESSAGE_PARSER_CLEANUP) ? PHP_HTTP_HEADER_PARSER_CLEANUP : 0;
 
-                               switch (php_http_header_parser_parse(&parser->header, buffer, header_parser_flags, &(*message)->hdrs, (php_http_info_callback_t) php_http_message_info_callback, message)) {
+                               switch (php_http_header_parser_parse(&parser->header, buffer, header_parser_flags, *message ? &(*message)->hdrs : NULL, (php_http_info_callback_t) php_http_message_info_callback, message)) {
                                        case PHP_HTTP_HEADER_PARSER_STATE_FAILURE:
                                                return PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE;