5. 引用解析 (Reference Resolution)
本节描述将 URI references 解析为 absolute form 的算法.
5.1. 建立 Base URI (Establishing a Base URI)
relative references 的解析需要 base URI. base URI 可以通过多种方法建立.
5.1.1. 内容中嵌入的 Base URI (Base URI Embedded in Content)
HTML 的 <base> tag 等机制可以在 content 内指定 base URI.
5.1.2. 来自封装实体的 Base URI (Base URI from the Encapsulating Entity)
encapsulating entity (例如 MIME message) 可以定义 base URI.
5.1.3. 来自 Retrieval URI 的 Base URI (Base URI from the Retrieval URI)
如果没有其他 base URI 可用, 则使用检索该 document 所用的 URI.
5.1.4. 默认 Base URI (Default Base URI)
Applications 可以定义 default base URI.
5.2. 相对解析 (Relative Resolution)
relative reference resolution algorithm 的 pseudocode:
if R.scheme is defined then
T.scheme = R.scheme
T.authority = R.authority
T.path = remove_dot_segments(R.path)
T.query = R.query
else
if R.authority is defined then
T.authority = R.authority
T.path = remove_dot_segments(R.path)
T.query = R.query
else
if R.path is empty then
T.path = Base.path
if R.query is defined then
T.query = R.query
else
T.query = Base.query
else
if R.path starts-with "/" then
T.path = remove_dot_segments(R.path)
else
T.path = merge(Base, R.path)
T.path = remove_dot_segments(T.path)
T.query = R.query
T.authority = Base.authority
T.scheme = Base.scheme
T.fragment = R.fragment
5.3. 组件重组 (Component Recomposition)
将已解析的 components 重新组合为 URI string.
5.4. 引用解析示例 (Reference Resolution Examples)
Base URI: http://a/b/c/d;p?q
| Relative Reference | Resolved Result |
|---|---|
g | http://a/b/c/g |
./g | http://a/b/c/g |
g/ | http://a/b/c/g/ |
/g | http://a/g |
//g | http://g |
?y | http://a/b/c/d;p?y |
g?y | http://a/b/c/g?y |
#s | http://a/b/c/d;p?q#s |
../g | http://a/b/g |
../../g | http://a/g |
Next Chapter: 6. 规范化和比较 (Normalization and Comparison) - URI normalization techniques