Skip to main content

6. Serializing Origins

6. Serializing Origins

This section defines how to serialize an origin to a Unicode [Unicode6] string and to an ASCII [RFC20] string.

6.1 Unicode Serialization of an Origin

The unicode-serialization of an origin is the value returned by the following algorithm:

  1. If the origin is not a scheme/host/port triple, then return the string

    null

    (i.e., the code point sequence U+006E, U+0075, U+006C, U+006C) and abort these steps.

  2. Otherwise, let result be the scheme part of the origin triple.

  3. Append the string "://" to result.

  4. Append each component of the host part of the origin triple (converted as follows) to the result, separated by U+002E FULL STOP code points ("."):

    1. If the component is an A-label, use the corresponding U-label instead (see [RFC5890] and [RFC5891]).

    2. Otherwise, use the component verbatim.

  5. If the port part of the origin triple is different from the default port for the protocol given by the scheme part of the origin triple:

    1. Append a U+003A COLON code point (":") and the given port, in base ten, to result.
  6. Return result.

6.2 ASCII Serialization of an Origin

The ascii-serialization of an origin is the value returned by the following algorithm:

  1. If the origin is not a scheme/host/port triple, then return the string

    null

    (i.e., the code point sequence U+006E, U+0075, U+006C, U+006C) and abort these steps.

  2. Otherwise, let result be the scheme part of the origin triple.

  3. Append the string "://" to result.

  4. Append the host part of the origin triple to result.

  5. If the port part of the origin triple is different from the default port for the protocol given by the scheme part of the origin triple:

    1. Append a U+003A COLON code point (":") and the given port, in base ten, to result.
  6. Return result.