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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
f14774df
Commit
f14774df
authored
Jun 10, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue #276: Enable Response::sendFile() to operate on resources
parent
9806563f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
13 deletions
+43
-13
HttpException.php
framework/yii/base/HttpException.php
+3
-4
HeaderCollection.php
framework/yii/web/HeaderCollection.php
+16
-0
Response.php
framework/yii/web/Response.php
+0
-0
data.txt
tests/unit/data/web/data.txt
+2
-0
ResponseTest.php
tests/unit/framework/web/ResponseTest.php
+22
-9
No files found.
framework/yii/base/HttpException.php
View file @
f14774df
...
...
@@ -7,8 +7,6 @@
namespace
yii\base
;
use
yii\web\Response
;
/**
* HttpException represents an exception caused by an improper request of the end-user.
*
...
...
@@ -44,8 +42,9 @@ class HttpException extends UserException
*/
public
function
getName
()
{
if
(
isset
(
Response
::
$httpStatuses
[
$this
->
statusCode
]))
{
return
Response
::
$httpStatuses
[
$this
->
statusCode
];
// use absolute namespaced class here because PHP will generate a mysterious error otherwise
if
(
isset
(
\yii\web\Response
::
$httpStatuses
[
$this
->
statusCode
]))
{
return
\yii\web\Response
::
$httpStatuses
[
$this
->
statusCode
];
}
else
{
return
'Error'
;
}
...
...
framework/yii/web/HeaderCollection.php
View file @
f14774df
...
...
@@ -104,6 +104,22 @@ class HeaderCollection extends Object implements \IteratorAggregate, \ArrayAcces
}
/**
* Adds a new header only if it does not exist yet.
* If there is already a header with the same name, the new one will be ignored.
* @param string $name the name of the header
* @param string $value the value of the header
* @return HeaderCollection the collection object itself
*/
public
function
addDefault
(
$name
,
$value
)
{
$name
=
strtolower
(
$name
);
if
(
empty
(
$this
->
_headers
[
$name
]))
{
$this
->
_headers
[
$name
][]
=
$value
;
}
return
$this
;
}
/**
* Returns a value indicating whether the named header exists.
* @param string $name the name of the header
* @return boolean whether the named header exists
...
...
framework/yii/web/Response.php
View file @
f14774df
This diff is collapsed.
Click to expand it.
tests/unit/data/web/data.txt
0 → 100644
View file @
f14774df
12ёжик3456798áèabcdefghijklmnopqrstuvwxyz!"§$%&/(ёжик)=?
\ No newline at end of file
tests/unit/framework/web/ResponseTest.php
View file @
f14774df
...
...
@@ -4,10 +4,20 @@ namespace yiiunit\framework\web;
use
Yii
;
use
yii\helpers\StringHelper
;
use
yii\web\Response
;
class
Response
extends
\yii\web\Response
{
public
function
send
()
{
// does nothing to allow testing
}
}
class
ResponseTest
extends
\yiiunit\TestCase
{
/**
* @var Response
*/
public
$response
;
protected
function
setUp
()
...
...
@@ -31,17 +41,20 @@ class ResponseTest extends \yiiunit\TestCase
/**
* @dataProvider rightRanges
*/
public
function
testSendFileRanges
(
$rangeHeader
,
$expectedHeader
,
$length
,
$expected
File
)
public
function
testSendFileRanges
(
$rangeHeader
,
$expectedHeader
,
$length
,
$expected
Content
)
{
$content
=
$this
->
generateTestFileContent
();
$dataFile
=
\Yii
::
getAlias
(
'@yiiunit/data/web/data.txt'
);
$fullContent
=
file_get_contents
(
$dataFile
);
$_SERVER
[
'HTTP_RANGE'
]
=
'bytes='
.
$rangeHeader
;
$this
->
response
->
sendFile
(
'testFile.txt'
,
$content
,
null
,
false
);
ob_start
();
$this
->
response
->
sendFile
(
$dataFile
);
$content
=
ob_get_clean
();
$this
->
assertEquals
(
$expected
File
,
$this
->
response
->
content
);
$this
->
assertEquals
(
$expected
Content
,
$
content
);
$this
->
assertEquals
(
206
,
$this
->
response
->
statusCode
);
$headers
=
$this
->
response
->
headers
;
$this
->
assertEquals
(
"bytes"
,
$headers
->
get
(
'Accept-Ranges'
));
$this
->
assertEquals
(
"bytes "
.
$expectedHeader
.
'/'
.
StringHelper
::
strlen
(
$
c
ontent
),
$headers
->
get
(
'Content-Range'
));
$this
->
assertEquals
(
"bytes "
.
$expectedHeader
.
'/'
.
StringHelper
::
strlen
(
$
fullC
ontent
),
$headers
->
get
(
'Content-Range'
));
$this
->
assertEquals
(
'text/plain'
,
$headers
->
get
(
'Content-Type'
));
$this
->
assertEquals
(
"
$length
"
,
$headers
->
get
(
'Content-Length'
));
}
...
...
@@ -63,11 +76,11 @@ class ResponseTest extends \yiiunit\TestCase
*/
public
function
testSendFileWrongRanges
(
$rangeHeader
)
{
$this
->
setExpectedException
(
'yii\base\HttpException'
,
'Requested Range Not Satisfiable'
);
$this
->
setExpectedException
(
'yii\base\HttpException'
);
$
content
=
$this
->
generateTestFileContent
(
);
$
dataFile
=
\Yii
::
getAlias
(
'@yiiunit/data/web/data.txt'
);
$_SERVER
[
'HTTP_RANGE'
]
=
'bytes='
.
$rangeHeader
;
$this
->
response
->
sendFile
(
'testFile.txt'
,
$content
,
null
,
fals
e
);
$this
->
response
->
sendFile
(
$dataFil
e
);
}
protected
function
generateTestFileContent
()
...
...
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