5. Reference Resolution (引用解析)
本节描述将URI引用解析为绝对形式的算法。
5.1. Establishing a Base URI (建立基URI)
相对引用的解析需要基URI。基URI可以通过多种方式建立。
5.1.1. Base URI Embedded in Content (内容中嵌入的基URI)
HTML的<base>标签等机制可以在内容中指定基URI。
5.1.2. Base URI from the Encapsulating Entity (来自封装实体的基URI)
封装实体(如MIME消息)可以定义基URI。
5.1.3. Base URI from the Retrieval URI (来自检索URI的基URI)
如果没有其他基URI,则使用检索文档的URI。
5.1.4. Default Base URI (默认基URI)
应用程序可以定义默认基URI。
5.2. Relative Resolution (相对解析)
相对引用解析算法的伪代码:
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 (组件重组)
将解析后的组件重新组合成URI字符串。
5.4. Reference Resolution Examples (引用解析示例)
基URI: http://a/b/c/d;p?q
| 相对引用 | 解析结果 |
|---|---|
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 |