[TIL] HTTP : The Definitive Guide "p268 ~ p272"

시윤·2025년 3월 18일

[TIL] Two Pages Per Day

목록 보기
111/146
post-thumbnail

Chapter 11. Client Identification and Cookies

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


✏️ 원문 번역


There are two different versions of cookie specifications in use: Version 0 cookies (sometimes called “Netscape cookies”), and Version 1 (“RFC 2965”) cookies. Version 1 cookies are a less widely used extension of Version 0 cookies.

  • 사용되는 쿠키 명세에는 Version 0(Netscape Cookies), Version 1(RFC 2965)의 두 가지 버전이 있습니다.

  • Version 1 쿠키는 Version 0 쿠키에 비해 널리 사용되고 있지 않습니다.
    (* 현재 Version 1 쿠키는 deprecated 되었습니다.)

Neither the Version 0 or Version 1 cookie specification is documented as part of the HTTP/1.1 specification. There are two primary adjunct documents that best describe the use of cookies, summarized in Table 11-2.

  • Version 0과 Version 1 쿠키 명세 중 어떤 것도 HTTP/1.1 명세의 일부로 문서화되지 않았습니다.

  • 쿠키의 용도를 가장 잘 설명하는 두 가지 주요 부속 문서는 Table 11-2에 요약되어 있습니다.

    • Persistent Client State: HTTP Cookies : Netscape Cookie 표준
    • RFC 2965: HTTP State Management Mechanism : Version 1 Cookie 표준


Version 0 (Netscape) Cookies

The initial cookie specification was defined by Netscape. These “Version 0” cookies defined the Set-Cookie response header, the Cookie request header, and the fields available for controlling cookies. Version 0 cookies look like this:

Set-Cookie: name=value [; expires=date] [; path=path] [; domain=domain] [; secure]
Cookie: name1=value1 [; name2=value2] ...
  • 최초의 쿠키 명세는 Netscape에 의해 정의되었습니다.

  • "Version 0" 쿠키는 Set-Cookie 응답 헤더 및 Cookie 요청 헤더, 쿠키를 제어할 수 있는 몇 가지 필드들을 정의합니다.

  • Version 0 쿠키는 위와 같은 형태를 지니고 있습니다.

The Set-Cookie header has a mandatory cookie name and cookie value. It can be followed by optional cookie attributes, separated by semicolons. The Set-Cookie fields are described in Table 11-3.

  • Set-Cookie 헤더는 쿠키의 이름과 값을 필수로 가집니다.

  • 그 뒤로는 세미콜론으로 구분되는 선택적인 쿠키 속성이 뒤따를 수 있습니다.

  • Set-Cookie 필드는 Table 11-3에서 설명하고 있습니다.

  • NAME=VALUE : NAME과 VALUE는 큰따옴표로 감싸지 않은 세미콜론과 반점, 등호, 공백 문자를 제외한 문자로 구성된 문자열입니다.

    Set-Cookie: customer=Mary
  • Expires : 쿠키가 유효한 생명주기를 정의하는 Date 문자열입니다.

    Set-Cookie: foo=bar; expires=Weekday, DD-Mon-YY HH:MM:SS GMT
  • Domain : 브라우저가 특정 도메인에 해당하는 서버 호스트에게만 쿠키를 전송합니다. 도메인이 설정되지 않은 경우 디폴트로 Set-Cookie 응답을 생성한 서버의 호스트명을 적용합니다.

    Set-Cookie: SHIPPING=FEDEX; domain="joes-hardware.com"
  • Path : 서버의 특정 문서에 쿠키를 할당할 수 있게 합니다. Path에 쓰인 접두사로 시작하는 모든 url에 쿠키가 적용됩니다.

    Set-Cookie: lastorder=00183; path=/orders
  • Secure : SSL 보안 연결을 사용중인 HTTP를 통해서만 쿠키를 전송합니다.

    Set-Cookie: private_id=519; secure

When a client sends requests, it includes all the unexpired cookies that match the domain, path, and secure filters to the site. All the cookies are combined into a
Cookie header:

Cookie: session-id=002-1145265-8016838; session-id-time=1007884800
  • 클라이언트는 요청을 전송할 때 domain과 path, 사이트의 secure 필터와 일치하는 만료되지 않은 쿠키를 전부 포함합니다.

  • 모든 쿠키는 Cookie 헤더에 결합되어 전송됩니다.


