Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
d7cb4ce9
Commit
d7cb4ce9
authored
Jun 11, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue #276: support range request for sending content as a file.
parent
1a7f5f58
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
16 deletions
+23
-16
Response.php
framework/yii/web/Response.php
+23
-16
No files found.
framework/yii/web/Response.php
View file @
d7cb4ce9
...
@@ -204,17 +204,12 @@ class Response extends \yii\base\Response
...
@@ -204,17 +204,12 @@ class Response extends \yii\base\Response
{
{
$this
->
sendHeaders
();
$this
->
sendHeaders
();
$this
->
sendContent
();
$this
->
sendContent
();
for
(
$level
=
ob_get_level
();
$level
>
0
;
--
$level
)
{
if
(
function_exists
(
'fastcgi_finish_request'
))
{
if
(
!@
ob_end_flush
())
{
fastcgi_finish_request
();
ob_clean
();
}
else
{
for
(
$level
=
ob_get_level
();
$level
>
0
;
--
$level
)
{
if
(
!@
ob_end_flush
())
{
ob_clean
();
}
}
}
flush
();
}
}
flush
();
}
}
public
function
reset
()
public
function
reset
()
...
@@ -306,8 +301,15 @@ class Response extends \yii\base\Response
...
@@ -306,8 +301,15 @@ class Response extends \yii\base\Response
*/
*/
public
function
sendContentAsFile
(
$content
,
$attachmentName
,
$mimeType
=
'application/octet-stream'
)
public
function
sendContentAsFile
(
$content
,
$attachmentName
,
$mimeType
=
'application/octet-stream'
)
{
{
$this
->
getHeaders
()
$headers
=
$this
->
getHeaders
();
->
addDefault
(
'Pragma'
,
'public'
)
$contentLength
=
StringHelper
::
strlen
(
$content
);
$range
=
$this
->
getHttpRange
(
$contentLength
);
if
(
$range
===
false
)
{
$headers
->
set
(
'Content-Range'
,
"bytes */
$contentLength
"
);
throw
new
HttpException
(
416
,
Yii
::
t
(
'yii'
,
'Requested range not satisfiable'
));
}
$headers
->
addDefault
(
'Pragma'
,
'public'
)
->
addDefault
(
'Accept-Ranges'
,
'bytes'
)
->
addDefault
(
'Accept-Ranges'
,
'bytes'
)
->
addDefault
(
'Expires'
,
'0'
)
->
addDefault
(
'Expires'
,
'0'
)
->
addDefault
(
'Content-Type'
,
$mimeType
)
->
addDefault
(
'Content-Type'
,
$mimeType
)
...
@@ -316,7 +318,16 @@ class Response extends \yii\base\Response
...
@@ -316,7 +318,16 @@ class Response extends \yii\base\Response
->
addDefault
(
'Content-Length'
,
StringHelper
::
strlen
(
$content
))
->
addDefault
(
'Content-Length'
,
StringHelper
::
strlen
(
$content
))
->
addDefault
(
'Content-Disposition'
,
"attachment; filename=
\"
$attachmentName
\"
"
);
->
addDefault
(
'Content-Disposition'
,
"attachment; filename=
\"
$attachmentName
\"
"
);
$this
->
content
=
$content
;
list
(
$begin
,
$end
)
=
$range
;
if
(
$begin
!=
0
||
$end
!=
$contentLength
-
1
)
{
$this
->
setStatusCode
(
206
);
$headers
->
set
(
'Content-Range'
,
"bytes
$begin
-
$end
/
$contentLength
"
);
$this
->
content
=
StringHelper
::
substr
(
$content
,
$begin
,
$end
-
$begin
+
1
);
}
else
{
$this
->
setStatusCode
(
200
);
$this
->
content
=
$content
;
}
$this
->
send
();
$this
->
send
();
}
}
...
@@ -347,10 +358,6 @@ class Response extends \yii\base\Response
...
@@ -347,10 +358,6 @@ class Response extends \yii\base\Response
$this
->
setStatusCode
(
200
);
$this
->
setStatusCode
(
200
);
}
}
if
(
isset
(
$options
[
'mimeType'
]))
{
$headers
->
set
(
'Content-Type'
,
$options
[
'mimeType'
]);
}
$length
=
$end
-
$begin
+
1
;
$length
=
$end
-
$begin
+
1
;
$headers
->
addDefault
(
'Pragma'
,
'public'
)
$headers
->
addDefault
(
'Pragma'
,
'public'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment