]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #27628 (Simplify the process of making a POST request via
authorIlia Alshanetsky <iliaa@php.net>
Fri, 19 Mar 2004 15:41:26 +0000 (15:41 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 19 Mar 2004 15:41:26 +0000 (15:41 +0000)
stream context).

NEWS
ext/standard/http_fopen_wrapper.c

diff --git a/NEWS b/NEWS
index 37e276720c7abde84245ad82d34df08574582b43..79a82ac0fb705f0f92eacc1d30282c19e7918cf2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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)
 
index c4f08dfd5e3f639c131a4217b1c39a5f512f48ca..a753bb36398f577232efcb05f6af15895e690ef7 100644 (file)
@@ -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';