Version 1 (RFC 2965) Cookies

An extended version of cookies is defined in RFC 2965 (previously RFC 2109). This Version 1 standard introduces the Set-Cookie2 and Cookie2 headers, but it also interoperates with the Version 0 system.

  • RFC 2965(이전에는 RFC 2109)에서는 확장된 쿠키 버전을 정의하고 있습니다.

  • Version 1 표준은 Set-Cookie2와 Cookie2 헤더를 도입하였지만 Version 0 시스템과도 호환이 가능합니다.

The RFC 2965 cookie standard is a bit more complicated than the original Netscape standard and is not yet completely supported. The major changes of RFC 2965 cookies are:

• Associate descriptive text with each cookie to explain its purpose

• Support forced destruction of cookies on browser exit, regardless of expiration

• Max-Age aging of cookies in relative seconds, instead of absolute dates

• Ability to control cookies by the URL port number, not just domain and path

• The Cookie header carries back the domain, port, and path filters (if any)

• Version number for interoperability

• $ prefix in Cookie header to distinguish additional keywords from usernames

  • RFC 2965 쿠키 표준은 기존의 Netscape 표준에 비해 조금 더 정교하지만 아직까지 완벽하게 지원되지 않습니다.

  • RFC 2965 쿠키의 주요한 변화는 다음과 같습니다.

    • 쿠키의 목적을 설명하기 위한 텍스트 연결
    • 만료일시와 관계없이 브라우저를 빠져나가면 강제로 쿠키를 제거할 수 있게 지원
    • 절대날짜 대신 상대적인 시간으로 만료를 표현하는 Max-Age 기법
    • 도메인과 경로를 넘어 URL의 포트 번호를 제어할 수 있는 기능
    • 도메인, 포트 번호, 경로 필터를 다시 전달하는 Cookie 헤더
    • 호환성을 위한 버전 번호
    • 사용자와 부가적인 키워드를 구분하기 위한 Cookie 헤더의 $ 접두사

The Version 1 cookie syntax is as follows:

  • Version 1 쿠키의 문법은 아래와 같습니다.

Version 1 Set-Cookie2 Header

More attributes are available in the Version 1 cookie standard than in the Netscape standard. Table 11-4 provides a quick summary of the attributes. Refer to RFC 2965 for more detailed explanation.

  • Version 1 쿠키 표준은 Netscape 표준에 비해 더 많은 속성을 제공합니다.

  • Table 11-4는 Version 1 쿠키가 제공하는 속성을 나열한 것입니다.

  • 자세한 설명은 RFC 2965를 참고할 수 있습니다.

  • NAME=VALUE : 쿠키의 이름은 $로 시작하지 않습니다. ($ 문자는 예약어)

  • Version : 쿠키 명세의 버전을 나타내는 정수 타입의 속성입니다.

    Set-Cookie2: Part="Rocket_Launcher_0001"; Version="1"
  • Comment : 서버의 쿠키 사용 의도를 나타내는 속성입니다. 이 문자열은 UTF-8로 인코딩되어야 합니다.

  • CommentURL : 쿠키의 목적과 정책에 관한 상세 문서로 연결되는 URL 포인터입니다.

  • Discard : 클라이언트 프로그램이 종료될 때 쿠키를 제거하도록 지시합니다.

  • Domain : 브라우저가 특정 도메인에 해당하는 서버 호스트에게만 쿠키를 전송합니다. 도메인 매칭에 대한 몇 가지 새로운 규칙이 생겼습니다.

  • Max-Age : 쿠키의 생명주기를 초 단위로 설정하는 정수 속성입니다. 클라이언트는 HTTP/1.1 Age-Calculation 규칙에 따라 쿠키의 나이를 계산할 수 있습니다. 쿠키가 Max-Age보다 오래되었다면 폐기합니다.

  • Path : 서버의 특정 문서에 쿠키를 할당할 수 있게 합니다. Path에 쓰인 접두사로 시작하는 모든 url에 쿠키가 적용됩니다. Path가 지정되지 않은 경우 Set-Cookie 응답을 생성한 URL의 경로로 설정됩니다.

  • Port : 쿠키가 적용될 포트를 독립적인 키워드나 콤마로 구분된 리스트의 형태로 표현할 수 있습니다. Port라고만 적힌 경우 현재 응답중인 서버의 포트번호로만 전달될 수 있습니다.

    Set-Cookie2: foo="bar"; Version="1"; Port="80, 81, 8080"
    Set-Cookie2: foo="bar"; Version="1"; Port
  • Secure : SSL 보안 연결을 사용중인 HTTP를 통해서만 쿠키를 전송합니다.

