最小的 HTTP 和 HTTPS 数据请求是多少
假设我想使用 HTTP 协议从服务器获取一个字节,并且我想最小化所有内容。没有标题,只是 http://myserver.com/b,其中 b 是一个包含一个字符的文本文件,或者更好的是 b 只是一个字符(不确定这是否可能)。
有没有办法用 Apache 来做到这一点?完整的 http 和完整的 HTTPS 事务所需的最小数据量是多少?
或者,如果数据效率更高,则可以仅通过头请求来完成事务。
Lets say I want to GET one byte from a server using the HTTP protocol and I want to minimize everything. No headers just http://myserver.com/b, where b is a text file with one character in it, or better still b is just one character (not sure if that is possible).
Is there a way to do this with Apache and what is the smallest possible amount of data that is required for complete http and, complete HTTPS transactions?
Alternatively, the transaction could be done with just a head request if that is more data efficient.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您计划使用 HTTP/1.1(如果您最终使用虚拟主机,则或多或少需要),您的
GET
请求将需要包含主机名,可以在Host 中
标头或作为请求行中的绝对 URI(请参阅 RFC 2616 第 5.1.2 节)。您的回复还需要
Content-Length
或 传输编码标头和分隔符。如果您愿意通过使用
HEAD
请求来“破坏”HTTP,那么听起来 HTTP 可能不是协议的最佳选择。您也许还可以在自定义标头中返回某些内容,但这不是一种干净的方法。请注意,即使您实现自己的协议,您也需要实现类似于 Content-Length 或分块编码提供的机制,以便能够确定何时停止从远程方读取(否则,您将无法检测严重关闭的连接)。
编辑:
这是一个简单的示例,这将根据您的主机名而有所不同(假设是 HTTP 1.1)。我想你可以使用
OPTIONS
来代替。这取决于您愿意破坏 HTTP 的程度...请求:
即 14 + 2 + 21 + 2 + 2 = 41 字节(2 表示 CRLF)
响应:
即 15 + 2 + 17 + 2 + 24 + 2 + 2 + 1 = 65 字节
对于 HTTPS,SSL/TLS 通道本身会有少量开销,但其中大部分将由握手占用,特别是,服务器证书(假设您没有使用客户端证书身份验证)应该是最大的。检查证书的大小(DER 格式)。
If you're planning to use HTTP/1.1 (more or less require if you end up on a virtual host), your
GET
request will need to have the host name, either in theHost
header or as an absolute URI in the request line (see RFC 2616 section 5.1.2).Your response will also need a
Content-Length
or transfer encoding headers and delimiters.If you're willing to "break" HTTP by using a
HEAD
request, it sounds like HTTP might not be the best choice of protocol. You might also be able to return something in a custom header, but that's not a clean way of doing it.Note that, even if you implement your own protocol, you will need to implement a mechanism similar to what
Content-Length
or chunked encoding provide, to be able to determine when to stop reading from the remote party (otherwise, you won't be able to detect badly closed connections).EDIT:
Here is a quick example, this will vary depending on your host name (assuming HTTP 1.1). I guess you could use
OPTIONS
instead. It depends on how much you're willing to break HTTP...Request:
That's 14 + 2 + 21 + 2 + 2 = 41 bytes (2 for CRLF)
Response:
That's 15 + 2 + 17 + 2 + 24 + 2 + 2 + 1 = 65 bytes
For HTTPS, there will be a small overhead for the SSL/TLS channel itself, but the bulk of it will be taken by the handshake, in particular, the server certificate (assuming you're not using client-cert authentication) should be the biggest. Check the size (in DER format) of your certificate.
你究竟想要实现什么目标,这是一种保持活力吗?
您可以执行“GET /”,这意味着正在使用 HTTP/1.0,但这会阻止您使用虚拟主机等内容。您可以将“/”映射到 cgi 脚本,它不需要是真实的文件,具体取决于您想要实现的目标。您可以将 Apache 配置为仅返回最小的标头集,这基本上是“Content-Type: text/plain”(或其他更短的 mime 类型,可能是自定义 mimetype,例如“Content-Type: a/b”)和“ Content-Length: 0”,因此根本不返回响应正文。
What exactly are you trying to achieve, is this a sort of keep alive?
You could do a "GET /", which implies HTTP/1.0 being used, but that locks you out of stuff like virtual hosting etc. You can map "/" to a cgi-script, it doesn't need to be a real file, depending on what you're trying to achieve. You can configure Apache to only return the minimum set of headers, which would basically be "Content-Type: text/plain" (or another, shorter mime type, possibly custom mimetype e.g. "Content-Type: a/b") and "Content-Length: 0", thus not returning a response body at all.
这是一个老问题,但也许有人发现它有用,因为没有人回答问题的 HTTPS 部分。
对我来说,这是为了在我的代理中轻松验证 HTTPS 通信所需要的,该代理通过隧道连接不可信的其他代理。
这个网站解释得很清楚:http://netsekure.org/2010/03/tls-overhead /
文章引用:
因此最小值可以大(或小)为:
尽管根据文章,平均值约为 <代码>6449 字节。
另外,重要的是要知道 TLS 会话可以恢复,因此只有第一个连接有此开销。所有其他消息大约有
330
字节以上。It is an old question, but maybe someone found it useful, because nobody has answered the HTTPS part of the question.
For me this was needed for an easy validation of HTTPS communication in my proxy, which connects untrustable other proxies through tunnel.
This site explains it clearly: http://netsekure.org/2010/03/tls-overhead/
Quotes from the article:
So the minimum can be as big (or small) as:
Though according to the article, the average is about
6449
bytes.Also it is important to know that TLS sessions can be resumed, so only the 1st connection has this overhead. All other messages have about
330
bytes plus.如果不需要任何返回值,最小的 HTTP 响应是:
If you don’t need any returned value, the smallest HTTP Response is :