@@ -187,10 +187,6 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, config AISecurityConfig, log
187
187
log .Debugf ("request checking is disabled" )
188
188
ctx .DontReadRequestBody ()
189
189
}
190
- if ! config .checkResponse {
191
- log .Debugf ("response checking is disabled" )
192
- ctx .DontReadResponseBody ()
193
- }
194
190
return types .ActionContinue
195
191
}
196
192
@@ -199,7 +195,7 @@ func onHttpRequestBody(ctx wrapper.HttpContext, config AISecurityConfig, body []
199
195
content := gjson .GetBytes (body , config .requestContentJsonPath ).Raw
200
196
model := gjson .GetBytes (body , "model" ).Raw
201
197
ctx .SetContext ("requestModel" , model )
202
- log .Debugf ("Raw response content is: %s" , content )
198
+ log .Debugf ("Raw request content is: %s" , content )
203
199
if len (content ) > 0 {
204
200
timestamp := time .Now ().UTC ().Format ("2006-01-02T15:04:05Z" )
205
201
randomID , _ := generateHexID (16 )
@@ -321,6 +317,11 @@ func reconvertHeaders(hs map[string][]string) [][2]string {
321
317
}
322
318
323
319
func onHttpResponseHeaders (ctx wrapper.HttpContext , config AISecurityConfig , log wrapper.Log ) types.Action {
320
+ if ! config .checkResponse {
321
+ log .Debugf ("response checking is disabled" )
322
+ ctx .DontReadResponseBody ()
323
+ return types .ActionContinue
324
+ }
324
325
headers , err := proxywasm .GetHttpResponseHeaders ()
325
326
if err != nil {
326
327
log .Warnf ("failed to get response headers: %v" , err )
@@ -399,7 +400,7 @@ func onHttpResponseBody(ctx wrapper.HttpContext, config AISecurityConfig, body [
399
400
var jsonData []byte
400
401
if config .protocolOriginal {
401
402
jsonData = []byte (denyMessage )
402
- } else if strings . Contains ( strings . Join ( hdsMap [ "content-type" ], ";" ), "event-stream" ) {
403
+ } else if isStreamingResponse {
403
404
randomID := generateRandomID ()
404
405
jsonData = []byte (fmt .Sprintf (OpenAIStreamResponseFormat , randomID , model , denyMessage , randomID , model ))
405
406
} else {
0 commit comments