热门标签 | 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.

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


推荐阅读
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • 本文讨论了在VMWARE5.1的虚拟服务器Windows Server 2008R2上安装oracle 10g客户端时出现的问题,并提供了解决方法。错误日志显示了异常访问违例,通过分析日志中的问题帧,找到了解决问题的线索。文章详细介绍了解决方法,帮助读者顺利安装oracle 10g客户端。 ... [详细]
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • PHP图片截取方法及应用实例
    本文介绍了使用PHP动态切割JPEG图片的方法,并提供了应用实例,包括截取视频图、提取文章内容中的图片地址、裁切图片等问题。详细介绍了相关的PHP函数和参数的使用,以及图片切割的具体步骤。同时,还提供了一些注意事项和优化建议。通过本文的学习,读者可以掌握PHP图片截取的技巧,实现自己的需求。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文介绍了在CentOS上安装Python2.7.2的详细步骤,包括下载、解压、编译和安装等操作。同时提供了一些注意事项,以及测试安装是否成功的方法。 ... [详细]
  • 欢乐的票圈重构之旅——RecyclerView的头尾布局增加
    项目重构的Git地址:https:github.comrazerdpFriendCircletreemain-dev项目同步更新的文集:http:www.jianshu.comno ... [详细]
  • 本文分析了Wince程序内存和存储内存的分布及作用。Wince内存包括系统内存、对象存储和程序内存,其中系统内存占用了一部分SDRAM,而剩下的30M为程序内存和存储内存。对象存储是嵌入式wince操作系统中的一个新概念,常用于消费电子设备中。此外,文章还介绍了主电源和后备电池在操作系统中的作用。 ... [详细]
  • 本文介绍了pack布局管理器在Perl/Tk中的使用方法及注意事项。通过调用pack()方法,可以控制部件在显示窗口中的位置和大小。同时,本文还提到了在使用pack布局管理器时,应注意将部件分组以便在水平和垂直方向上进行堆放。此外,还介绍了使用Frame部件或Toplevel部件来组织部件在窗口内的方法。最后,本文强调了在使用pack布局管理器时,应避免在中间切换到grid布局管理器,以免造成混乱。 ... [详细]
  • 使用C++编写程序实现增加或删除桌面的右键列表项
    本文介绍了使用C++编写程序实现增加或删除桌面的右键列表项的方法。首先通过操作注册表来实现增加或删除右键列表项的目的,然后使用管理注册表的函数来编写程序。文章详细介绍了使用的五种函数:RegCreateKey、RegSetValueEx、RegOpenKeyEx、RegDeleteKey和RegCloseKey,并给出了增加一项的函数写法。通过本文的方法,可以方便地自定义桌面的右键列表项。 ... [详细]
  • 本文介绍了使用C++Builder实现获取USB优盘序列号的方法,包括相关的代码和说明。通过该方法,可以获取指定盘符的USB优盘序列号,并将其存放在缓冲中。该方法可以在Windows系统中有效地获取USB优盘序列号,并且适用于C++Builder开发环境。 ... [详细]
  • JAVA调用存储过程CallableStatement对象的方法及使用示例
    本文介绍了使用JAVA调用存储过程CallableStatement对象的方法,包括创建CallableStatement对象、传入IN参数、注册OUT参数、传入INOUT参数、检索结果和OUT参数、处理NULL值等。通过示例代码演示了具体的调用过程。 ... [详细]
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社区 版权所有