[TIL] HTTP : The Definitive Guide "p53 ~ p54"

시윤·2024년 2월 18일
0

[TIL] Two Pages Per Day

목록 보기
22/108
post-thumbnail

Chapter 3. HTTP Messages

(해석 또는 이해가 잘못된 부분이 있다면 댓글로 편하게 알려주세요.)


❤️ 원문 번역 ❤️

Methods

Let’s talk in more detail about some of the basic HTTP methods, listed earlier in Table 3-1. Note that not all methods are implemented by every server. To be compliant with HTTP Version 1.1, a server need implement only the GET and HEAD methods for its resources.

  • 지금부터는 앞서 Table 3-1에 나왔던 몇 가지 HTTP 메소드에 대해 더 자세히 이야기해봅시다.

  • 우선 모든 서버가 모든 메소드를 구현하는 것은 아님에 유의합니다.

  • HTTP 버전 1.1을 준수하기 위해 서버는 리소스에 대해 오직 GET과 HEAD 메소드만을 구현하면 됩니다.

Even when servers do implement all of these methods, the methods most likely have restricted uses. For example, servers that support DELETE or PUT (described later in this section) would not want just anyone to be able to delete or store resources. These restrictions generally are set up in the server’s configuration, so they vary from site to site and from server to server.

  • 서버가 이러한 모든 메소드를 구현하다고 하더라도, 메소드가 사용을 제한했을 가능성이 높습니다.

  • 쉽게 말해 DELETE나 PUT을 지원하는 서버는 리소스를 삭제하거나 저장하기를 바라는 사용자를 원하지 않을 거라는 뜻입니다. (DELETE나 PUT 메소드는 해당 섹션의 후반부에서 설명합니다)

  • 이러한 제한은 일반적으로 서버 구성에 설정되어 있습니다. 따라서 사이트마다 서버마다 다릅니다.


Safe Methods

HTTP defines a set of methods that are called safe methods. The GET and HEAD methods are said to be safe, meaning that no action should occur as a result of an HTTP request that uses either the GET or HEAD method.

  • HTTP는 "Safe Method"라고 불리는 메소드의 집합을 정의합니다.

  • GET 메소드와 HEAD 메소드는 안전하다고 알려져 있습니다. 이때 안전하다는 것은 GET이나 HEAD 메소드를 사용하는 HTTP 요청의 결과로 아무런 액션도 발생하지 않아야 한다는 것을 뜻합니다.

By no action, we mean that nothing will happen on the server as a result of the HTTP request. For example, consider when you are shopping online at Joe’s Hardware and you click on the “submit purchase” button. Clicking on the button submits a POST request (discussed later) with your credit card information, and an action is performed on the server on your behalf. In this case, the action is your credit card being charged for your purchase.

  • 액션이 발생하지 않는다는 것은 HTTP 요청의 결과로 서버에 아무런 일도 발생하지 않음을 뜻합니다.

  • 예를 들어, Joe's Hardware에서 온라인 쇼핑을 하던 중 "submit purchase" 버튼을 눌렀다고 가정해봅시다.

  • 이 버튼을 누르면 여러분의 신용카드 정보를 가지고 POST 요청을 보냅니다. 그리고 여러분을 대신하여 액션이 수행됩니다.

  • 여기서 액션은 여러분의 소비에 대해 신용카드가 청구되는 것입니다.

There is no guarantee that a safe method won’t cause an action to be performed (in practice, that is up to the web developers). Safe methods are meant to allow HTTP application developers to let users know when an unsafe method that may cause some action to be performed is being used. In our Joe’s Hardware example, your web browser may pop up a warning message letting you know that you are making a request with an unsafe method and that, as a result, something might happen on the server (e.g., your credit card being charged).

  • 안전한 메소드로 액션이 수행되지 않는다는 보장은 없습니다. 실제로 이것은 웹 개발자에게 달려 있습니다.

  • 안전한 메소드는 HTTP 애플리케이션 개발자가 유저에게 특정 액션을 수행할지도 모르는 안전하지 않은 메소드가 사용될 때 알려줄 수 있게 한다는 데 의미가 있습니다.

  • Joe's Hardware의 예시에서 웹 브라우저는 안전하지 않은 메소드를 사용한 요청을 하고 있고, 그 결과 서버에 무언가 발생했을 것이라는 경고 메시지를 띄울 겁니다. (신용카드 청구 등)

