AlinsRan opened a new pull request, #2762:
URL: https://github.com/apache/apisix-ingress-controller/pull/2762

   ## Summary
   
   Closes #399
   
   Add `Body` as a new scope value for `ApisixRouteHTTPMatchExprSubject`, 
enabling request body matching in `ApisixRoute` HTTP match expressions.
   
   ## How it works
   
   When `scope: Body` is used, the subject maps to APISIX's `post_arg.<name>` 
variable. This variable supports:
   
   - `application/json`
   - `application/x-www-form-urlencoded`
   - `multipart/form-data`
   
   Dot-notation JSON path expressions are also supported (e.g., 
`model.version`, `messages[*].role`).
   
   **Example:**
   
   ```yaml
   exprs:
   - subject:
       scope: Body
       name: action        # matches form field or JSON key
     op: Equal
     value: login
   ```
   
   ```yaml
   exprs:
   - subject:
       scope: Body
       name: model.version  # dot-notation JSON path
     op: Equal
     value: gpt-4
   ```
   
   ## Changes
   
   - `api/v2/shared_types.go`: add `ScopeBody = "Body"` constant
   - `api/v2/apisixroute_types.go`:
     - Add `case ScopeBody` in `ToVars()` mapping to `post_arg.<name>`
     - Add `Body` to `+kubebuilder:validation:Enum` on `Scope` field
     - Add `+kubebuilder:validation:XValidation` CEL rule: `name` is required 
when `scope` is not `Path`
     - Make `Name` field optional (`omitempty`) so `Path` scope works without 
providing a name
   - `api/v2/apisixroute_types_test.go`: unit tests for Body scope and CEL 
validation
   - `config/crd/bases/apisix.apache.org_apisixroutes.yaml`: regenerated
   - `docs/en/latest/reference/api-reference.md`: regenerated
   - `test/e2e/crds/v2/route.go`: e2e tests for urlencoded form field and JSON 
nested path matching
   
   ## Testing
   
   Unit tests:
   ```
   go test ./api/v2/... -run "TestToVars|TestCEL"
   ```
   
   E2e tests added:
   - `Test ApisixRoute match by body vars (urlencoded)`: POST form field 
`action=login`
   - `Test ApisixRoute match by body vars (JSON nested path)`: POST JSON 
`{"model": {"version": "gpt-4"}}` with `model.version` dot-notation


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to