004-spring Cloud Gateway-gatewayfilter Factories

Source: Internet
Author: User

First, Gatewayfilter factories

A route filter allows you to modify an incoming HTTP request or an outgoing HTTP response in some way. Path filters are scoped to a specific path. Spring Cloud Gateway contains many built-in gatewayfilter factories.

1.1. Request Header

Spring:  Cloud:    Gateway:      routes:      ID: add_request_header_route        uri:http ://example.org        Filters:        -Addrequestheader=x-request-foo, Bar

Name and value, which adds the X-request-foo:bar header to the downstream request header for all matching requests.

Remove a request header

        Filters:        -Removerequestheader=x-request-foo

1.2. Request Parameters

        Filters:        -Addrequestparameter=foo, bar

This adds foo = bar to the query string of all matching requests for downstream requests.

1.3. Add the response header

        Filters:        -Addresponseheader=x-response-foo, Bar

This adds the X-response-foo:bar header to the downstream response header for all matching requests.

Remove the response header

        Filters:        -Removeresponseheader=x-response-foo

Setting the response header

        Filters:        -Setresponseheader=x-response-foo, Bar

This gatewayfilter replaces all headers with the given name instead of the Add.

1.4. Path Prefix

        Filters:        -Prefixpath=/mypath

This causes the/MyPath prefix to be the path of all matching requests. So the request to/hello will be sent to/Mypath/hello.

1.5. Original Host Header

Without parameters, this filter sets the host header that the route filter will check for the request properties to determine whether the original host header should be sent, rather than the HTTP client.

        Filters:        -Preservehostheader

1.6. redirect

        Filters:        -redirectto=302, http://acme.org

This sends the status 302 with the location:http://acme.org header to perform the redirection.

1.7. Rewrite the path

        predicates:        -Path=/foo*        /* Filters:        -rewritepath=/foo/(?< segment>.*),/$\{segment}

For the/Foo/bar request path, this sets the path to/bar before the downstream request is made. Note Because of the YAML specification, $ \ is replaced by $.

1.8. Save session

        predicates:        -Path=/foo*/*        filters:        -savesession

1.9. Path template

SetPath Gatewayfilter Factory takes path template parameters. It provides an easy way to manipulate request paths by allowing templated path segments.

        predicates:        -path=/foo/{segment}        filters:        -setpath=/{segment}

For the/Foo/bar request path, this sets the path to/bar before the downstream request is made.

1.10. Setting the response status

Spring:  Cloud:    Gateway:      routes:      ID: setstatusstring_route        uri:http:  //example.org        Filters:        -setstatus=bad_request       ID : Setstatusint_route        uri:http://example.org        Filters:        -setstatus=401

1.11. Request parameter Stripping

The parts parameter indicates the number of parts in the path that were stripped from the request before the request was sent to the downstream.

        predicates:        -path=/name*/*        filters:        -stripprefix=2

When a request is made through the gateway to/Name/bar/foo, the request to Nameservice will resemble http://Nameservice/foo.

1.12. Retry

Retries: Retry: The number of retries that should be attempted

Statuses: Status: The HTTP status code that should be retried, using the Org.springframework.http.HttpStatus representation

Methods: Method: The HTTP method that should be retried, using Org.springframework.http.HttpMethod to represent

Series: Family: A series of status codes to retry, using Org.springframework.http.HttpStatus.Series to represent

      routes:      ID: retry_test        uri:http://Localhost:8080/flakey          predicates:        -host=*. retry.com        Filters:        - name:retry          args :            3            statuses:bad_gateway

1.13, Hystrix Gatewayfilter Factory

Https://cloud.spring.io/spring-cloud-static/Finchley.SR1/single/spring-cloud.html#_hystrix_gatewayfilter_factory

1.14. Request Speed limit

Requestratelimiter Gatewayfilter Factory

1.15. Safety Head

Secureheaders Gatewayfilter Factory

004-spring Cloud Gateway-gatewayfilter Factories

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.