-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
43 lines (33 loc) · 1017 Bytes
/
response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package filter
import (
"context"
"github.com/corazawaf/coraza/v3/types"
pb "github.com/rikatz/coraza-grpc/apis/nginx"
)
func (s *GRPCHandler) handleResponse(ctx context.Context, id string, version string, headers map[string]string, body []byte, response *pb.Response) (*pb.Decision, error) {
var tx types.Transaction
// TODO: Implement the cache for responses using transaction id.
for k, v := range headers {
tx.AddResponseHeader(k, v)
}
if interruption := tx.ProcessResponseHeaders(int(response.Statuscode), "HTTP/"+version); interruption != nil {
return s.generateResponse(interruption), nil
}
if len(body) > 0 {
interruption, _, err := tx.WriteResponseBody(body)
if err != nil {
return nil, err
}
if interruption != nil {
return s.generateResponse(interruption), nil
}
}
interruption, err := tx.ProcessResponseBody()
if err != nil {
return nil, err
}
if interruption != nil {
return s.generateResponse(interruption), nil
}
return s.generateResponse(nil), nil
}