
첫번째 줄POST/saveHTTP/1.1START LINE 다음줄부터Host , Content-Type 등HTTP 메시지 구조 : 헤드(START LINE + 헤더) + 바디
헤더의 종류
- General : 메시지 전체에 적용 ex)
HTTP- Request : 요청의 내용을 좀 더 구제화하거나 요청 내용을 수정 ex)
Accept-Type,Accept-Language- Entity : 본문에 대한 내용, 없으면 생략되기도 함 ex)
Content-Length
서블릿이 HTTP 요청 메시지를 파싱한 결과를 HttpServletRequest에 저장해서 제공해 HTTP 메시지를 편리하게 조회할 수 있게함
HttpServletRequest는 생명주기가 HTTP 요청이 들어오면 만들어지고 해당 요청에 대한 처리가 끝나면 사라지는 생명주기를 가지고 있다. 이때 요청의 시작부터 끝까지 유지되는 임시 저장소 기능이 있다.
request.setAttribute(name, value)request.getAttribute(name)request.getSession(create: true)
| 메서드 이름 | 설명 |
|---|---|
| request.getMethod() | HTTP 메서드 이름 (GET, POST 등) |
| request.getProtocol() | 프로토콜 (HTTP/1.1) |
| request.getScheme() | 프로토콜 (http) |
| request.getRequestURL() | 전체 url (http://localhost:8080/request-header) |
| request.getRequestURI() | uri (/request-header) |
| request.getQueryString() | 쿼리스트링 (username=hi) |
| request.isSecure() | https 사용 유무 (true/false) |
| 메서드 이름 | 설명 |
|---|---|
| request.getHeaderNames() | 헤더 이름 목록 |
| request.getHeader(headerName) | 해당 헤더의 값 |
| request.getServerName() | Host 헤더 서버 이름 (localhost 등) |
| request.getServerPort() | Host 헤더 포트 번호 (8080 등) |
| request.getLocale(), request.getLocales() | Accept-Language 편의 조회 (ko, en, en_US 등) |
| request.getCookies() | cookie 조회 |
| cookie.getName() | 쿠키의 이름 |
| cookie.getValue() | 쿠키의 값 |
| request.getContentType() | content의 타입 (text/plain 등) |
| request.getContentLength() | content의 길이 |
| request.getCharacterEncoding() | content의 encoding ( UTF-8 등) |
출처
1. 스프링 MVC 1편 - 백엔드 웹 개발 핵심 기술
2. HTTP 메시지