Version 1 cookies carry back additional information about each delivered cookie, describing the filters each cookie passed. Each matching cookie must include any Domain, Port, or Path attributes from the corresponding Set-Cookie2 headers.

  • Version 1 쿠키는 쿠키가 통과한 필터를 나타냄으로써 전송된 쿠키에 관한 부가 정보를 반환할 수 있습니다.

  • 일치하는 각각의 쿠키는 Set-Cookie2 헤더와 일치하는 Domain, Port, Path 속성을 포함해야 합니다.

For example, assume the client has received these five Set-Cookie2 responses in the past from the www.joes-hardware.com web site:

Set-Cookie2: ID="29046"; Domain=".joes-hardware.com"
Set-Cookie2: color=blue
Set-Cookie2: support-pref="L2"; Domain="customer-care.joes-hardware.com"
Set-Cookie2: Coupon="hammer027"; Version="1"; Path="/tools"
Set-Cookie2: Coupon="handvac103"; Version="1"; Path="/tools/cordless"
  • 예를 들어 클라이언트가 이전에 www.joes-hardware.com 웹 사이트에서 다섯 개의 Set-Cookie2 응답을 받았다고 가정해봅시다.

If the client makes another request for path /tools/cordless/specials.html, it will pass along a long Cookie2 header like this:

Cookie: $Version="1";
		ID="29046"; $Domain=".joes-hardware.com";
		color="blue";
		Coupon="hammer027"; $Path="/tools";
		Coupon="handvac103"; $Path="/tools/cordless"
  • 클라이어언트가 /tools/cordless/specials.html에 대해 다른 요청을 생성하는 경우 Cookie2 헤더는 위와 같이 전달될 것입니다.

Notice that all the matching cookies are delivered with their Set-Cookie2 filters, and the reserved keywords begin with a dollar sign ($).

  • 모든 일치하는 쿠키는 Set-Cookie2 필터와 함께 전송되며 예약어가 달러 사인($)으로 시작한다는 점을 확인할 수 있습니다.

Version 1 Cookie2 Header and Version Negotiation

The Cookie2 request header is used to negotiate interoperability between clients and servers that understand different versions of the cookie specification. The Cookie2 header advises the server that the user agent understands new-style cookies and provides the version of the cookie standard supported (it would have made more sense to call it Cookie-Version):

Cookie2: $Version="1"
  • Cookie2 요청 헤더는 다른 버전의 쿠키 명세를 사용중인 클라이언트와 서버간 상호운용을 협의하기 위해 고안되었습니다.

  • Cookie2 헤더는 사용자 에이전트가 새로운 버전의 쿠키를 이해하고, 지원되는 쿠키 표준 버전을 제공한다는 것을 서버에 알립니다. 쿠키 버전이라고 부르는 것이 더 적절할 것입니다.
    (ㅋㅋㅋㅋ 해석이 잘 안 되네요...)

If the server understands new-style cookies, it recognizes the Cookie2 header and should send Set-Cookie2 (rather than Set-Cookie) response headers. If a client gets both a Set-Cookie and a Set-Cookie2 header for the same cookie, it ignores the old Set-Cookie header.

  • 서버가 새로운 버전의 쿠키를 이해한다면 Cookie2 헤더를 인식한 후 Set-Cookie 대신 Set-Cookie2 응답 헤더를 보내야 합니다.

  • 클라이언트가 동일한 쿠키에 대하여 Set-Cookie와 Set-Cookie2 헤더를 모두 받는다면 구버전인 Set-Cookie 헤더는 무시합니다.

