[TIL] HTTP : The Definitive Guide "p30 ~ p34"

시윤·2024년 1월 31일
0

[TIL] Two Pages Per Day

목록 보기
13/107
post-thumbnail

Chapter 2. URLs and Resources

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


❤️ 원문 번역 ❤️

URL Shortcuts

Web clients understand and use a few URL shortcuts. Relative URLs are a convenient shorthand for specifying a resource within a resource. Many browsers also support “automatic expansion” of URLs, where the user can type in a key (memorable) part of a URL, and the browser fills in the rest. This is explained in “Expandomatic URLs.”

  • 웹 클라이언트는 몇 가지 URL 약어를 이해하고 적용합니다.

  • Relative URL은 리소스 내에서 특정 리소스를 지정하는 데 편리한 약어입니다.

  • 많은 브라우저가 URL의 "자동 완성 기능"을 지원합니다. 이 기능을 통해 유저는 URL의 주요 부분을 입력하고, 브라우저가 나머지 부분을 작성합니다.

  • 이것을 "Expandomatic URL"라고 합니다.


1. Relative URLs

URLs come in two flavors: absolute and relative. So far, we have looked only at absolute URLs. With an absolute URL, you have all the information you need to access a resource.

  • URL은 "절대적인 URL(Absolute URL)"과 "상대적인 URL(Relative URL)" 두 가지로 나누어집니다.

  • 지금까지 우리는 Absolute URL에 대해서만 살펴보았습니다.

  • Absolute URL을 사용하면, 여러분은 리소스에 접근하는 데 필요한 모든 정보를 가집니다.

On the other hand, relative URLs are incomplete. To get all the information needed to access a resource from a relative URL, you must interpret it relative to another URL, called its base.

  • 반면 Relative URL은 불완전합니다.

  • Relative URL로부터 리소스에 접근하기 위한 모든 정보를 얻기 위해서는 "Base"라고 불리는 다른 URL과 연관지어 해석해야 합니다.

Relative URLs are a convenient shorthand notation for URLs. If you have ever written HTML by hand, you have probably found them to be a great shortcut. Example 2-1 contains an example HTML document with an embedded relative URL.

  • Relative URL은 URL의 편리한 약어 표현입니다.

  • 여러분이 HTML을 직접 작성해본 적이 있다면, 아마 이것이 훌륭한 약어 표현이라는 것을 이해할 겁니다.

  • Example 2-1은 Relative URL이 적용된 HTML 문서 예제입니다.

In Example 2-1, we have an HTML document for the resource:

http://www.joes-hardware.com/tools.html

In the HTML document, there is a hyperlink containing the URL ./hammers.html. This URL seems incomplete, but it is a legal relative URL. It can be interpreted relative to the URL of the document in which it is found; in this case, relative to the resource /tools.html on the Joe’s Hardware web server.

  • Example 2-1에서 우리는 리소스에 대한 HTML 문서를 가지고 있습니다.
    -> http://www.joes-hardware.com/tools.html

  • HTML 문서에서 하이퍼링크는 ./hammers.html을 URL로 가지고 있습니다.

  • 이 URL은 불완전해보이지만 합법적인 Relative URL입니다. 이는 해당 URL이 나타난 문서의 URL과 연관지어 해석될 수 있습니다.

  • 위의 경우, Joe's Hardware 웹 서버에 있는 /tools.html 리소스와 연관지어 해석합니다.

The abbreviated relative URL syntax lets HTML authors omit from URLs the scheme, host, and other components. These components can be inferred by the base URL of the resource they are in. URLs for other resources also can be specified in this shorthand.

  • 축약된 형태의 Relative URL 구문은 HTML 작성자가 Scheme, Host를 비롯한 다른 구성 요소들을 URL에서 생략 가능하게 합니다.

  • 이러한 구성 요소들은 소속된 리소스의 Base URL로부터 추론 가능합니다.

  • 다른 리소스에 대한 URL 또한 Relative URL을 통해 지정될 수 있습니다.

In Example 2-1, our base URL is:

http://www.joes-hardware.com/tools.html

Using this URL as a base, we can infer the missing information. We know the resource is ./hammers.html, but we don’t know the scheme or host. Using the base URL, we can infer that the scheme is http and the host is www.joes-hardware.com. Figure 2-4 illustrates this.

  • Example 2-1에서 Base URL은 http://www.joes-hardware.com/tools.html 입니다.

  • Base URL을 활용하면, 생략된 정보를 추론할 수 있습니다.

  • 우리는 리소스가 ./hammers.html이라는 사실을 알고 있지만, Scheme이나 Host를 알지는 못합니다.

  • Base URL을 통해 Scheme이 http고 Host가 www.joes-hardware.com이라는 사실을 유추할 수 있습니다.

  • Figure 2-4가 이것을 그림으로 나타내고 있습니다.

Relative URLs are only fragments or pieces of URLs. Applications that process URLs (such as your browser) need to be able to convert between relative and absolute URLs.

  • Relative URL은 URL의 오직 일부분만을 나타냅니다.

  • URL을 프로세싱하는 브라우저와 같은 애플리케이션은 Relative URL과 Absolute URL을 서로 변환할 수 있어야 합니다.

It is also worth noting that relative URLs provide a convenient way to keep a set of resources (such as HTML pages) portable. If you use relative URLs, you can move a set of documents around and still have their links work, because they will be interpreted relative to the new base. This allows for things like mirroring content on other servers.

  • Relative URL은 HTML 페이지와 같은 리소스 집합을 휴대할 수 있는 편리한 방법을 제공한다는 점에서도 가치가 있습니다.

  • Relative URL을 사용하면 리소스 집합의 위치를 옮기더라도 여전히 링크가 잘 작동합니다. 위치가 바뀌어도 새롭게 바뀐 Base와 연관지어 해석되기 때문입니다.

  • 이것은 다른 서버에 위치한 콘텐츠를 미러링하는 것과 같은 것을 허용합니다.


1-1. Base URLs

The first step in the conversion process is to find a base URL. The base URL serves as a point of reference for the relative URL. It can come from a few places:

  • Relative-Absolute 변환 과정의 단초는 Base URL을 찾는 것입니다.

  • Base URL은 Relative URL의 레퍼런스 역할을 합니다.

  • Base URL은 다음에서 얻을 수 있습니다.

Explicitly provided in the resource

Some resources explicitly specify the base URL. An HTML document, for example, may include a <BASE> HTML tag defining the base URL by which to convert all relative URLs in that HTML document.

  • 리소스에 명시적으로 제공되는 형태
    - 몇몇 리소스들은 Base URL을 명시적으로 지정합니다.
    - 예를 들어 HTML 문서에는 Relative URL을 변환하기 위해 정의된 <BASE> 태그가 포함될 수 있습니다.

Base URL of the encapsulating resource

If a relative URL is found in a resource that does not explicitly specify a base URL, as in Example 2-1, it can use the URL of the resource in which it is embedded as a base (as we did in our example).

  • 캡슐화된 리소스의 Base URL
    - 리소스가 Base URL을 명시적으로 지정하고 있지 않다면 Example 2-1처럼 리소스의 URL을 Base URL로 활용할 수 있습니다.

No base URL

In some instances, there is no base URL. This often means that you have an absolute URL; however, sometimes you may just have an incomplete or broken URL.

  • Base URL이 없는 형태
    - 어떤 경우에는 Base URL이 존재하지 않습니다.
    - 이것은 일반적으로 Absolute URL을 가지고 있음을 의미합니다.
    - 그러나 가끔 불완전하거나 잘못된 URL을 가지고 있을지도 모릅니다.

1-2. Resolving Relative References

Previously, we showed the basic components and syntax of URLs. The next step in converting a relative URL into an absolute one is to break up both the relative and base URLs into their component pieces.

  • 이전에 URL 구문과 기본적인 구성 요소를 살펴 보았습니다.

  • Relative URL을 Absolute URL로 변환하기 위한 다음 단계는 Relative URL과 Base URL을 모두 구성 요소들로 분해하는 것입니다.

In effect, you are just parsing the URL, but this is often called decomposing the URL, because you are breaking it up into its components. Once you have broken the base and relative URLs into their components, you can then apply the algorithm pictured in Figure 2-5 to finish the conversion.

  • 실제로는 그냥 URL을 파싱하는 것인데 이것을 보통 URL을 분해한다고 이야기합니다. URL을 각각의 구성 요소들로 쪼개어 나누기 때문입니다.

  • Base URL과 Relative URL을 구성 요소들로 분해하고 나면 Figure 2-5의 알고리즘을 적용하여 변환을 완료합니다.

This algorithm converts a relative URL to its absolute form, which can then be used to reference the resource. This algorithm was originally specified in RFC 1808 and later incorporated into RFC 2396.

  • 이 알고리즘은 Relative URL을 Absolute URL로 변환하여 리소스를 참조하는 데 사용될 수 있습니다.

  • 이 알고리즘은 초기에 RFC 1808에 명시되었고, 이후 RFC 2396에 통합되었습니다.

With our ./hammers.html example from Example 2-1, we can apply the algorithm depicted in Figure 2-5:

  1. Path is ./hammers.html; base URL is http://www.joes-hardware.com/tools.html.
  2. Scheme is empty; proceed down left half of chart and inherit the base URL scheme (HTTP).
  3. At least one component is non-empty; proceed to bottom, inheriting host and port components.
  4. Combining the components we have from the relative URL (path: ./hammers.html) with what we have inherited (scheme: http, host: www.joes-hardware.com, port: 80), we get our new absolute URL: http://www.joes-hardware.com/hammers.html.
  • Figure 2-5에 나타난 알고리즘을 Example 2-1의 ./hammers.html 예제에 적용해봅시다.

      1. Path는 ./hammers.html이고 Base URL은 http://www.joes-hardware.com/tools.html 입니다.
      1. Scheme은 비어 있습니다(Relative URL). 차트의 좌중간 아래로 진행하여 Base URL의 Scheme(HTTP)를 상속합니다.
      1. 적어도 하나의 구성 요소가 non-empty이므로, 아래로 진행하여 Host와 Port 구성 요소를 상속받습니다.
      1. Relative URL(./hammers.html)에 상속받은 구성 요소(scheme: http, host: www.joes-hardware.com, port: 80)를 결합하여 새로운 Absolute URL http://www.joes-hardware.com/hammers.html 을 얻습니다.

🧡 요약 정리 🧡

URL Shortcuts

1. Relative URLs

  • Absolute URL과 달리 불완전한 형태의 URL

  • Relative URL을 Aabsolute URL로 변환 과정
    - (1) Relative URL과 Base URL의 구성 요소 파싱
    - (2) Scheme이 비어있다면 Base URL의 Scheme 상속
    - (3) 유저명, 패스워드, 호스트, 포트 중 적어도 하나의 구성 요소가 Non-empty라면 Relative URL의 구성 요소와 Base URL의 구성 요소를 결합하여 새로운 Absolute URL 획득

  • Base URL은 리소스 내부에 명시적으로 나타나거나 리소스의 URL을 그대로 활용한다

2. Expandomatic URLs

  • 다음 포스팅에서 다룰 내용

💛 감상 💛

  • Chapter 2에 들어서고 매 포스팅마다 느끼는 거지만, URL 하나를 가지고 이렇게 긴 이야기를 할 수 있다는 게 놀랍다. 사람들이 당연하게 사용하고 있는 Relative URL을 번역하기 위해, 내부에서는 꽤 복잡한 알고리즘을 작동시키고 있었다는 것을 알게 되었다.

  • 저자가 몇 번씩이나 강조했던 것처럼 URL은 파일시스템의 경로 체계와 상당히 닮은 구석이 많다. 나는 컴퓨터 왕초보 시절에 파일 경로가 뭔지도 잘 몰랐고, 이걸 전혀 신경쓰지 않았다가 호되게 당한 적이 있다. 시간이 지나고 나서 무슨 프로그램이 어디 들어가있는지 한참을 헤매고 나서야 경로의 중요성을 깨달았었다 ㅎㅎ... URL도 별반 다르지 않을 것이다. 상대 주소와 절대 주소를 정확하게 이해하고 사용해야 전처럼 헤매는 일이 없을 것이다.

  • 당연한 것을 당연하게 받아들이지 않고 항상 질문을 던지는 사람이 되자.

profile
맑은 눈의 다람쥐

0개의 댓글

관련 채용 정보