热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用带范围说明符的HTTP范围头,而不是字节?-UsingtheHTTPRangeHeaderwitharangespecifierotherthanbytes?

ThecorequestionisabouttheuseoftheHTTPHeaders,includingRange,If-Range,Accept-Rangesand

The core question is about the use of the HTTP Headers, including Range, If-Range, Accept-Ranges and a user defined range specifier.

核心问题是关于HTTP头的使用,包括范围、If-Range、接受-范围和用户定义的范围说明符。

Here is a manufactured example to help illustrate my question. Assume I have a Web 2.0 style application that displays some sort of human readable documents. These documents are editorially broken up into pages (similar to articles you see on news websites). For this example, assume:

这里有一个人为的例子来说明我的问题。假设我有一个Web 2.0风格的应用程序,它显示了一些人类可读的文档。这些文档被编辑成页面(类似于你在新闻网站上看到的文章)。对于这个示例,假设:

  • There is a document titled "HTTP Range Question" is broken up into three pages.
  • 有一个名为“HTTP范围问题”的文档被分为三页。
  • The shell page (/document/shell/http-range-question) knows the meta information about the document, including the number of pages.
  • shell页面(/document/shell/http-range-question)知道关于文档的元信息,包括页面的数量。
  • The first readable page of the document is loaded during the page onload event via an ajax GET and inserted onto the page.
  • 文档的第一个可读页面是在页面onload事件期间通过ajax GET加载并插入到页面中。
  • A UI control that looks like [ 1 2 3 All ] is at the bottom of the page, and clicking on a number will display that readable page (also loaded via ajax), and clicking "All" will display the entire document. Assume these URLS for the 1, 2, 3 and All use cases:
    • /document/content/http-range-question?page=1
    • /文档/内容/ http-range-question ? = 1页
    • /document/content/http-range-question?page=2
    • /文档/内容/ http-range-question ? = 2页
    • /document/content/http-range-question?page=3
    • /文档/内容/ http-range-question ? = 3页
    • /document/content/http-range-question
    • /文档/内容/ http-range-question
  • 一个看起来像[1 2 3]的UI控件在页面的底部,单击一个数字将显示可读页面(也通过ajax加载),点击“All”将显示整个文档。假设这些url用于1,2,3和所有用例:/document/content/http-range-question?页面= 1 /文档/内容/ http-range-question吗?页面= 2 /文档/内容/ http-range-question吗?页面= 3 /文档/内容/ http-range-question

Now to the question. Can I use the HTTP Range headers instead part of the URL (e.g. a querystring parameter)? Maybe something like this on the GET /document/content/http-range-question request:

现在的问题。我可以使用HTTP范围标头而不是URL的一部分(例如一个querystring参数)吗?可能在GET /document/content/http-range-question请求中有这样的内容:

Range: page=1

It looks like the spec only defines byte ranges as allowable, so even if I made my ajax calls work with my browser and server code, anything in the middle could break the contract (e.g. a caching proxy server).

看起来规范只定义了允许的字节范围,所以即使我让ajax调用与浏览器和服务器代码一起工作,中间的任何东西都可能破坏契约(例如缓存代理服务器)。

Range: bytes=0-499

Any opinions or real world examples of custom range specifiers?

对自定义范围说明符有什么看法或实际示例吗?

Update: I did find a similar question about the Range header (Paging in a Rest Collection) where they mention that Dojo's JsonRestStore uses a custom Range header value.

更新:我确实发现了一个类似的关于范围标头(在Rest集合中分页)的问题,在这个问题中,他们提到Dojo的JsonRestStore使用自定义范围标头值。

Range: items=0-24

4 个解决方案

#1


32  

Absolutely - you are free to specify any range units you like.

绝对-你可以自由指定任何你喜欢的范围单位。

From RFC 2616:

RFC 2616:

3.12 Range Units

3.12单位范围

HTTP/1.1 allows a client to request that only part (a range of) the
response entity be included within the response. HTTP/1.1 uses range units in the Range (section 14.35) and Content-Range (section 14.16)
header fields. An entity can be broken down into subranges according to various structural units.

HTTP/1.1允许客户端请求响应中只包含响应实体的一部分(范围)。HTTP/1.1使用范围单元(第14.35节)和内容范围(第14.16节)头字段。一个实体可以根据不同的结构单元分解成子程序。

  range-unit       = bytes-unit | other-range-unit
  bytes-unit       = "bytes"
  other-range-unit = token

The only range unit defined by HTTP/1.1 is "bytes". HTTP/1.1
implementations MAY ignore ranges specified using other units.

HTTP/1.1定义的唯一范围单元是“字节”。HTTP/1.1实现可以忽略使用其他单元指定的范围。

The key piece is the last paragraph. Really what it's saying is that when they wrote the spec for HTTP/1.1, they only outlined the "bytes" token. But, as you can see from the 'other-range-unit' bit, you are free to come up with your own token specifiers.

关键是最后一段。它真正的意思是,当他们为HTTP/1.1编写规范时,他们只列出了“字节”标记。但是,正如您从“其他范围单元”位中看到的,您可以自由地提出自己的令牌说明符。

Coming up with your own Range specifiers does mean that you have to have control over the client and server code that uses that specifier. So, if you own the backend piece that exposes the "/document/content/http-range-question" URI, you are good to go; presumably you're using a modern web framework that lets you inspect the request headers coming in. You could then look at the Range values to perform the backing query correctly.

提供您自己的范围说明符意味着您必须控制使用该说明符的客户端和服务器代码。因此,如果您拥有公开“/document/content/http-range-question”URI的后端部分,那么您可以使用;假设您正在使用一个现代的web框架,它允许您检查传入的请求头。然后,您可以查看范围值,以正确执行支持查询。

