@@ -46,7 +46,7 @@ func (s *Server) Process(srv extProcPb.ExternalProcessor_ProcessServer) error {
46
46
loggerVerbose := logger .V (logutil .VERBOSE )
47
47
loggerVerbose .Info ("Processing" )
48
48
49
- reader , writer := io . Pipe ()
49
+ var streamedBody [] byte
50
50
51
51
for {
52
52
select {
@@ -78,7 +78,7 @@ func (s *Server) Process(srv extProcPb.ExternalProcessor_ProcessServer) error {
78
78
}
79
79
case * extProcPb.ProcessingRequest_RequestBody :
80
80
loggerVerbose .Info ("Incoming body chunk" , "body" , string (v .RequestBody .Body ), "EoS" , v .RequestBody .EndOfStream )
81
- responses , err = s .processRequestBody (ctx , req .GetRequestBody (), writer , reader , logger )
81
+ responses , err = s .processRequestBody (ctx , req .GetRequestBody (), streamedBody , logger )
82
82
case * extProcPb.ProcessingRequest_RequestTrailers :
83
83
responses , err = s .HandleRequestTrailers (req .GetRequestTrailers ())
84
84
case * extProcPb.ProcessingRequest_ResponseHeaders :
@@ -105,35 +105,20 @@ func (s *Server) Process(srv extProcPb.ExternalProcessor_ProcessServer) error {
105
105
}
106
106
}
107
107
108
- func (s * Server ) processRequestBody (ctx context.Context , body * extProcPb.HttpBody , bufferWriter * io. PipeWriter , bufferReader * io. PipeReader , logger logr.Logger ) ([]* extProcPb.ProcessingResponse , error ) {
108
+ func (s * Server ) processRequestBody (ctx context.Context , body * extProcPb.HttpBody , streamedBody [] byte , logger logr.Logger ) ([]* extProcPb.ProcessingResponse , error ) {
109
109
loggerVerbose := logger .V (logutil .VERBOSE )
110
110
111
111
var requestBody map [string ]interface {}
112
112
if s .streaming {
113
113
// In the stream case, we can receive multiple request bodies.
114
- // To buffer the full message, we create a goroutine with a writer.Write()
115
- // call, which will block until the corresponding reader reads from it.
116
- // We do not read until we receive the EndofStream signal, and then
117
- // decode the entire JSON body.
118
- if ! body .EndOfStream {
119
- go func () {
120
- loggerVerbose .Info ("Writing to stream buffer" )
121
- _ , err := bufferWriter .Write (body .Body )
122
- if err != nil {
123
- logger .V (logutil .DEFAULT ).Error (err , "Error populating writer" )
124
- }
125
- }()
126
-
127
- return nil , nil
128
- }
114
+ streamedBody = append (streamedBody , body .Body ... )
129
115
130
116
if body .EndOfStream {
131
117
loggerVerbose .Info ("Flushing stream buffer" )
132
- decoder := json .NewDecoder ( bufferReader )
133
- if err := decoder . Decode ( & requestBody ); err != nil {
118
+ err := json .Unmarshal ( streamedBody , & requestBody )
119
+ if err != nil {
134
120
logger .V (logutil .DEFAULT ).Error (err , "Error unmarshaling request body" )
135
121
}
136
- bufferReader .Close ()
137
122
}
138
123
} else {
139
124
if err := json .Unmarshal (body .GetBody (), & requestBody ); err != nil {
0 commit comments