Skip to content

Commit

Permalink
MFH: Fixed bug #27628 (Simplify the process of making a POST request via
Browse files Browse the repository at this point in the history
stream context).
  • Loading branch information
Ilia Alshanetsky committed Mar 19, 2004
1 parent a145c1b commit d45b2c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
22 changes: 20 additions & 2 deletions ext/standard/http_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit d45b2c6

Please sign in to comment.