728x90
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpMethod;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
@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";
}
}
728x90
'백엔드 > Spring(Boot)' 카테고리의 다른 글
스프링 HTTP 요청 파라미터 - @ModelAttribute (0) | 2021.09.09 |
---|---|
스프링 HTTP 요청 파라미터 - @RequestParam (0) | 2021.09.09 |
스프링 API 개발 기초 (0) | 2021.09.09 |
스프링 요청 매핑 (0) | 2021.09.09 |
로깅 (0) | 2021.09.08 |