diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2004-03-19 15:41:26 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2004-03-19 15:41:26 +0000 |
commit | d45b2c6bc3f72e096039d743788a1627ee9c0f54 (patch) | |
tree | 77e50de0d7b6fbfa9544eca56ea8f417e625017f | |
parent | a145c1b4cec64b0781d7e34f157d25c7270002fc (diff) | |
download | php-git-d45b2c6bc3f72e096039d743788a1627ee9c0f54.tar.gz |
MFH: Fixed bug #27628 (Simplify the process of making a POST request via
stream context).
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | ext/standard/http_fopen_wrapper.c | 22 |
2 files changed, 22 insertions, 2 deletions
@@ -1,6 +1,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ????? 2004, PHP 5 Release Candidate 2 +- Fixed bug #27628 (Simplify the process of making a POST request via stream + context). (Ilia) - Fixed bug #27469 (serialize() objects of incomplete class). (Dmitry) - Fixed bug #27457 (handling of numeric indexes in strtr()). (Dmitry) diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index c4f08dfd5e..a753bb3639 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -85,6 +85,8 @@ #define HTTP_HEADER_HOST 2 #define HTTP_HEADER_AUTH 4 #define HTTP_HEADER_FROM 8 +#define HTTP_HEADER_CONTENT_LENGTH 16 +#define HTTP_HEADER_TYPE 32 php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context, int redirect_max, int header_init STREAMS_DC TSRMLS_DC) { @@ -249,6 +251,12 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, if (strstr(tmp, "authorization:")) { have_header |= HTTP_HEADER_AUTH; } + if (strstr(tmp, "content-length:")) { + have_header |= HTTP_HEADER_CONTENT_LENGTH; + } + if (strstr(tmp, "content-type:")) { + have_header |= HTTP_HEADER_TYPE; + } } efree(tmp); } @@ -323,14 +331,24 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, } } - php_stream_write(stream, "\r\n", sizeof("\r\n")-1); - /* Request content, such as for POST requests */ if (context && php_stream_context_get_option(context, "http", "content", &tmpzval) == SUCCESS && Z_STRLEN_PP(tmpzval) > 0) { + if (!(have_header & HTTP_HEADER_CONTENT_LENGTH)) { + scratch_len = snprintf(scratch, scratch_len, "Content-Length: %d\r\n", Z_STRLEN_PP(tmpzval)); + php_stream_write(stream, scratch, scratch_len); + } + if (!(have_header & HTTP_HEADER_TYPE)) { + php_stream_write(stream, "Content-Type: application/x-www-form-urlencoded\r\n", + sizeof("Content-Type: application/x-www-form-urlencoded\r\n") - 1); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Content-type not specified assuming application/x-www-form-urlencoded"); + } + php_stream_write(stream, "\r\n", sizeof("\r\n")-1); php_stream_write(stream, Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval)); php_stream_write(stream, "\r\n\r\n", sizeof("\r\n\r\n")-1); + } else { + php_stream_write(stream, "\r\n", sizeof("\r\n")-1); } location[0] = '\0'; |