@Override
	public GatewayFilter apply(RequestHeaderSizeGatewayFilterFactory.Config config) {
		String errorHeaderName = config.getErrorHeaderName() != null ? config.getErrorHeaderName() : "errorMessage";
		return new GatewayFilter() {
			@Override
			public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
				ServerHttpRequest request = exchange.getRequest();
				HttpHeaders headers = request.getHeaders();
				HashMap<String, Long> longHeaders = new HashMap<>();

				for (Map.Entry<String, List<String>> headerEntry : headers.entrySet()) {
					long headerSizeInBytes = 0L;
					headerSizeInBytes += headerEntry.getKey().getBytes().length;
					List<String> values = headerEntry.getValue();
					for (String value : values) {
						headerSizeInBytes += value.getBytes().length;
					}
					if (headerSizeInBytes > config.getMaxSize().toBytes()) {
						longHeaders.put(headerEntry.getKey(), headerSizeInBytes);
					}
				}

				if (!longHeaders.isEmpty()) {
					exchange.getResponse().setStatusCode(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE);
					exchange.getResponse()
						.getHeaders()
						.add(errorHeaderName, getErrorMessage(longHeaders, config.getMaxSize()));
					return exchange.getResponse().setComplete();

				}

				return chain.filter(exchange);
			}

			@Override
			public String toString() {
				return filterToStringCreator(RequestHeaderSizeGatewayFilterFactory.this)
					.append("maxSize", config.getMaxSize())
					.toString();
			}
		};
	}
@Test
	public void toStringFormat() {
		Config config = new Config();
		config.setMaxSize(DataSize.ofBytes(1000L));
		GatewayFilter filter = new RequestHeaderSizeGatewayFilterFactory().apply(config);
		assertThat(filter.toString()).contains("maxSize").contains("1000B");
	}