@Slf4j
@RestController
public class RequestHeaderController {
@RequestMapping("/headers")
public String headers(HttpServletRequest request,
HttpServletResponse response,
HttpMethod httpMethod,
Locale locale,
@RequestHeader MultiValueMap<String, String> headerMap,
@RequestHeader("host") String host,
@CookieValue(value = "myCookie", required = false) String cookie) {
log.info("request={}", request);
log.info("response={}", response);
log.info("httpMethod={}", httpMethod);
log.info("locale={}", locale);
log.info("headerMap={}", headerMap);
log.info("header host={}", host);
log.info("myCookie={}", cookie);
return "ok";
}
}
HttpServletRequest
HttpServletResponse
HttpMethod
: HTTP 메서드를 조회한다. org.springframework.http.HttpMethod
Locale
: Locale 정보를 조회한다.@RequestHeader MultiValueMap headerMap
@RequestHeader("host") String host
required
defaultValue
@CookieValue(value = "myCookie", required = false) String cookie
required
defaultValue
MultiValueMap
MultiValueMap<String ,String> map = new LinkedMultiValueMap();
map.add("keyA", "value1");
map.add("keyA", "value2");
List<String> vlaues = map.get("keyA"); // [value1, value2]