iliaa Sun Apr 6 15:21:45 2008 UTC Modified files: /php-src/ext/standard http_fopen_wrapper.c Log: MFB: Fixed bug #44603 (Order issues with Content-Type/Length headers on POST) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/http_fopen_wrapper.c?r1=1.131&r2=1.132&diff_format=u Index: php-src/ext/standard/http_fopen_wrapper.c diff -u php-src/ext/standard/http_fopen_wrapper.c:1.131 php-src/ext/standard/http_fopen_wrapper.c:1.132 --- php-src/ext/standard/http_fopen_wrapper.c:1.131 Mon Dec 31 07:12:15 2007 +++ php-src/ext/standard/http_fopen_wrapper.c Sun Apr 6 15:21:45 2008 @@ -19,7 +19,7 @@ | Sara Golemon <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: http_fopen_wrapper.c,v 1.131 2007/12/31 07:12:15 sebastian Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.132 2008/04/06 15:21:45 iliaa Exp $ */ #include "php.h" #include "php_globals.h" @@ -148,6 +148,7 @@ int protocol_version_len = 3; /* Default: "1.0" */ char *charset = NULL; struct timeval timeout; + char *user_headers = NULL; tmp_line[0] = '\0'; @@ -394,10 +395,8 @@ efree(tmp); tmp = tmp_c; } - - /* Output trimmed headers with \r\n at the end */ - php_stream_write(stream, tmp, strlen(tmp)); - php_stream_write(stream, "\r\n", sizeof("\r\n") - 1); + + user_headers = estrdup(tmp); /* Make lowercase for easy comparison against 'standard' headers */ php_strtolower(tmp, strlen(tmp)); @@ -495,6 +494,27 @@ } } + if (user_headers) { + /* A bit weird, but some servers require that Content-Length be sent prior to Content-Type for POST + * see bug #44603 for details. Since Content-Type maybe part of user's headers we need to do this check first. + */ + if ( + header_init && + context && + !(have_header & HTTP_HEADER_CONTENT_LENGTH) && + php_stream_context_get_option(context, "http", "content", &tmpzval) == SUCCESS && + Z_TYPE_PP(tmpzval) == IS_STRING && Z_STRLEN_PP(tmpzval) > 0 + ) { + scratch_len = slprintf(scratch, scratch_len, "Content-Length: %d\r\n", Z_STRLEN_PP(tmpzval)); + php_stream_write(stream, scratch, scratch_len); + have_header |= HTTP_HEADER_CONTENT_LENGTH; + } + + php_stream_write(stream, user_headers, strlen(user_headers)); + php_stream_write(stream, "\r\n", sizeof("\r\n")-1); + efree(user_headers); + } + /* Request content, such as for POST requests */ if (header_init && context && php_stream_context_get_option(context, "http", "content", &tmpzval) == SUCCESS &&
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php