http - 仅在应用层级别支持 URL 路径的概念?
问题描述
我正在编写自己的客户端和服务器,它们实现了我自己的应用程序级协议。传输层使用 TCP。对于互联网层,使用 IPv4。TCP 标头和 IPv4 标头都不包含有关 URL 路径的任何信息。TCP头包含端口,IPv4包含IP地址。谁应该包含路径?
所以,考虑这个 URL - 127.0.0.1:4444/location-path
。127.0.0.1
应该是 IPv4 的一部分。4444
应该是TCP的一部分。例如,在 Golang 中,使用标准net.Dial()
和net.Listen()
,我只能使用127.0.0.1:4444
. 使用 of127.0.0.1:4444/location-path
会抛出一个错误,这是意料之中的,因为它只支持 TCP/IP/域名解析,而/location-path
不是这三者的一部分。
- 那么,在客户端和服务器端,我应该如何处理
/location-path
客户端可以向不同位置发送请求而服务器可以为不同位置提供服务的方式? - 每个应用程序协议都应该实现自己的逻辑来处理
/location-path
?
根据RFC 1738:
url-path
The rest of the locator consists of data specific to the
scheme, and is known as the "url-path". It supplies the
details of how the specified resource can be accessed. Note
that the "/" between the host (or port) and the url-path is
NOT part of the url-path.
The url-path syntax depends on the scheme being used, as does the
manner in which it is interpreted.
那么,我可以实现自己的规则url-path
以及客户端和服务器将如何解释它?要传输它,我可以将其作为数据发送吗?
例如,我可以只定义我自己的应用程序级协议的规则proto
——将url-path
在 TCP 有效负载的前四个字节处放置?所以,proto://127.0.0.1:4444/path
会变成127.0.0.1:4444
与 TCP 有效载荷[112 97 116 104]
。
解决方案
最简单的比较方法是 HTTP。
http url 可能类似于 http://example:1234/bar
http 客户端理解该 URL。HTTP 客户端(在后台)仍然会建立标准的 TCP 连接以到达那里。
它通过抓取主机和端口部分并(暂时)丢弃其他所有内容来做到这一点。所以只有example
and1234
用在那个阶段。
TCP连接建立后,会使用路径部分作为第一行发送。
TCP 客户端不知道 URL,他们知道主机和端口。你对路径部分做什么取决于你。
推荐阅读
- snowflake-schema - How to load 533 columns of data into snowflake table?
- python - 在 Python 中操作大型 csv 文件的最快方法是什么?
- c# - 如何在c#中过滤一个sql条件
- flutter - 颤振问题这需要启用“控制流集合”实验
- powershell - powershell并排比较两个网络适配器的属性
- json - 如何获取具有动态值的嵌套json
- emacs - 无法再启动 emacs (spacemacs):无效的读取语法:无效的字节码对象
- python - Python NumPy 形状
- java - 如何找到蓝牙设备之间的距离
- javascript - Vue可以使用道具进行造型吗?(SCSS/SASS)