@@ -287,59 +287,55 @@ pub async fn post_event(req: HttpRequest, body: web::Json<serde_json::Value>) ->
287
287
}
288
288
} ;
289
289
290
- if body. is_array ( ) {
290
+ if let Some ( array ) = body. as_array ( ) {
291
291
let mut i = 0 ;
292
- loop {
293
- if body. get ( i) . unwrap ( ) . is_object ( ) {
294
- let body =
295
- utils:: flatten_json_body ( web:: Json ( body[ i] . clone ( ) ) , labels. clone ( ) ) . unwrap ( ) ;
296
- let schema = utils:: read_schema_from_file ( & stream_name) . unwrap ( ) ;
297
- let e = event:: Event {
298
- body,
299
- path : option:: get_opts ( ) . local_disk_path ,
300
- stream_name : stream_name. clone ( ) ,
301
- schema : Bytes :: from ( schema) ,
302
- } ;
303
-
304
- if let Err ( e) = e. process ( ) {
305
- return response:: ServerResponse {
306
- msg : format ! ( "Failed to process event at index {} due to err: {}" , i, e) ,
307
- code : StatusCode :: INTERNAL_SERVER_ERROR ,
308
- }
309
- . to_http ( ) ;
292
+
293
+ for body in array {
294
+ let body = utils:: flatten_json_body ( web:: Json ( body. clone ( ) ) , labels. clone ( ) ) . unwrap ( ) ;
295
+ let schema = utils:: read_schema_from_file ( & stream_name) . unwrap ( ) ;
296
+ let e = event:: Event {
297
+ body,
298
+ path : option:: get_opts ( ) . local_disk_path ,
299
+ stream_name : stream_name. clone ( ) ,
300
+ schema : Bytes :: from ( schema) ,
301
+ } ;
302
+
303
+ if let Err ( e) = e. process ( ) {
304
+ return response:: ServerResponse {
305
+ msg : format ! ( "Failed to process event at index {} due to err: {}" , i, e) ,
306
+ code : StatusCode :: INTERNAL_SERVER_ERROR ,
310
307
}
311
- i += 1 ;
312
- } else {
313
- break ;
308
+ . to_http ( ) ;
314
309
}
310
+
311
+ i += 1 ;
315
312
}
316
313
317
- response:: ServerResponse {
314
+ return response:: ServerResponse {
318
315
msg : format ! ( "Successfully posted {} events" , i) ,
319
316
code : StatusCode :: OK ,
320
317
}
321
- . to_http ( )
322
- } else {
323
- let e = event:: Event {
324
- body : utils:: flatten_json_body ( body, labels) . unwrap ( ) ,
325
- path : option:: get_opts ( ) . local_disk_path ,
326
- stream_name,
327
- schema,
328
- } ;
329
- if let Err ( e) = e. process ( ) {
330
- return response:: ServerResponse {
331
- msg : format ! ( "Failed to process event due to err: {}" , e) ,
332
- code : StatusCode :: INTERNAL_SERVER_ERROR ,
333
- }
334
- . to_http ( ) ;
318
+ . to_http ( ) ;
319
+ }
320
+ let e = event:: Event {
321
+ body : utils:: flatten_json_body ( body, labels) . unwrap ( ) ,
322
+ path : option:: get_opts ( ) . local_disk_path ,
323
+ stream_name,
324
+ schema,
325
+ } ;
326
+ if let Err ( e) = e. process ( ) {
327
+ return response:: ServerResponse {
328
+ msg : format ! ( "Failed to process event due to err: {}" , e) ,
329
+ code : StatusCode :: INTERNAL_SERVER_ERROR ,
335
330
}
331
+ . to_http ( ) ;
332
+ }
336
333
337
- response:: ServerResponse {
338
- msg : "Successfully posted event" . to_string ( ) ,
339
- code : StatusCode :: OK ,
340
- }
341
- . to_http ( )
334
+ response:: ServerResponse {
335
+ msg : "Successfully posted event" . to_string ( ) ,
336
+ code : StatusCode :: OK ,
342
337
}
338
+ . to_http ( )
343
339
}
344
340
345
341
/// collect labels passed from http headers
0 commit comments