Skip to content

Commit 8dd4dd7

Browse files
committed
fix: use clearroute cache and raw value for header mutation
Signed-off-by: bitliu <[email protected]>
1 parent a71922c commit 8dd4dd7

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/semantic-router/pkg/extproc/request_handler.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,18 @@ func (r *OpenAIRouter) handleModelRouting(openAIRequest *openai.ChatCompletionNe
385385
if selectedEndpoint != "" {
386386
setHeaders = append(setHeaders, &core.HeaderValueOption{
387387
Header: &core.HeaderValue{
388-
Key: "x-semantic-destination-endpoint",
389-
Value: selectedEndpoint,
388+
Key: "x-semantic-destination-endpoint",
389+
Value: selectedEndpoint,
390+
RawValue: []byte(selectedEndpoint),
390391
},
391392
})
392393
}
393394
if actualModel != "" {
394395
setHeaders = append(setHeaders, &core.HeaderValueOption{
395396
Header: &core.HeaderValue{
396-
Key: "x-selected-model",
397-
Value: actualModel,
397+
Key: "x-selected-model",
398+
Value: actualModel,
399+
RawValue: []byte(actualModel),
398400
},
399401
})
400402
}
@@ -414,9 +416,10 @@ func (r *OpenAIRouter) handleModelRouting(openAIRequest *openai.ChatCompletionNe
414416
Response: &ext_proc.ProcessingResponse_RequestBody{
415417
RequestBody: &ext_proc.BodyResponse{
416418
Response: &ext_proc.CommonResponse{
417-
Status: ext_proc.CommonResponse_CONTINUE,
418-
HeaderMutation: headerMutation,
419-
BodyMutation: bodyMutation,
419+
ClearRouteCache: true,
420+
Status: ext_proc.CommonResponse_CONTINUE_AND_REPLACE,
421+
HeaderMutation: headerMutation,
422+
BodyMutation: bodyMutation,
420423
},
421424
},
422425
},
@@ -583,16 +586,16 @@ func (r *OpenAIRouter) updateRequestWithTools(openAIRequest *openai.ChatCompleti
583586
if selectedEndpoint != "" {
584587
setHeaders = append(setHeaders, &core.HeaderValueOption{
585588
Header: &core.HeaderValue{
586-
Key: "x-semantic-destination-endpoint",
587-
Value: selectedEndpoint,
589+
Key: "x-semantic-destination-endpoint",
590+
RawValue: []byte(selectedEndpoint),
588591
},
589592
})
590593
}
591594
if actualModel != "" {
592595
setHeaders = append(setHeaders, &core.HeaderValueOption{
593596
Header: &core.HeaderValue{
594-
Key: "x-selected-model",
595-
Value: actualModel,
597+
Key: "x-selected-model",
598+
RawValue: []byte(actualModel),
596599
},
597600
})
598601
}

src/semantic-router/pkg/utils/http/response.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ func CreatePIIViolationResponse(model string, deniedPII []string) *ext_proc.Proc
5555
SetHeaders: []*core.HeaderValueOption{
5656
{
5757
Header: &core.HeaderValue{
58-
Key: "content-type",
59-
Value: "application/json",
58+
Key: "content-type",
59+
RawValue: []byte("application/json"),
6060
},
6161
},
6262
{
6363
Header: &core.HeaderValue{
64-
Key: "x-pii-violation",
65-
Value: "true",
64+
Key: "x-pii-violation",
65+
RawValue: []byte("true"),
6666
},
6767
},
6868
},
@@ -162,14 +162,14 @@ func CreateCacheHitResponse(cachedResponse []byte) *ext_proc.ProcessingResponse
162162
SetHeaders: []*core.HeaderValueOption{
163163
{
164164
Header: &core.HeaderValue{
165-
Key: "content-type",
166-
Value: "application/json",
165+
Key: "content-type",
166+
RawValue: []byte("application/json"),
167167
},
168168
},
169169
{
170170
Header: &core.HeaderValue{
171-
Key: "x-cache-hit",
172-
Value: "true",
171+
Key: "x-cache-hit",
172+
RawValue: []byte("true"),
173173
},
174174
},
175175
},

0 commit comments

Comments
 (0)