@@ -222,7 +222,7 @@ const zend_function_entry swoole_http_request_methods[] =
222
222
PHP_ME (swoole_http_request, parse, arginfo_class_Swoole_Http_Request_parse, ZEND_ACC_PUBLIC)
223
223
PHP_ME (swoole_http_request, isCompleted, arginfo_class_Swoole_Http_Request_isCompleted, ZEND_ACC_PUBLIC)
224
224
PHP_ME (swoole_http_request, getMethod, arginfo_class_Swoole_Http_Request_getMethod, ZEND_ACC_PUBLIC)
225
- PHP_ME (swoole_http_request, getBodyStream, arginfo_class_Swoole_Http_Request_getBodyStream, ZEND_ACC_PUBLIC)
225
+ PHP_ME (swoole_http_request, getBodyStream, arginfo_class_Swoole_Http_Request_getBodyStream, ZEND_ACC_PUBLIC)
226
226
PHP_FE_END
227
227
};
228
228
// clang-format on
@@ -918,33 +918,37 @@ static PHP_METHOD(swoole_http_request, getBodyStream) {
918
918
RETURN_FALSE;
919
919
}
920
920
921
- char tmp_file[SW_HTTP_UPLOAD_TMPDIR_SIZE];
922
- sw_snprintf (tmp_file, SW_HTTP_UPLOAD_TMPDIR_SIZE, " %s/swoole.request.XXXXXX" , ctx->upload_tmp_dir .c_str ());
923
- int fd = swoole_tmpfile (tmp_file);
924
- if (fd < 0 ) {
925
- RETURN_FALSE;
926
- }
927
-
928
921
HttpRequest *req = &ctx->request ;
922
+ const char *data = nullptr ;
923
+ size_t length = 0 ;
924
+
929
925
if (req->body_length > 0 ) {
930
926
zval *zdata = &req->zdata ;
931
- write (fd, Z_STRVAL_P (zdata) + Z_STRLEN_P (zdata) - req->body_length , req->body_length );
927
+ data = Z_STRVAL_P (zdata) + Z_STRLEN_P (zdata) - req->body_length ;
928
+ length = req->body_length ;
932
929
} else if (req->chunked_body && req->chunked_body ->length != 0 ) {
933
- write (fd, req->chunked_body ->str , req->chunked_body ->length );
930
+ data = req->chunked_body ->str ;
931
+ length = req->chunked_body ->length ;
934
932
} else if (req->h2_data_buffer && req->h2_data_buffer ->length != 0 ) {
935
- write (fd, req->h2_data_buffer ->str , req->h2_data_buffer ->length );
933
+ data = req->h2_data_buffer ->str ;
934
+ length = req->h2_data_buffer ->length ;
936
935
}
937
936
938
- lseek (fd, 0 , SEEK_SET);
939
- php_stream *stream = php_swoole_create_stream_from_pipe (fd, " r+" , nullptr );
937
+ zend_string *buf = nullptr ;
938
+ if (data && length > 0 ) {
939
+ buf = zend_string_init (data, length, 0 );
940
+ }
941
+ php_stream *stream = php_stream_memory_open (TEMP_STREAM_READONLY, buf);
940
942
if (!stream) {
941
- close (fd);
943
+ if (buf) {
944
+ zend_string_release (buf);
945
+ }
942
946
RETURN_FALSE;
943
947
}
944
- zval *ztmpfiles = swoole_http_init_and_read_property (
945
- swoole_http_request_ce, ctx->request .zobject , &ctx->request .ztmpfiles , SW_ZSTR_KNOWN (SW_ZEND_STR_TMPFILES));
946
- add_next_index_string (ztmpfiles, tmp_file);
947
948
php_stream_to_zval (stream, return_value);
949
+ if (buf) {
950
+ zend_string_release (buf);
951
+ }
948
952
}
949
953
950
954
static PHP_METHOD (swoole_http_request, getData) {
0 commit comments