@@ -61,6 +61,15 @@ function setKoaResponse(ctx, response) {
61
61
}
62
62
}
63
63
64
+ // Save response details of the primary route
65
+ ctx . resDetails = {
66
+ status : response . status ,
67
+ headers : response . headers ,
68
+ body : Buffer . isBuffer ( response . body )
69
+ ? response . body . toString ( )
70
+ : response . body
71
+ }
72
+
64
73
for ( const key in response . headers ) {
65
74
const value = response . headers [ key ]
66
75
switch ( key . toLowerCase ( ) ) {
@@ -294,6 +303,10 @@ function sendRequestToRoutes(ctx, routes, next) {
294
303
295
304
if ( route . primary ) {
296
305
ctx . primaryRoute = route
306
+
307
+ // Save request body of the primary route
308
+ ctx . reqBody = Buffer . isBuffer ( ctx . body ) ? ctx . body . toString ( ) : ctx . body
309
+
297
310
promise = sendRequest ( ctx , route , options )
298
311
. then ( response => {
299
312
logger . info ( `executing primary route : ${ route . name } ` )
@@ -658,7 +671,8 @@ function sendKafkaRequest(ctx, route) {
658
671
path : ctx . request . url ,
659
672
pattern : channel . urlPattern ,
660
673
headers : ctx . request . headers ,
661
- body : ctx . body && ctx . body . toString ( )
674
+ body : ctx . reqBody ?? '' ,
675
+ response : ctx . resDetails ?? { }
662
676
}
663
677
664
678
return producer
0 commit comments