[6] [[URL]] における [DFN[[CODE[[[port]]]]]] は、[[ポート番号]]を表します。

;; [15] [[ポート (TCP/IP)]] も参照。

* 仕様書

[REFS[
- [161] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2016-03-31 07:16:44 +09:00]] 版) <https://html.spec.whatwg.org/#concept-origin-tuple>
- [21] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2016-03-14 22:44:13 +09:00]] 版) <https://html.spec.whatwg.org/#dom-location-port>
]REFS]

* 構文

[9] [[ポート]]は、零文字以上の[[ASCII数字]]です。

[FIG(railroad)[
= *
== [[ASCII数字]]
]FIG]

[10] [[空文字列]]もなぜか認められています。

[11] [[先導0]]も認められています。

[12] [[TCP]] や [[UDP]] で認められていない[[ポート番号]]も使えます。

* 文脈

[13] [CODE(ABNF)@en[[[port]]]] は、 [[URL]] の [[authority]] のうち、
[CODE(ABNF)@en[[[host]]]] の後の [CODE(URI)[[[:]]]] よりも後の部分です。

[14] ただし [CODE(URI)[[[:]]]] と [CODE(ABNF)@en[[[port]]]] は省略できます。

[162] [[項組起源]]の[DFN[[F[ポート]]]] [SRC[>>161]] は、
[[起源]]のうちの[[ポート]]の部分を表しています。

;; [[項組起源]]参照。

* 既定のポート

[5] [[既定のポート]]

[3] [CITE[Bug 54090 – KURL should remove default port numbers when canonicalizing urls]]
( ([TIME[2011-02-20 17:42:24 +09:00]] 版))
<https://bugs.webkit.org/show_bug.cgi?id=54090>

* TCP/IP ポート番号以外を使う URL scheme

- [4] [CODE(URI)@en[[[git+ssh:]]]]

* [CODE(DOMi)@en[Location]] インターフェイス [CODE(DOMa)@en[port]] 属性

** 性質

[23] この[[属性]]は、 [CODE(xattr IDL)@en[Unforgeable]] です [SRC[>>21]]。

** 取得器

[24] [CODE(JS)@en[location.port]] の[[取得器]]は、次のようにしなければ[MUST[なりません]]
[SRC[>>21]]。

[FIG(steps)[
= [25] [[文脈オブジェクト]]の[F[[[関係する[CODE(DOMi)@en[Document]]]]]]の[F[起源][文書の起源]]と[[入口設定群オブジェクト]]の[F[起源]]が[[同じ起源ドメイン]]でなければ、
== [26] [CODE(DOMe)@en[SecurityError]] [[例外]]を[[投げ]]、ここで停止します。
= [27] [VAR[URL]]を、[[文脈オブジェクト]]の[F[URL][Location (DOM)]] に設定します。
= [28] [VAR[URL]]の[F[ポート]]が [[null]] なら、
== [29] [[空文字列]]を返してここで停止します。
= [30] [VAR[URL]] の[F[ポート]]に[[整数の直列化]]を適用した結果を返します。
]FIG]

** 設定器

[31] [CODE(JS)@en[location.port]] の[[設定器]]は、次のようにしなければ[MUST[なりません]]
[SRC[>>21]]。

[FIG(steps)[
= [38] [VAR[入力]]を、与えられた値を [CODE(IDL)@en[USVString]] として解釈した結果に設定します。
= [32] [[文脈オブジェクト]]の[F[[[関係する[CODE(DOMi)@en[Document]]]]]]の[F[起源][文書の起源]]と[[入口設定群オブジェクト]]の[F[起源]]が[[同じ起源ドメイン]]でなければ、
== [33] [CODE(DOMe)@en[SecurityError]] [[例外]]を[[投げ]]、ここで停止します。
= [34] [VAR[複製]]を、[[文脈オブジェクト]]の[F[URL][Location (DOM)]] に設定します。
= [35] [VAR[複製]]の[F[cannot-be-a-base-URL flag]]が設定されていれば、
== [51] ここで停止します。
= [37] [VAR[複製]]の[F[cannot have a username/password/port]]が[[真]]なら、
== [50] ここで停止します。
= [44] [VAR[入力]]が[[空文字列]]なら、
== [45] [VAR[複製]]の[F[ポート][URL port]]を [CODE[null]] に設定します。
= [36] それ以外の場合、
== [46] [VAR[入力]]に[[基本URL構文解析]]を適用します。
[VAR[URL]] は[VAR[複製]]、[VAR[状態上書き]]は [[port state]] とします。
= [22] [[文脈オブジェクト]]と [VAR[複製]]について
[[[CODE(DOMi)@en[Location]]-object-setter navigate]] を実行します。
]FIG]

* 歴史

[2]
[CODE(URI)@en[http:]] [[URI]]で[[ポート番号]]を含められるようになったのは[[Line Mode Browser]]では[TIME[1991年11月][1991-11]]の0.12からのようです。

[REFS[
- [39] [CITE@en[Change History of Line Mode Browser]] 
<https://www.w3.org/LineMode/User/Features.html>
]REFS]

[1]
[CODE(URI)[[[about:]]]] とか[[ポート]]のない [[URI]]
を開いている時に [CODE(JS)@en[location.port]]
を見ると、 [CODE[134946048]] とか変な値になります。
[[DOM Inspector]] で見ると [CODE[1]] になっています。
([[Firefox]] 1.0.4)

