<commit_before>/*
 * Copyright 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.springframework.cloud.gateway.test;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.http.codec.multipart.Part;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.IOException;
import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/httpbin")
public class HttpBinCompatibleController {
	private static final Log log = LogFactory.getLog(HttpBinCompatibleController.class);

	@RequestMapping("/")
	public String home() {
		return "httpbin compatible home";
	}

	@RequestMapping(path = "/headers", method = {
			RequestMethod.GET, RequestMethod.POST}, produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<Map<String, Object>> headers(ServerWebExchange exchange) {
		return getHeaders(exchange);
	}

	@RequestMapping(path = "/delay/{sec}", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<Map<String, Object>> get(ServerWebExchange exchange, @PathVariable int sec) throws InterruptedException {
		int delay = Math.min(sec, 10);
		return get(exchange).delayElement(Duration.ofSeconds(delay));
	}

	@RequestMapping(path = "/anything/{anything}", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<Map<String, Object>> anything(ServerWebExchange exchange, @PathVariable String anything) {
		return get(exchange);
	}

	@RequestMapping(path = "/get", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<Map<String, Object>> get(ServerWebExchange exchange) {
		return getHeaders(exchange).map(map -> {
			HashMap<String, Object> result = new HashMap<>(map);<commit_msg>makes /anything path variable not required<commit_after>/*
 * Copyright 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.springframework.cloud.gateway.test;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.http.codec.multipart.Part;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.IOException;
import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/httpbin")
public class HttpBinCompatibleController {
	private static final Log log = LogFactory.getLog(HttpBinCompatibleController.class);

	@RequestMapping("/")
	public String home() {
		return "httpbin compatible home";
	}

	@RequestMapping(path = "/headers", method = {
			RequestMethod.GET, RequestMethod.POST}, produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<Map<String, Object>> headers(ServerWebExchange exchange) {
		return getHeaders(exchange);
	}

	@RequestMapping(path = "/delay/{sec}", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<Map<String, Object>> get(ServerWebExchange exchange, @PathVariable int sec) throws InterruptedException {
		int delay = Math.min(sec, 10);
		return get(exchange).delayElement(Duration.ofSeconds(delay));
	}

	@RequestMapping(path = "/anything/{anything}", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<Map<String, Object>> anything(ServerWebExchange exchange, @PathVariable(required = false) String anything) {
		return get(exchange);
	}

	@RequestMapping(path = "/get", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<Map<String, Object>> get(ServerWebExchange exchange) {
		return getHeaders(exchange).map(map -> {
			HashMap<String, Object> result = new HashMap<>(map);
{'fraction_non_alphanumeric': 0.10391386087848231, 'fraction_numerical': 0.003418219107844813, 'mean_word_length': 5.7653179190751445, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3409186', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1569, 'n_words': 431}