Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing of HTTPPathModifier #1165

Closed
hzxuzhonghu opened this issue May 18, 2022 · 4 comments · Fixed by #1162
Closed

Confusing of HTTPPathModifier #1165

hzxuzhonghu opened this issue May 18, 2022 · 4 comments · Fixed by #1162
Labels
kind/documentation Categorizes issue or PR as related to documentation. kind/feature Categorizes issue or PR as related to a new feature.

Comments

@hzxuzhonghu
Copy link
Member

type HTTPPathModifier struct {
// Type defines the type of path modifier.
//
// <gateway:experimental>
// +kubebuilder:validation:Enum=Absolute;ReplacePrefixMatch
Type HTTPPathModifierType `json:"type"`
// Substitution defines the HTTP path value to substitute. An empty value
// ("") indicates that the portion of the path to be changed should be
// removed from the resulting path. For example, a request to "/foo/bar"
// with a prefix match of "/foo" would be modified to "/bar".
//
// <gateway:experimental>
// +kubebuilder:validation:MaxLength=1024
Substitution string `json:"substitution"`

How could i rewrite url like /foo/bar prefixed with foo to /bar , it does not allow setting match value

@hzxuzhonghu hzxuzhonghu added the kind/feature Categorizes issue or PR as related to a new feature. label May 18, 2022
@robscott
Copy link
Member

Thanks for the question @hzxuzhonghu! I think #1124 and #1162 will help make this a bit clearer. The value that is being replaced is from the path match. So if you want to use a prefix match to rewrite requests starting with /foo/bar to /bar, you could use config like this:

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
  name: http-filter-rewrite
spec:
  rules:
    - matches:
      - path:
          type: PathPrefix
          value: /foo/bar
      filters:
      - type: URLRewrite
         urlRewrite:
           path:
             type: ReplacePathPrefix
             replacePathPrefix: /bar
      backendRefs:
      - name: example-svc
        weight: 1
        port: 80

@robscott robscott added the kind/documentation Categorizes issue or PR as related to documentation. label May 18, 2022
@robscott robscott linked a pull request May 18, 2022 that will close this issue
@hzxuzhonghu
Copy link
Member Author

So what will happen if no path match is specified? Because they are two different structs, and so how can you make users understand this well.

@robscott
Copy link
Member

Good question. That would be an invalid configuration. We should probably add some webhook validation to prevent that from happening.

@robscott
Copy link
Member

x-ref #1166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Categorizes issue or PR as related to documentation. kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants