File tree 1 file changed +4
-3
lines changed
1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -68,21 +68,22 @@ export class SSEServerTransport implements Transport {
68
68
async handlePostMessage (
69
69
req : IncomingMessage ,
70
70
res : ServerResponse ,
71
+ parsedBody ?: unknown ,
71
72
) : Promise < void > {
72
73
if ( ! this . _sseResponse ) {
73
74
const message = "SSE connection not established" ;
74
75
res . writeHead ( 500 ) . end ( message ) ;
75
76
throw new Error ( message ) ;
76
77
}
77
78
78
- let body : string ;
79
+ let body : string | unknown ;
79
80
try {
80
81
const ct = contentType . parse ( req . headers [ "content-type" ] ?? "" ) ;
81
82
if ( ct . type !== "application/json" ) {
82
83
throw new Error ( `Unsupported content-type: ${ ct } ` ) ;
83
84
}
84
85
85
- body = await getRawBody ( req , {
86
+ body = parsedBody ?? await getRawBody ( req , {
86
87
limit : MAXIMUM_MESSAGE_SIZE ,
87
88
encoding : ct . parameters . charset ?? "utf-8" ,
88
89
} ) ;
@@ -93,7 +94,7 @@ export class SSEServerTransport implements Transport {
93
94
}
94
95
95
96
try {
96
- await this . handleMessage ( JSON . parse ( body ) ) ;
97
+ await this . handleMessage ( typeof body === 'string' ? JSON . parse ( body ) : body ) ;
97
98
} catch {
98
99
res . writeHead ( 400 ) . end ( `Invalid message: ${ body } ` ) ;
99
100
return ;
You can’t perform that action at this time.
0 commit comments