Skip to content

Instantly share code, notes, and snippets.

@artemptushkin
Created March 27, 2020 12:05
Show Gist options
  • Save artemptushkin/48111d49b84e16e5f2f43cf5c65d6b3b to your computer and use it in GitHub Desktop.
Save artemptushkin/48111d49b84e16e5f2f43cf5c65d6b3b to your computer and use it in GitHub Desktop.
package io.github.aptushkin.proxy.image.filter
import org.springframework.cloud.gateway.filter.GatewayFilter
import org.springframework.cloud.gateway.filter.GatewayFilterChain
import org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter.ROUTE_TO_URL_FILTER_ORDER
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils
import org.springframework.core.Ordered
import org.springframework.web.server.ServerWebExchange
import reactor.core.publisher.Mono
class ProxyForwardGatewayFilter: GatewayFilter, Ordered {
override fun getOrder(): Int = ROUTE_TO_URL_FILTER_ORDER + 1
override fun filter(exchange: ServerWebExchange, chain: GatewayFilterChain): Mono<Void> {
val target = exchange.request.uri
exchange.attributes[ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR] = target
return chain.filter(exchange)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment