@Test public void toStringFormat() { Config config = new Config(); config.setMaxSize(DataSize.ofBytes(1000L)); GatewayFilter filter = new RequestHeaderSizeGatewayFilterFactory().apply(config); assertThat(filter.toString()).contains("max").contains("1000B"); }
@Override public GatewayFilter apply(RequestHeaderSizeGatewayFilterFactory.Config config) { return new GatewayFilter() { @Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { ServerHttpRequest request = exchange.getRequest(); HttpHeaders headers = request.getHeaders(); Long headerSizeInBytes = 0L; for (Map.Entry<String, List<String>> headerEntry : headers.entrySet()) { List<String> values = headerEntry.getValue(); for (String value : values) { headerSizeInBytes += Long.valueOf(value.getBytes().length); } } if (headerSizeInBytes > config.getMaxSize().toBytes()) { exchange.getResponse().setStatusCode(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE); exchange.getResponse().getHeaders().add("errorMessage", getErrorMessage(headerSizeInBytes, config.getMaxSize())); return exchange.getResponse().setComplete(); } return chain.filter(exchange); } @Override public String toString() { return filterToStringCreator(RequestHeaderSizeGatewayFilterFactory.this) .append("max", config.getMaxSize()).toString(); } }; }
RequestHeaderSizeGatewayFilterFactory extends AbstractGatewayFilterFactory<RequestHeaderSizeGatewayFilterFactory.Config> { @Override public GatewayFilter apply(RequestHeaderSizeGatewayFilterFactory.Config config) { return new GatewayFilter() { @Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { ServerHttpRequest request = exchange.getRequest(); HttpHeaders headers = request.getHeaders(); Long headerSizeInBytes = 0L; for (Map.Entry<String, List<String>> headerEntry : headers.entrySet()) { List<String> values = headerEntry.getValue(); for (String value : values) { headerSizeInBytes += Long.valueOf(value.getBytes().length); } } if (headerSizeInBytes > config.getMaxSize().toBytes()) { exchange.getResponse().setStatusCode(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE); exchange.getResponse().getHeaders().add("errorMessage", getErrorMessage(headerSizeInBytes, config.getMaxSize())); return exchange.getResponse().setComplete(); } return chain.filter(exchange); } @Override public String toString() { return filterToStringCreator(RequestHeaderSizeGatewayFilterFactory.this) .append("max", config.getMaxSize()).toString(); } }; } }
RequestHeaderSizeGatewayFilterFactory extends AbstractGatewayFilterFactory<RequestHeaderSizeGatewayFilterFactory.Config> { @Override public GatewayFilter apply(RequestHeaderSizeGatewayFilterFactory.Config config) { return new GatewayFilter() { @Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { ServerHttpRequest request = exchange.getRequest(); HttpHeaders headers = request.getHeaders(); Long headerSizeInBytes = 0L; for (Map.Entry<String, List<String>> headerEntry : headers.entrySet()) { List<String> values = headerEntry.getValue(); for (String value : values) { headerSizeInBytes += Long.valueOf(value.getBytes().length); } } if (headerSizeInBytes > config.getMaxSize().toBytes()) { exchange.getResponse().setStatusCode(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE); exchange.getResponse().getHeaders().add("errorMessage", getErrorMessage(headerSizeInBytes, config.getMaxSize())); return exchange.getResponse().setComplete(); } return chain.filter(exchange); } @Override public String toString() { return filterToStringCreator(RequestHeaderSizeGatewayFilterFactory.this) .append("max", config.getMaxSize()).toString(); } }; } RequestHeaderSizeGatewayFilterFactory(); }
RequestHeaderSizeGatewayFilterFactory extends AbstractGatewayFilterFactory<RequestHeaderSizeGatewayFilterFactory.Config> { @Override public GatewayFilter apply(RequestHeaderSizeGatewayFilterFactory.Config config) { return new GatewayFilter() { @Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { ServerHttpRequest request = exchange.getRequest(); HttpHeaders headers = request.getHeaders(); Long headerSizeInBytes = 0L; for (Map.Entry<String, List<String>> headerEntry : headers.entrySet()) { List<String> values = headerEntry.getValue(); for (String value : values) { headerSizeInBytes += Long.valueOf(value.getBytes().length); } } if (headerSizeInBytes > config.getMaxSize().toBytes()) { exchange.getResponse().setStatusCode(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE); exchange.getResponse().getHeaders().add("errorMessage", getErrorMessage(headerSizeInBytes, config.getMaxSize())); return exchange.getResponse().setComplete(); } return chain.filter(exchange); } @Override public String toString() { return filterToStringCreator(RequestHeaderSizeGatewayFilterFactory.this) .append("max", config.getMaxSize()).toString(); } }; } RequestHeaderSizeGatewayFilterFactory(); @Override GatewayFilter apply(RequestHeaderSizeGatewayFilterFactory.Config config); }
RequestHeaderSizeGatewayFilterFactory extends AbstractGatewayFilterFactory<RequestHeaderSizeGatewayFilterFactory.Config> { @Override public GatewayFilter apply(RequestHeaderSizeGatewayFilterFactory.Config config) { return new GatewayFilter() { @Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { ServerHttpRequest request = exchange.getRequest(); HttpHeaders headers = request.getHeaders(); Long headerSizeInBytes = 0L; for (Map.Entry<String, List<String>> headerEntry : headers.entrySet()) { List<String> values = headerEntry.getValue(); for (String value : values) { headerSizeInBytes += Long.valueOf(value.getBytes().length); } } if (headerSizeInBytes > config.getMaxSize().toBytes()) { exchange.getResponse().setStatusCode(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE); exchange.getResponse().getHeaders().add("errorMessage", getErrorMessage(headerSizeInBytes, config.getMaxSize())); return exchange.getResponse().setComplete(); } return chain.filter(exchange); } @Override public String toString() { return filterToStringCreator(RequestHeaderSizeGatewayFilterFactory.this) .append("max", config.getMaxSize()).toString(); } }; } RequestHeaderSizeGatewayFilterFactory(); @Override GatewayFilter apply(RequestHeaderSizeGatewayFilterFactory.Config config);  }