@@ -230,6 +230,64 @@ var _ = Describe("Endpoint Selection", func() {
230
230
}
231
231
})
232
232
})
233
+
234
+ It ("should only set one of Value or RawValue in header mutations to avoid Envoy 500 errors" , func () {
235
+ // Create a request that will trigger model routing and header mutations
236
+ openAIRequest := map [string ]interface {}{
237
+ "model" : "auto" ,
238
+ "messages" : []map [string ]interface {}{
239
+ {
240
+ "role" : "user" ,
241
+ "content" : "Write a Python function to sort a list" ,
242
+ },
243
+ },
244
+ }
245
+
246
+ requestBody , err := json .Marshal (openAIRequest )
247
+ Expect (err ).NotTo (HaveOccurred ())
248
+
249
+ // Create processing request
250
+ processingRequest := & ext_proc.ProcessingRequest {
251
+ Request : & ext_proc.ProcessingRequest_RequestBody {
252
+ RequestBody : & ext_proc.HttpBody {
253
+ Body : requestBody ,
254
+ },
255
+ },
256
+ }
257
+
258
+ // Create mock stream
259
+ stream := NewMockStream ([]* ext_proc.ProcessingRequest {processingRequest })
260
+
261
+ // Process the request
262
+ err = router .Process (stream )
263
+ Expect (err ).NotTo (HaveOccurred ())
264
+
265
+ // Verify response was sent
266
+ Expect (stream .Responses ).To (HaveLen (1 ))
267
+ response := stream .Responses [0 ]
268
+
269
+ // Get the request body response
270
+ bodyResp := response .GetRequestBody ()
271
+ Expect (bodyResp ).NotTo (BeNil ())
272
+
273
+ // Check header mutations if they exist
274
+ headerMutation := bodyResp .GetResponse ().GetHeaderMutation ()
275
+ if headerMutation != nil && len (headerMutation .SetHeaders ) > 0 {
276
+ for _ , headerOption := range headerMutation .SetHeaders {
277
+ header := headerOption .Header
278
+ Expect (header ).NotTo (BeNil ())
279
+
280
+ // Envoy requires that only one of Value or RawValue is set
281
+ // Setting both causes HTTP 500 errors
282
+ hasValue := header .Value != ""
283
+ hasRawValue := len (header .RawValue ) > 0
284
+
285
+ // Exactly one should be set, not both and not neither
286
+ Expect (hasValue || hasRawValue ).To (BeTrue (), "Header %s should have either Value or RawValue set" , header .Key )
287
+ Expect (! (hasValue && hasRawValue )).To (BeTrue (), "Header %s should not have both Value and RawValue set (causes Envoy 500 error)" , header .Key )
288
+ }
289
+ }
290
+ })
233
291
})
234
292
235
293
Describe ("Endpoint Configuration Validation" , func () {
0 commit comments