iliaa           Fri Mar 19 10:42:41 2004 EDT

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/standard       http_fopen_wrapper.c 
  Log:
  MFH: Fixed bug #27628 (Simplify the process of making a POST request via
  stream context).
  
  
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1650&r2=1.1651&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1650 php-src/NEWS:1.1651
--- php-src/NEWS:1.1650 Thu Mar 18 13:25:22 2004
+++ php-src/NEWS        Fri Mar 19 10:40:11 2004
@@ -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)
 
http://cvs.php.net/diff.php/php-src/ext/standard/http_fopen_wrapper.c?r1=1.85&r2=1.86&ty=u
Index: php-src/ext/standard/http_fopen_wrapper.c
diff -u php-src/ext/standard/http_fopen_wrapper.c:1.85 
php-src/ext/standard/http_fopen_wrapper.c:1.86
--- php-src/ext/standard/http_fopen_wrapper.c:1.85      Wed Feb 25 19:13:30 2004
+++ php-src/ext/standard/http_fopen_wrapper.c   Fri Mar 19 10:41:26 2004
@@ -18,7 +18,7 @@
    |          Wez Furlong <[EMAIL PROTECTED]>                          |
    +----------------------------------------------------------------------+
  */
-/* $Id: http_fopen_wrapper.c,v 1.85 2004/02/26 00:13:30 sniper Exp $ */ 
+/* $Id: http_fopen_wrapper.c,v 1.86 2004/03/19 15:41:26 iliaa Exp $ */ 
 
 #include "php.h"
 #include "php_globals.h"
@@ -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 @@
                        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_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';

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to