最近在看直播的問題, 必須看一些 RFC 的文件. 在此把相關的部分都整理出來.
最基礎的一本是 RFC 1738 Uniform Resource Locators (URL), 一個 URL 可以分成兩個部分:
<scheme>:<scheme-specific-part>
Scheme 可以翻譯成 "系統" 或 "範型", 它包括以下幾種內容, 相當於是大分類. http 或是 ftp 都是常用的 scheme.
scheme | 說明 |
ftp | File Transfer protocol |
http | Hypertext Transfer Protocol |
gopher | The Gopher protocol |
mailto | Electronic mail address |
news | USENET news |
nntp | USENET news using NNTP access |
telnet | Reference to interactive sessions |
wais | Wide Area Information Servers |
file | Host-specific file names |
prospero | Prospero Directory Service |
至於 scheme-specific-part 的部份, 會依據不同的 scheme 而有不同的格式變化.下面就進入 RFC1808 Relative Uniform Resource Locators 的 URL 格式, 和前面 RFC1738 最大的差異在於:Relative – "相對性".
它基本的長相是這樣.
<scheme>://<net_loc>/<path>;<params>?<query>#<fragment>
scheme ":" ::= scheme name. "//" net_loc ::= network location and login information. "/" path ::= URL path. ";" params ::= object parameters. "?" query ::= query information. "#" fragment ::= fragment identifier.
為了簡化描述, 我們直接看簡化版的例子, scheme, net_loc, params, query (component), fragment 改用 http://, a, p, q, f 代替. Path 的部份因為要多給幾層才能看出端倪, 所以給三個符號 b, c, d. d 可以視為檔名. 此後 URL 變成 <URL:http://a/b/c/d;p?q#f>
於是我們有下列的表達方式:
g:h = <URL:g:h>
g = <URL:http://a/b/c/g>
./g = <URL:http://a/b/c/g>
g/ = <URL:http://a/b/c/g/>
/g = <URL:http://a/g>
//g = <URL:http://g>
?y = <URL:http://a/b/c/d;p?y>
g?y = <URL:http://a/b/c/g?y>
g?y/./x = <URL:http://a/b/c/g?y/./x>
#s = <URL:http://a/b/c/d;p?q#s>
g#s = <URL:http://a/b/c/g#s>
g#s/./x = <URL:http://a/b/c/g#s/./x>
g?y#s = <URL:http://a/b/c/g?y#s>
;x = <URL:http://a/b/c/d;x>
g;x = <URL:http://a/b/c/g;x>
g;x?y#s = <URL:http://a/b/c/g;x?y#s>
. = <URL:http://a/b/c/>
./ = <URL:http://a/b/c/>
.. = <URL:http://a/b/>
../ = <URL:http://a/b/>
../g = <URL:http://a/b/g>
../.. = <URL:http://a/>
../../ = <URL:http://a/>
../../g = <URL:http://a/g>
由於 a 是 network location, 無論往上幾層, 都不能高過於 http://a/, 其他的都可以直觀地了解. 大致瞭解了比較常聽見的 URL, 接著看看比較陌生的 RFC3896 Uniform Resource Identifier (URI): Generic Syntax.
其實 RFC3896 的內容和 RFC1808 有些重複, 原因是 URI 包含了 URL 和 URN (Uniform Resource Name), 所以 RFC1808 只是 RFC3896 的一部份. 一個 URI 可能是一個 locator (URL), 一個 name (URN), 或是 locator + name. 舉例子來說, 它們會像這樣:
foo://example.com:8042/over/there?name=ferret#nose _/ ______________/_________/ _________/ __/ | | | | | scheme authority path query fragment | _____________________|__ / / urn:example:animal:ferret:nose
大家應該很容易就發現, URI 的說明, 簡直就和 URL 一樣嘛! 只不過 URL 用 network location 代替了 URI 的 authority, URL 有 parameters, 而 URI 把它併入了 path. 基本上, URI 著重在 "標識" – identifier, URL 著重在位置 – location, 即使兩者的長相完全一樣.
參考 [ref 4] 的說法, 若是 PPS 把一部 "大話西遊 – 月光寶盒" 的電影, 同時放在伺服器 1, 2, … 和伺服器 100, 以便給不同地區的使用者觀看. 這些片子可以理解為同一個 URI, 但它們的 URL 各自不同. 另外一部同時放在伺服器 1 的電影: "大話西遊 – 仙履奇緣", 就要理解為另外一個 URI 了.
[ref]
1. http://www.ietf.org/rfc/rfc1738.txt
2. http://www.ietf.org/rfc/rfc1808.txt