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
2310fe6e
Commit
2310fe6e
authored
Jan 22, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2111 from dizews/get-headers
Added ability to get incoming headers
parents
af53c0f8
4dabe605
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
5 deletions
+43
-5
RequestPanel.php
extensions/debug/panels/RequestPanel.php
+7
-5
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Request.php
framework/web/Request.php
+35
-0
No files found.
extensions/debug/panels/RequestPanel.php
View file @
2310fe6e
...
...
@@ -36,13 +36,15 @@ class RequestPanel extends Panel
public
function
save
()
{
if
(
function_exists
(
'apache_request_headers'
))
{
$requestHeaders
=
apache_request_headers
();
}
elseif
(
function_exists
(
'http_get_request_headers'
)
)
{
$requestHeaders
=
http_get_request_headers
(
);
$headers
=
Yii
::
$app
->
getRequest
()
->
getHeaders
();
foreach
(
$headers
as
$name
=>
$value
)
{
if
(
is_array
(
$value
)
&&
count
(
$value
)
==
1
)
{
$requestHeaders
[
$name
]
=
current
(
$value
);
}
else
{
$requestHeaders
=
[]
;
$requestHeaders
[
$name
]
=
$value
;
}
}
$responseHeaders
=
[];
foreach
(
headers_list
()
as
$header
)
{
if
((
$pos
=
strpos
(
$header
,
':'
))
!==
false
)
{
...
...
framework/CHANGELOG.md
View file @
2310fe6e
...
...
@@ -93,6 +93,7 @@ Yii Framework 2 Change Log
-
Enh #1839: Added support for getting file extension and basename from uploaded file (anfrantic)
-
Enh: yii
\c
odeception
\T
estCase now supports loading and using fixtures via Yii fixture framework (qiangxue)
-
Enh: Added support to parse json request data to Request::getRestParams() (cebe)
-
Enh: Added ability to get incoming headers (dizews)
-
Chg #1519:
`yii\web\User::loginRequired()`
now returns the
`Response`
object instead of exiting the application (qiangxue)
-
Chg #1586:
`QueryBuilder::buildLikeCondition()`
will now escape special characters and use percentage characters by default (qiangxue)
-
Chg #1610:
`Html::activeCheckboxList()`
and
`Html::activeRadioList()`
will submit an empty string if no checkbox/radio is selected (qiangxue)
...
...
framework/web/Request.php
View file @
2310fe6e
...
...
@@ -151,6 +151,10 @@ class Request extends \yii\base\Request
private
$_cookies
;
/**
* @var array the headers in this collection (indexed by the header names)
*/
private
$_headers
;
/**
* Resolves the current request into a route and the associated parameters.
...
...
@@ -170,6 +174,37 @@ class Request extends \yii\base\Request
}
/**
* Returns the header collection.
* The header collection contains incoming HTTP headers.
* @return HeaderCollection the header collection
*/
public
function
getHeaders
()
{
if
(
$this
->
_headers
===
null
)
{
$this
->
_headers
=
new
HeaderCollection
;
$headers
=
[];
if
(
function_exists
(
'getallheaders'
))
{
$headers
=
getallheaders
();
}
elseif
(
function_exists
(
'http_get_request_headers'
))
{
$headers
=
http_get_request_headers
();
}
else
{
foreach
(
$_SERVER
as
$name
=>
$value
)
{
if
(
substr
(
$name
,
0
,
5
)
==
'HTTP_'
)
{
$name
=
str_replace
(
' '
,
'-'
,
ucwords
(
strtolower
(
str_replace
(
'_'
,
' '
,
substr
(
$name
,
5
)))));
$this
->
_headers
->
add
(
$name
,
$value
);
}
}
return
$this
->
_headers
;
}
foreach
(
$headers
as
$name
=>
$value
)
{
$this
->
_headers
->
add
(
$name
,
$value
);
}
}
return
$this
->
_headers
;
}
/**
* Returns the method of the current request (e.g. GET, POST, HEAD, PUT, PATCH, DELETE).
* @return string request method, such as GET, POST, HEAD, PUT, PATCH, DELETE.
* The value returned is turned into upper case.
...
...
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