@@ -3,6 +3,7 @@ package handlers
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "strconv"
6
7
7
8
configPb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
8
9
extProcPb "github.com/envoyproxy/go-control-plane/envoy/service/ext_proc/v3"
@@ -41,6 +42,7 @@ func (s *Server) HandleRequestBody(reqCtx *RequestContext, req *extProcPb.Proces
41
42
// TODO: Read from LLMService CRD.
42
43
Critical : true ,
43
44
}
45
+ klog .V (3 ).Infof ("LLM Request: %+v" , llmReq )
44
46
45
47
// Update target models in the body.
46
48
rb ["model" ] = llmReq .ResolvedTargetModel
@@ -49,7 +51,7 @@ func (s *Server) HandleRequestBody(reqCtx *RequestContext, req *extProcPb.Proces
49
51
klog .Errorf ("Error marshaling request body: %v" , err )
50
52
return nil , fmt .Errorf ("error marshaling request body: %v" , err )
51
53
}
52
- klog .V (3 ).Infof ("Updated body: %v" , updatedBody )
54
+ klog .V (3 ).Infof ("Updated body: %v" , string ( updatedBody ) )
53
55
54
56
targetPod , err := s .scheduler .Schedule (llmReq )
55
57
if err != nil {
@@ -68,6 +70,14 @@ func (s *Server) HandleRequestBody(reqCtx *RequestContext, req *extProcPb.Proces
68
70
RawValue : []byte (targetPod .Address ),
69
71
},
70
72
},
73
+ // We need to update the content length header if the body is mutated, see Envoy doc:
74
+ // https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/http/ext_proc/v3/processing_mode.proto#enum-extensions-filters-http-ext-proc-v3-processingmode-bodysendmode
75
+ {
76
+ Header : & configPb.HeaderValue {
77
+ Key : "Content-Length" ,
78
+ RawValue : []byte (strconv .Itoa (len (updatedBody ))),
79
+ },
80
+ },
71
81
}
72
82
// Print headers for debugging
73
83
for _ , header := range headers {
@@ -81,12 +91,11 @@ func (s *Server) HandleRequestBody(reqCtx *RequestContext, req *extProcPb.Proces
81
91
HeaderMutation : & extProcPb.HeaderMutation {
82
92
SetHeaders : headers ,
83
93
},
84
- // TODO: Enable body mutation
85
- // BodyMutation: &extProcPb.BodyMutation{
86
- // Mutation: &extProcPb.BodyMutation_Body{
87
- // Body: updatedBody,
88
- // },
89
- // },
94
+ BodyMutation : & extProcPb.BodyMutation {
95
+ Mutation : & extProcPb.BodyMutation_Body {
96
+ Body : updatedBody ,
97
+ },
98
+ },
90
99
},
91
100
},
92
101
},
0 commit comments