(해석 또는 이해가 잘못된 부분이 있다면 댓글로 편하게 알려주세요.)
All HTTP messages fall into two types: request messages and response messages. Request messages request an action from a web server. Response messages carry results of a request back to a client. Both request and response messages have the same basic message structure. Figure 3-4 shows request and response messages to get a GIF image.
모든 HTTP 메시지는 요청 메시지와 응답 메시지의 두 가지 유형으로 나뉩니다.
요청 메시지는 웹 서버에게 특정 액션을 요청합니다.
응답 메시지는 요청의 결과를 클라이언트에게 전달합니다.
두 메시지는 모두 동일한 기본 구조를 가지고 있습니다.
Figure 3-4는 GIF 이미지를 주고받기 위한 요청 및 응답 메시지를 나타냅니다.
Here’s the format for a request message:
<method> <request-URL> <version> <headers> <entity-body>
Here’s the format for a response message (note that the syntax differs only in the start line):
<version> <status> <reason-phrase> <headers> <entity-body>
Here’s a quick description of the various parts:
method
The action that the client wants the server to perform on the resource. It is a single word, like “GET,” “HEAD,” or “POST”. We cover the method in detail later in this chapter.
request-URL
A complete URL naming the requested resource, or the path component of the URL. If you are talking directly to the server, the path component of the URL is usually okay as long as it is the absolute path to the resource—the server can assume itself as the host/port of the URL. Chapter 2 covers URL syntax in detail.
version
The version of HTTP that the message is using. Its format looks like:
HTTP/<major>.<minor>
where major and minor both are integers. We discuss HTTP versioning a bit more later in this chapter.
HTTP/<major>.<minor>
입니다.status-code
A three-digit number describing what happened during the request. The first digit of each code describes the general class of status (“success,” “error,” etc.). An exhaustive list of status codes defined in the HTTP specification and their meanings is provided later in this chapter.
reason-phrase
A human-readable version of the numeric status code, consisting of all the text until the end-of-line sequence. Example reason phrases for all the status codes defined in the HTTP specification are provided later in this chapter. The reason phrase is meant solely for human consumption, so, for example, response lines containing “HTTP/1.0 200 NOT OK” and “HTTP/1.0 200 OK” should be treated as equivalent success indications, despite the reason phrases suggesting otherwise.
headers
Zero or more headers, each of which is a name, followed by a colon (:), followed by optional whitespace, followed by a value, followed by a CRLF. The headers are terminated by a blank line (CRLF), marking the end of the list of headers and the beginning of the entity body. Some versions of HTTP, such as HTTP/1.1, require certain headers to be present for the request or response message to be valid. The various HTTP headers are covered later in this chapter.
entity-body
The entity body contains a block of arbitrary data. Not all messages contain entity bodies, so sometimes a message terminates with a bare CRLF. We discuss entities in detail in Chapter 15.
Figure 3-5 demonstrates hypothetical request and response messages.
Note that a set of HTTP headers should always end in a blank line (bare CRLF), even if there are no headers and even if there is no entity body. Historically, however, many clients and servers (mistakenly) omitted the final CRLF if there was no entity body. To interoperate with these popular but noncompliant implementations, clients and servers should accept messages that end without the final CRLF.
헤더가 없거나 엔티티 본문이 없더라도, HTTP 헤더는 항상 공백 라인 (CRLF)로 끝나야 한다는 것에 주의합니다.
그러나 역사적으로 많은 클라이언트와 서버가 엔티티 본문이 없을 때 마지막 CRLF를 실수로 생략하였습니다.
이처럼 자주 사용되지만 어설픈 구현과 상호 소통하기 위해서는 클라이언트와 서버가 마지막 CRLF가 없는 메시지도 받아들일 수 있어야 합니다.
<method> <request-URL> <version>
<headers>
<entity-body>
<version> <status> <reason-phrase>
<headers>
<entity-body>
설 연휴를 거하게 쉬고 왔더니 일과 공부가 손에 안 잡힌다. 항상 긴 휴가를 보내고 오면 원래의 페이스를 잃어버리는 느낌이다. 그렇지만 휴가에 쉬어야지 일을 할 수도 없고...ㅎ 그냥 다시 부지런히 감을 찾는 수밖에 없겠다.
이번 챕터부터는 본격적으로 요청 메시지와 응답 메시지의 형태에 대해 살핀다. 평소에 스프링부트로 API를 이것저것 만드는 취미가 있는데, 사실 API를 개발하면서 수도 없이 많이 접했던 내용이다. 알던 내용이지만 한 번 더 살펴보면서 놓치고 있는 부분은 없는지 꼼꼼히 확인하려 한다.