19
19
#include "../string_helpers.h"
20
20
#include "request_init.h"
21
21
#include <mpack.h>
22
- #include <zend_string.h>
23
22
24
23
static dd_result _request_pack (mpack_writer_t * nonnull w , void * nonnull ctx );
25
24
static void _init_autoglobals (void );
@@ -31,6 +30,8 @@ static void _pack_files_field_names(
31
30
mpack_writer_t * nonnull w , const zend_array * nonnull files );
32
31
static void _pack_path_params (
33
32
mpack_writer_t * nonnull w , const zend_string * nullable uri_raw );
33
+ static void _pack_request_body (mpack_writer_t * nonnull w ,
34
+ struct req_info_init * nonnull ctx , const zend_array * nonnull server );
34
35
35
36
static const dd_command_spec _spec = {
36
37
.name = "request_init" ,
@@ -101,8 +102,7 @@ static dd_result _request_pack(mpack_writer_t *nonnull w, void *nonnull _ctx)
101
102
102
103
// 6.
103
104
dd_mpack_write_lstr (w , "server.request.body" );
104
- dd_mpack_write_array (w , dd_get_superglob_or_equiv (ZEND_STRL ("_POST" ),
105
- TRACK_VARS_POST , ctx -> superglob_equiv ));
105
+ _pack_request_body (w , ctx , server );
106
106
107
107
// 7.
108
108
const zend_array * nonnull files = dd_get_superglob_or_equiv (
@@ -123,12 +123,9 @@ static dd_result _request_pack(mpack_writer_t *nonnull w, void *nonnull _ctx)
123
123
dd_mpack_write_nullable_zstr (w , ctx -> req_info .client_ip );
124
124
125
125
// 11.
126
- if (send_raw_body && ! ctx -> superglob_equiv ) {
126
+ if (send_raw_body && ctx -> entity ) {
127
127
dd_mpack_write_lstr (w , "server.request.body.raw" );
128
- zend_string * nonnull req_body =
129
- dd_request_body_buffered (get_DD_APPSEC_MAX_BODY_BUFF_SIZE ());
130
- dd_mpack_write_zstr (w , req_body );
131
- zend_string_release (req_body );
128
+ dd_mpack_write_zstr (w , ctx -> entity );
132
129
}
133
130
134
131
mpack_finish_map (w );
@@ -175,7 +172,13 @@ static void _pack_headers(
175
172
continue ;
176
173
}
177
174
178
- if (_is_relevant_header (key )) {
175
+ if (zend_string_equals_literal (key , "CONTENT_TYPE" )) {
176
+ dd_mpack_write_lstr (w , "content-type" );
177
+ dd_mpack_write_zval (w , val );
178
+ } else if (zend_string_equals_literal (key , "CONTENT_LENGTH" )) {
179
+ dd_mpack_write_lstr (w , "content-length" );
180
+ dd_mpack_write_zval (w , val );
181
+ } else if (_is_relevant_header (key )) {
179
182
zend_string * transf_header_name = _transform_header_name (key );
180
183
dd_mpack_write_zstr (w , transf_header_name );
181
184
zend_string_efree (transf_header_name );
@@ -274,3 +277,31 @@ static void _pack_path_params(
274
277
efree (uri_work_zstr );
275
278
mpack_complete_array (w );
276
279
}
280
+
281
+ static void _pack_request_body (mpack_writer_t * nonnull w ,
282
+ struct req_info_init * nonnull ctx , const zend_array * nonnull server )
283
+ {
284
+ const zend_array * post = dd_get_superglob_or_equiv (
285
+ ZEND_STRL ("_POST" ), TRACK_VARS_POST , ctx -> superglob_equiv );
286
+ if (zend_hash_num_elements (post ) != 0 ) {
287
+ dd_mpack_write_array (w , post );
288
+ } else {
289
+ bool written = false;
290
+ if (ctx -> entity ) {
291
+ zend_string * ct =
292
+ dd_php_get_string_elem_cstr (server , ZEND_STRL ("CONTENT_TYPE" ));
293
+ if (ct ) {
294
+ zval body_zv = dd_entity_body_convert (
295
+ ZSTR_VAL (ct ), ZSTR_LEN (ct ), ctx -> entity );
296
+ if (Z_TYPE (body_zv ) != IS_NULL ) {
297
+ dd_mpack_write_zval (w , & body_zv );
298
+ zval_ptr_dtor (& body_zv );
299
+ written = true;
300
+ }
301
+ }
302
+ }
303
+ if (!written ) {
304
+ dd_mpack_write_array (w , & zend_empty_array );
305
+ }
306
+ }
307
+ }
0 commit comments