HTTP Range header
http://stackoverflow.com/questions/3303029/http-range-header
***************************
|
I was reading http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35 and trying to figure out how to continue a file download. For example, suppose a file is of length 100 bytes and I have all the 100 bytes. However, I don't know what the expected file size should be, so I ask for the file and specify a Range header that looks like this:
Is this a valid Range request? |
|||||||||
|
|
It's a syntactically valid request, but not a satisfiable request. If you look further in that section you see:
So I think in your example, the server should return a 416 since it's not a valid byte range for that file. |
|||||||||||||||||
|
Did you find this question interesting? Try our newsletter
Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).
|
As Wrikken suggested, it's a valid request. It's also quite common when the client is requesting media or resuming a download. A client will often test to see if the server handles ranged requests other than just looking for an Whenever a client includes
So, in order for the client to play video properly, your server must be able to handle these incomplete range requests. You can handle the type of 'range' you specified in your question in two ways: First, You could reply with the requested starting point given in the response, then the total length of the file minus one (the requested byte range is zero-indexed). For example: Request:
Response:
Second, you could reply with the starting point given in the request and an open-ended file length (size). This is for webcasts or other media where the total length is unknown. For example: Request:
Response:
Tips: You must always respond with the content length included with the range. If the range is complete, with start to end, then the content length is simply the difference: Request: Range: bytes=500-1000 Response: Content-Range: bytes 500-1000/123456 Remember that the range is zero-indexed, so
Or:
But, avoid the latter method if possible because some media players try to figure out the duration from the file size. If your request is for media content, which is my hunch, then you should include its duration in the response. This is done with the following format:
This must be a floating point. Unlike
With some media types, such as webm, you must also include the content-type, such as:
All of these are necessary for the media to play properly, especially in HTML5. If you don't give a duration, the player may try to figure out the duration (to allow for seeking) from its file size, but this won't be accurate. This is fine, and necessary for webcasts or live streaming, but not ideal for playback of video files. You can extract the duration using software like FFMPEG and save it in a database or even the filename.
One more point: Chrome always starts its first video request with the following:
Some servers will send a regular 200 response as a reply, which it accepts (but with limited playback options), but try to send a 206 instead to show than your server handles ranges. RFC 2616 says it's acceptable to ignore range headers. |
|||||||||||||||||||||
|
|
Contrary to Mark Novakowski answer, which for some reason has been upvoted by many, yes, it is a valid and satisfiable request. In fact the standard, as Wrikken pointed out, makes just such an example. In practice, Firefox responds to such requests as expected (with a 206 code), and this is exactly what I use to implement progressive download, that is, only get the tail of a long log file which grows in real time with polling. |
|||||
|
HTTP Range header的更多相关文章
- PHP header() http各种状态码大全查询
PHP header()the function declaration: void header ( string string [, bool replace [, int http_respon ...
- 数据流分段下载(Http之 Range)
public FileStreamResult StreamUploadedSongs(int id) { byte[] song = db.UploadedSongs.Where(x => x ...
- squid对http range的处理以及range_offset_limit
range_offset_limit A range request comes from a client that wants only some subset of an HTTP respon ...
- (实例篇)PHP实现HTTP断点续传的方法
PHP实现HTTP断点续传的方法. <?php /** * PHP-HTTP断点续传实现 * @param string $path: 文件所在路径 * @param string $file: ...
- HTTP请求应答服务——HTTP Request & Response Service
服务站点:https://httpbin.org/ Freely hosted in HTTP, HTTPS & EU flavors by Runscope DESCRIPTION Test ...
- HTTP超文本传输协议-HTTP/1.1中文版
摘要 超文本传输协议(HTTP)是一种为分布式,合作式,多媒体信息系统服务,面向应用层的协议.它是一种通用的,不分状态(stateless)的协议,除了诸如名称服务和分布对象管理系统之类的超文本用途外 ...
- http-code 未译
1xx Informational Request received, continuing process. This class of status code indicates a provis ...
- Apache Mod/Filter Development
catalog . 引言 . windows下开发apache模块 . mod进阶: 接收客户端数据的 echo 模块 . mod进阶: 可配置的 echo 模块 . mod进阶: 过滤器 0. 引言 ...
- php 下载文件的函数
通过函数完成下载文件的PHP功能代码 function download($url, $filename) { // 获得文件大小, 防止超过2G的文件, 用sprintf来读 $filesize = ...
随机推荐
- javascript不依赖JS加载顺序事件对象实现
背景: 在现在WEB开发中,稍复杂一点的页面,都会涉及到多个模块,尤其是类似seajs.LABjs.requireJS等模块工具出来后,前端开发者分模块开发已经慢慢变成一种习惯了,但是多个模块间的常常 ...
- Android应用程序访问linux驱动第一步:实现并测试Linux驱动
一直都想亲自做一次使用android应用程序访问Linux内核驱动的尝试,但总是没能做到.最近抽出时间,下决心重新尝试一次.尝试的开始当然是先写一个Linux内核驱动了. 我希望写一个简单测驱动程序, ...
- 在Windows Server 2008 R2上安装Exchange 2013过程中遇到的一些问题
笔者对Exchange经验非常有限, 但也正因为如此, 这里分享的东西对从没接触过Exchange的朋友会有更多的帮助吧, 至少希望如此. 1. Exchange 2013的安装需要.net fr ...
- 使用 session_destroy() 销毁session文件时 报 Trying to destroy uninitialized session 错误解决办法
在使用 sessio_destroy() 销毁session文件的时候,必须要先使用session_start() 来开启session 后才能删除session文件
- Spark详解
原文连接 http://xiguada.org/spark/ Spark概述 当前,MapReduce编程模型已经成为主流的分布式编程模型,它极大地方便了编程人员在不会分布式并行编程的情况下,将自己的 ...
- HDU 4372 - Count the Buildings(组合计数)
首先想过n^3的组合方法,即f(i,j,k)=f(i-1,j,k)*(i-2)+f(i-1,j-1,k)+f(i-1,j,k-1),肯定搞不定 然后想了好久没有效果,就去逛大神博客了,结果发现需要用到 ...
- (转)IntelliJ Idea 常用快捷键列表 for win
Ctrl+Shift + Enter,语句完成 ctrl+alt+左键 进入实现方法 “!”,否定完成,输入表达式时按 “!”键Ctrl+E,最近的文件Ctrl+Shift+E,最近更改的文件Shif ...
- Java 8 Stream 教程
Java 8 Stream Tutorial 本文采用实例驱动的方式,对JAVA8的stream API进行一个深入的介绍.虽然JAVA8中的stream API与JAVA I/O中的InputStr ...
- 《大话操作系统——做坚实的project实践派》(5)
有人说我不是仅仅会玩X86吗?我如今铁板钉钉的申明:我事实上兼通:ARM.IA-32.IA-32e.AMD64. 了解MIPS.但没做过MIPS由于确实没有对应的MIPS硬件平台.
- 重构wm_concat,采用clob做为存储容器
--Type CREATE OR REPLACE TYPE zh_concat_im AUTHID CURRENT_USER AS OBJECT ( CURR_STR clob, STATIC FUN ...