If a client supports both Version 0 and Version 1 cookies but gets a Version 0 Set-Cookie header from the server, it should send cookies with the Version 0 Cookie header. However, the client also should send Cookie2: $Version=“1” to give the server indication that it can upgrade.

  • 클라이언트가 Version 0과 Version 1 쿠키를 모두 지원하지만 서버로부터 Version 0 Set-Cookie 헤더를 받은 경우 Version 0의 Cookie 헤더를 전송해야 합니다.

  • 하지만 클라이언트는 서버에게 업그레이드가 가능하다는 신호를 전달하기 위해 Cookie2: $Version="1"도 보내야 합니다.


✏️ 요약


Version 0 Cookies

  • NAME=VALUE : NAME과 VALUE는 큰따옴표로 감싸지 않은 세미콜론과 반점, 등호, 공백 문자를 제외한 문자로 구성된 문자열입니다.
    Set-Cookie: customer=Mary
  • Expires : 쿠키의 유효기간을 정의하는 Date 문자열
    Set-Cookie: foo=bar; expires=Weekday, DD-Mon-YY HH:MM:SS GMT
  • Domain : 쿠키를 전송할 도메인 (도메인이 설정되지 않은 경우 디폴트로 Set-Cookie 응답을 생성한 서버의 호스트명 적용)
    Set-Cookie: SHIPPING=FEDEX; domain="joes-hardware.com"
  • Path : 쿠키를 전송할 특정 문서 (Path에 쓰인 접두사로 시작하는 모든 url에 쿠키 적용)
    Set-Cookie: lastorder=00183; path=/orders
  • Secure : 보안 연결을 통해서만 쿠키 전송
    Set-Cookie: private_id=519; secure
  • 적용중인 모든 쿠키를 하나의 헤더에 결합하여 전송
    Cookie: session-id=12345; session-id-time=1007884800

Version 1 Cookies

: Netscape 표준을 발전시킨 쿠키 표준 (RFC 2965, deprecated)

[1] Set-Cookie2

  • Comment : 쿠키 사용 의도를 나타내는 UTF-8 문자열
  • CommentURL : 쿠키에 관한 상세 문서로 연결되는 URL 포인터
  • Discard : 클라이언트 프로그램이 종료될 때 쿠키를 제거하는 명령어
  • Domain : 쿠키를 전송할 도메인 (도메인 매칭에 대한 몇 가지 규칙 추가)
  • Max-Age : 쿠키의 유효기간을 초 단위로 설정하는 정수 속성
  • Path : 쿠키를 전송할 특정 문서 (Path가 지정되지 않은 경우 Set-Cookie 응답을 생성한 URL의 경로로 설정)
  • Port : 쿠키가 적용될 포트
  • Set-Cookie2 헤더와 일치하는 Domain, Port, Path 속성 포함
  • 달러 사인($)으로 시작하는 예약어 적용 ($Version, $Path, $Domain, ...)

[3] Cookie2

  • 다른 버전의 쿠키를 사용하는 클라이언트와 서버간 상호운용 협의를 위한 헤더

✏️ 감상


뭔가 deprecated 될 만하다

사실 Version 1 쿠키 부분을 읽으면서 왜 deprecated 됐는지 조금은 알 것 같았다. 소신발언을 하나 하자면(?) Version 1은 기능을 너무 쓸데없이 많이 늘려서 망한 거다. Version 0의 기능만으로도 충분히 많은 것들을 구현할 수 있었는데 욕심을 부리는 바람에 괜히 복잡해지기만 한 느낌이다. Version 0의 쿠키는 개발자가 따로 공부하지 않고도 쉽게 사용할 수 있는 형태인 반면 Version 1은 진입장벽이 높다. 아마 귀차니즘이 심한 개발자들이 죽어도 Version 1 쿠키를 쓰지 않아서 deprecated가 되었을 것이다. 나라도 쉽고 편한 Version 0을 두고 RFC 2965를 쓰지는 않았을 것 같다...ㅋㅋㅋㅋㅋㅋ

지금은 사용하지 않는 쿠키지만 도대체 어떤 의도를 가지고 만들어진 건지가 궁금했어서,, 나름 꼼꼼하게 해석하며 읽었다.

근데 하루종일 도서관에 있었더니 너무 피곤하다. 얼른 업로드하고 집에 가야겠다......

profile
틈틈이 두 페이지씩 원서 읽기

0개의 댓글