[REFS[
- [7] [CITE@en[RFC 6943 - Issues in Identifier Comparison for Security Purposes]]
( ([TIME[2013-11-19 01:20:54 +09:00]] 版))
<http://tools.ietf.org/html/rfc6943#section-3.2>
- [8] [CITE@en[RFC 6335 - Internet Assigned Numbers Authority (IANA) Procedures for the Management of the Service Name and Transport Protocol Port Number Registry]]
([TIME[2015-03-15 10:21:32 +09:00]] 版)
<https://tools.ietf.org/html/rfc6335>
]REFS]

[FIG(quote)[
[FIGCAPTION[
[16] [CITE@en-US[I can't bind to a port – Help Center]]
([TIME[2014-11-05 00:59:51 +09:00]] 版)
<https://help.openshift.com/hc/en-us/articles/202185874-I-can-t-bind-to-a-port>
]FIGCAPTION]

> It is possible to bind to the internal IP with port range: 15000 - 35530. All other ports are reserved for specific processes to avoid conflicts. 

]FIG]

[17] >>16 0.0.0.0 や 127.0.0.1 では bind できなくて、 OPENSHIFT_DIY_IP など適当な[[環境変数]]を使う必要があるようです。

[18] [CITE@en[RFC 7605 - Recommendations on Using Assigned Transport Port Numbers]]
([TIME[2015-08-08 05:18:27 +09:00]] 版)
<https://tools.ietf.org/html/rfc7605>

[19] [CITE@en[Make port either null or a 16-bit integer. Fixes https://www.w3.org/B… · whatwg/url@c3a454c]]
([TIME[2015-08-15 11:49:19 +09:00]] 版)
<https://github.com/whatwg/url/commit/c3a454c073d6bf9f24d8ee2b5c3e6e006b943777>

[20] [CITE@en[Fix #76: a URL's port is a 16-bit _unsigned_ integer · whatwg/url@ce81868]]
([TIME[2016-01-15 18:59:56 +09:00]] 版)
<https://github.com/whatwg/url/commit/ce81868076997e749a4cc749b3fe3754068de7a8>

[40] [CITE@en[Editorial: non-relative flag got renamed · whatwg/html@d360c27]]
([TIME[2016-03-31 12:39:48 +09:00]] 版)
<https://github.com/whatwg/html/commit/d360c27d44c52390441b5910d39e898160ec016d>

[41] [CITE@en[Merge effective script origin into origin · whatwg/html@8a843f2]]
([TIME[2016-03-31 18:08:43 +09:00]] 版)
<https://github.com/whatwg/html/commit/8a843f2169a6864a3024c4329528dccb2051d275>

[42] [CITE@en[Change URL's port attribute's setter]]
([[SimonSapin]]著, [TIME[2016-10-28 19:12:19 +09:00]])
<https://github.com/whatwg/url/commit/05ffaa644bc3cd4c6694ac6db11a072781af449c>

[43] [CITE@en[Change Location/<a>/<area>'s port setter]]
([[annevk]]著, [TIME[2016-10-28 18:40:28 +09:00]])
<https://github.com/whatwg/html/commit/c62eddef0ee671f362678486f68af6adbb005740>

[47] [CITE@en[Editorial: give URL syntax components their own terms]]
([[annevk]]著, [TIME[2016-11-01 00:05:41 +09:00]])
<https://github.com/whatwg/url/commit/451696e4297c4c676fae21dbc926aeafb2477e6c>

[FIG(quote)[
[FIGCAPTION[
[48] [CITE@ja-jp[Microsoft Office Outlook 用タイム ゾーン データ更新ツールを使用してタイム ゾーンの変更に対処する方法]]
([TIME[2017-01-26 22:13:34 +09:00]])
<https://support.microsoft.com/ja-jp/help/931667/how-to-address-time-zone-changes-by-using-the-time-zone-data-update-tool-for-microsoft-office-outlook>
]FIGCAPTION]

> 夏時間の歴史に関する一般的な情報については、次の Web サイトを参照してください。
> http://www.seizethedaylight.com/dst
> http://www.npr.org:80/templates/story/story.php?storyId=4572036

]FIG]


[49] [CITE@en[Cleanup API for file and non-special URLs]]
([[annevk]]著, [TIME[2017-02-09 03:31:21 +09:00]])
<https://github.com/whatwg/url/commit/cf616f9d3fca44bd5329e992519a4236a39b0cb7>

[52] [CITE@en[Normalize port after updating scheme]]
([[TimothyGu]]著, [TIME[2017-06-30 09:05:07 +09:00]])
<https://github.com/whatwg/url/commit/0f53958338bbaec3882f902897873da59ba7e8bd>

[53] [CITE@en[Setting scheme should set port to null if it matches the default port · Issue #327 · whatwg/url]]
([TIME[2017-07-01 10:30:53 +09:00]])
<https://github.com/whatwg/url/issues/327>

[54] [CITE@en[Normalize port after updating scheme by TimothyGu · Pull Request #328 · whatwg/url]]
([TIME[2017-07-01 10:31:18 +09:00]])
<https://github.com/whatwg/url/pull/328>