Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
tornadoweb
Tornado
提交
5b794dee
Tornado
项目概览
镜像
/
tornadoweb
/
Tornado
10 个月 前同步成功
通知
26
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Tornado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5b794dee
编写于
5月 21, 2013
作者:
D
David Wolever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Send HTTP 200 in response to Range: bytes=0-
上级
8a0e824b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
5 deletion
+24
-5
tornado/test/web_test.py
tornado/test/web_test.py
+14
-2
tornado/web.py
tornado/web.py
+10
-3
未找到文件。
tornado/test/web_test.py
浏览文件 @
5b794dee
...
@@ -756,6 +756,7 @@ class StaticFileTest(WebTestCase):
...
@@ -756,6 +756,7 @@ class StaticFileTest(WebTestCase):
# The expected MD5 hash of robots.txt, used in tests that call
# The expected MD5 hash of robots.txt, used in tests that call
# StaticFileHandler.get_version
# StaticFileHandler.get_version
robots_txt_hash
=
b
"f71d20196d4caf35b6a670db8c70b03d"
robots_txt_hash
=
b
"f71d20196d4caf35b6a670db8c70b03d"
static_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'static'
)
def
get_handlers
(
self
):
def
get_handlers
(
self
):
class
StaticUrlHandler
(
RequestHandler
):
class
StaticUrlHandler
(
RequestHandler
):
...
@@ -794,8 +795,7 @@ class StaticFileTest(WebTestCase):
...
@@ -794,8 +795,7 @@ class StaticFileTest(WebTestCase):
(
'/override_static_url/(.*)'
,
OverrideStaticUrlHandler
)]
(
'/override_static_url/(.*)'
,
OverrideStaticUrlHandler
)]
def
get_app_kwargs
(
self
):
def
get_app_kwargs
(
self
):
return
dict
(
static_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
return
dict
(
static_path
=
self
.
static_dir
)
'static'
))
def
test_static_files
(
self
):
def
test_static_files
(
self
):
response
=
self
.
fetch
(
'/robots.txt'
)
response
=
self
.
fetch
(
'/robots.txt'
)
...
@@ -879,6 +879,18 @@ class StaticFileTest(WebTestCase):
...
@@ -879,6 +879,18 @@ class StaticFileTest(WebTestCase):
self
.
assertEqual
(
response
.
headers
.
get
(
"Content-Range"
),
self
.
assertEqual
(
response
.
headers
.
get
(
"Content-Range"
),
"0-9/26"
)
"0-9/26"
)
def
test_static_with_range_full_file
(
self
):
response
=
self
.
fetch
(
'/static/robots.txt'
,
headers
=
{
'Range'
:
'bytes=0-'
})
# Note: Chrome refuses to play audio if it gets an HTTP 206 in response
# to ``Range: bytes=0-`` :(
self
.
assertEqual
(
response
.
code
,
200
)
robots_file_path
=
os
.
path
.
join
(
self
.
static_dir
,
"robots.txt"
)
with
open
(
robots_file_path
)
as
f
:
self
.
assertEqual
(
response
.
body
,
utf8
(
f
.
read
()))
self
.
assertEqual
(
response
.
headers
.
get
(
"Content-Length"
),
"26"
)
self
.
assertEqual
(
response
.
headers
.
get
(
"Content-Range"
),
"0-25/26"
)
def
test_static_with_range_end_edge
(
self
):
def
test_static_with_range_end_edge
(
self
):
response
=
self
.
fetch
(
'/static/robots.txt'
,
headers
=
{
response
=
self
.
fetch
(
'/static/robots.txt'
,
headers
=
{
'Range'
:
'bytes=22-'
})
'Range'
:
'bytes=22-'
})
...
...
tornado/web.py
浏览文件 @
5b794dee
...
@@ -52,6 +52,7 @@ request.
...
@@ -52,6 +52,7 @@ request.
from
__future__
import
absolute_import
,
division
,
print_function
,
with_statement
from
__future__
import
absolute_import
,
division
,
print_function
,
with_statement
import
base64
import
base64
import
binascii
import
binascii
import
datetime
import
datetime
...
@@ -1797,11 +1798,17 @@ class StaticFileHandler(RequestHandler):
...
@@ -1797,11 +1798,17 @@ class StaticFileHandler(RequestHandler):
with
open
(
abspath
,
"rb"
)
as
file
:
with
open
(
abspath
,
"rb"
)
as
file
:
data
=
file
.
read
()
data
=
file
.
read
()
if
request_range
:
if
request_range
:
# 206: Partial Content
data_sliced
=
data
[
request_range
]
self
.
set_status
(
206
)
# Note: only return HTTP 206 if less than the entire range has
# been requested. Not only is this semantically correct, but
# Chrome refuses to play audio if it gets an HTTP 206 in
# response to ``Range: bytes=0-``.
if
len
(
data
)
!=
len
(
data_sliced
):
# 206: Partial Content
self
.
set_status
(
206
)
content_range
=
httputil
.
get_content_range
(
data
,
request_range
)
content_range
=
httputil
.
get_content_range
(
data
,
request_range
)
self
.
set_header
(
"Content-Range"
,
content_range
)
self
.
set_header
(
"Content-Range"
,
content_range
)
data
=
data
[
request_range
]
data
=
data
_sliced
if
include_body
:
if
include_body
:
self
.
write
(
data
)
self
.
write
(
data
)
else
:
else
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录