[1] GET

GET is the most common method. It usually is used to ask a server to send a resource. HTTP/1.1 requires servers to implement this method. Figure 3-7 shows an example of a client making an HTTP request with the GET method.

  • GET은 가장 흔히 사용되는 메소드입니다.

  • 이것은 주로 서버에게 리소스를 전송할 것을 요청하기 위해 사용됩니다.

  • HTTP/1.1은 이 메소드를 구현하기 위해 서버를 필요로 합니다.

  • Figure 3-7은 클라이언트가 GET 메소드를 포함한 HTTP 요청을 만드는 예시를 보여줍니다.

[2] HEAD

The HEAD method behaves exactly like the GET method, but the server returns only the headers in the response. No entity body is ever returned. This allows a client to inspect the headers for a resource without having to actually get the resource. Using HEAD, you can:

• Find out about a resource (e.g., determine its type) without getting it.
• See if an object exists, by looking at the status code of the response.
• Test if the resource has been modified, by looking at the headers.

  • HEAD 메소드는 정확히 GET 메소드와 동일한 액션을 취하지만, 서버가 오직 헤더만을 응답으로 반환합니다.

  • 엔티티 본문은 반환되지 않습니다.

  • 이것은 클라이언트가 전체 리소스를 가져올 필요없이 헤더만으로 리소스를 검사할 수 있게 합니다.

  • HEAD를 활용하면 다음과 같은 것들을 할 수 있습니다.
    - (1) 리소스 전체를 가져오지 않고 리소스에 대해 알 수 있습니다 (유형 결정 등)
    - (2) 응답의 상태 코드를 통해 객체가 존재하는지 확인할 수 있습니다
    - (3) 헤더를 통해 리소스가 바뀐 적이 있는지 확인할 수 있습니다

Server developers must ensure that the headers returned are exactly those that a GET request would return. The HEAD method also is required for HTTP/1.1 compliance. Figure 3-8 shows the HEAD method in action.

  • 서버 개발자들은 반환되는 헤더가 GET 요청이 반환하는 헤더와 정확히 일치한다는 것을 보장해야 합니다.

  • HEAD 메소드는 HTTP/1.1을 준수하기 위해 필요한 메소드기도 합니다.

  • Figure 3-8은 HEAD 메소드의 동작 과정을 보여줍니다.


🧡 요약 정리 🧡

Methods

  • HTTP/1.1을 준수하기 위해 반드시 필요한 메소드는 GET과 HEAD
  • 모든 서버가 모든 메소드를 구현하는 것은 아니다
  • Safe Methods : HTTP 요청의 결과로 어떠한 액션도 발생되지 않는 메소드 (ex. GET, HEAD)
  • Unsafe Methods : HTTP 요청의 결과로 액션이 발생할 수 있는 메소드 (ex. DELETE, PUT)

[1] GET

  • 서버에게 리소스를 전송할 것을 요청하는 메소드

[2] HEAD

  • 서버에게 리소스의 헤더만을 전송할 것을 요청하는 메소드
  • 리소스 정보, 리소스 존재 여부, 리소스 수정 여부 등을 확인하는 데 사용

💛 감상 💛

  • 메소드 파트 포스팅을 2번으로 나눌까, 3번으로 나눌까 하다가 결국 3번으로 나누기로 했다. 오늘은 일요일이니까.. 쉬고 싶으니까...ㅎ 그리고 어제 하던 크롤링이 뭐가 잘 안 돼서 그걸 조금 더 살펴봐야 할 것 같다.

  • 컴퓨터네트워크 수업시간에 배웠던 내용이 그대로 나와서 신기했다. 그러지 않아도 교수님께서 HTTP 수업을 하실 때 이 책을 읽어보라고 강력하게 권유하셨었다. 아마 교수님은 500페이지 되는 이 두꺼운 책을 적어도 3회독은 하지 않으셨을까? 나도 얼른 그만큼의 지식을 갖춘 사람이 되고 싶다.

profile
맑은 눈의 다람쥐

0개의 댓글

관련 채용 정보