Furthermore, if you control the AJAX code that makes requests to the backend, you should be able to set the Range header yourself.

此外,如果您控制了向后端发出请求的AJAX代码,您应该能够自己设置范围标题。

However, there is a potential downside which you anticipate in your question: the potential to break caching. If you are using a custom Range unit, any caches between your client and the origin servers "MAY ignore ranges specified using [units other than 'bytes']". So for example, if you had a Squid/Varnish cache between the front and backend, there's no guarantee that the results you're hoping for will be served from the cache!

但是,在您的问题中有一个潜在的缺点:可能破坏缓存。如果您正在使用自定义范围单元,那么您的客户端和源服务器之间的任何缓存“可能会忽略使用[除'bytes'之外的单元]指定的范围”。例如,如果你有一个鱿鱼/清漆缓存之间的前端和后端,没有保证你希望的结果将服务于缓存!

You might also consider an alternative implementation where, rather than using a query string, you make the page a "parameter" of the URI; e.g.: /document/content/http-range-question/page/1. This would likely be a little more work for you server-side, but it's HTTP/1.1 compliant and caches should treat it properly.

您还可以考虑另一种实现,即不使用查询字符串,而是将页面设置为URI的“参数”;例如:/文档/内容/ http-range-question / / 1页。对于服务器端来说,这可能需要做更多的工作,但是它是兼容HTTP/1.1的,缓存应该正确地对待它。

Hope this helps.

希望这个有帮助。

#2


0  

HTTP Range is typically used for recovering interrupted downloads without starting from the beginning.

HTTP Range通常用于从一开始就恢复被中断的下载。

What you're trying to do would be better handled by OAI-ORE, which allows you to define relationships between multiple documents. (alternative formats, components of the whole, etc)

您正在尝试做的事情最好由OAI-ORE来处理,它允许您定义多个文档之间的关系。(可选格式、整体组件等)

Unfortunately, it's a relatively new metadata format, and I don't know of any web browsers that ship with native support.

不幸的是,它是一种相对较新的元数据格式,我不知道有任何web浏览器附带本机支持。

#3


0  

bytes is the only unit supported by HTTP 1.1 Specification.

字节是HTTP 1.1规范支持的惟一单元。

#4


-2  

It sounds like you want to change the HTTP spec just to remove a querystring parameter. In order to do this you'd have to modify code on both the client to send the modified header and the server to read from the "Range" header instead of the querystring.

听起来您想要更改HTTP规范,只是为了删除一个querystring参数。为了做到这一点,您必须修改客户机上的代码,以便将修改后的头和服务器从“范围”头(而不是querystring)中读取。

The end result is that this will probably work, but you're breaking all of the standards and existing tools to do so.

最终的结果是,这可能会起作用,但是您违反了所有的标准和现有的工具。


推荐阅读
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 个人学习使用:谨慎参考1Client类importcom.thoughtworks.gauge.Step;importcom.thoughtworks.gauge.T ... [详细]
  • 本文介绍了一个适用于PHP应用快速接入TRX和TRC20数字资产的开发包,该开发包支持使用自有Tron区块链节点的应用场景,也支持基于Tron官方公共API服务的轻量级部署场景。提供的功能包括生成地址、验证地址、查询余额、交易转账、查询最新区块和查询交易信息等。详细信息可参考tron-php的Github地址:https://github.com/Fenguoz/tron-php。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文介绍了一种划分和计数油田地块的方法。根据给定的条件,通过遍历和DFS算法,将符合条件的地块标记为不符合条件的地块,并进行计数。同时,还介绍了如何判断点是否在给定范围内的方法。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 关键词:Golang, Cookie, 跟踪位置, net/http/cookiejar, package main, golang.org/x/net/publicsuffix, io/ioutil, log, net/http, net/http/cookiejar ... [详细]
  • 在重复造轮子的情况下用ProxyServlet反向代理来减少工作量
    像不少公司内部不同团队都会自己研发自己工具产品,当各个产品逐渐成熟,到达了一定的发展瓶颈,同时每个产品都有着自己的入口,用户 ... [详细]
  • 本文详细介绍了Java中vector的使用方法和相关知识,包括vector类的功能、构造方法和使用注意事项。通过使用vector类,可以方便地实现动态数组的功能,并且可以随意插入不同类型的对象,进行查找、插入和删除操作。这篇文章对于需要频繁进行查找、插入和删除操作的情况下,使用vector类是一个很好的选择。 ... [详细]
  • 深入理解Kafka服务端请求队列中请求的处理
    本文深入分析了Kafka服务端请求队列中请求的处理过程,详细介绍了请求的封装和放入请求队列的过程,以及处理请求的线程池的创建和容量设置。通过场景分析、图示说明和源码分析,帮助读者更好地理解Kafka服务端的工作原理。 ... [详细]
  • Windows7 64位系统安装PLSQL Developer的步骤和注意事项
    本文介绍了在Windows7 64位系统上安装PLSQL Developer的步骤和注意事项。首先下载并安装PLSQL Developer,注意不要安装在默认目录下。然后下载Windows 32位的oracle instant client,并解压到指定路径。最后,按照自己的喜好对解压后的文件进行命名和压缩。 ... [详细]
  • CEPH LIO iSCSI Gateway及其使用参考文档
    本文介绍了CEPH LIO iSCSI Gateway以及使用该网关的参考文档,包括Ceph Block Device、CEPH ISCSI GATEWAY、USING AN ISCSI GATEWAY等。同时提供了多个参考链接,详细介绍了CEPH LIO iSCSI Gateway的配置和使用方法。 ... [详细]
  • 图像因存在错误而无法显示 ... [详细]
author-avatar
pfm4191006
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有