Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
413573c8
Commit
413573c8
authored
May 01, 2012
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix redirecting to https when requireHttps is set, fixes #308
parent
5f7b6505
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
2 deletions
+50
-2
src/Silex/RedirectableUrlMatcher.php
src/Silex/RedirectableUrlMatcher.php
+16
-1
tests/Silex/Tests/RouterTest.php
tests/Silex/Tests/RouterTest.php
+34
-1
No files found.
src/Silex/RedirectableUrlMatcher.php
View file @
413573c8
...
...
@@ -27,9 +27,24 @@ class RedirectableUrlMatcher extends BaseRedirectableUrlMatcher
*/
public
function
redirect
(
$path
,
$route
,
$scheme
=
null
)
{
$url
=
$this
->
context
->
getBaseUrl
()
.
$path
;
if
(
$this
->
context
->
getHost
())
{
if
(
$scheme
)
{
$port
=
''
;
if
(
'http'
===
$scheme
&&
80
!=
$this
->
context
->
getHttpPort
())
{
$port
=
':'
.
$this
->
context
->
getHttpPort
();
}
elseif
(
'https'
===
$scheme
&&
443
!=
$this
->
context
->
getHttpsPort
())
{
$port
=
':'
.
$this
->
context
->
getHttpsPort
();
}
$url
=
$scheme
.
'://'
.
$this
->
context
->
getHost
()
.
$port
.
$url
;
}
}
return
array
(
'_controller'
=>
function
(
$url
)
{
return
new
RedirectResponse
(
$url
,
301
);
},
'url'
=>
$
this
->
context
->
getBaseUrl
()
.
$path
,
'url'
=>
$
url
,
);
}
}
tests/Silex/Tests/RouterTest.php
View file @
413573c8
...
...
@@ -102,6 +102,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
public
function
testMissingRoute
()
{
$app
=
new
Application
();
unset
(
$app
[
'exception_handler'
]);
$request
=
Request
::
create
(
'/baz'
);
...
...
@@ -147,13 +148,16 @@ class RouterTest extends \PHPUnit_Framework_TestCase
public
function
testRequestShouldBeStoredRegardlessOfRouting
()
{
$app
=
new
Application
();
$app
->
get
(
'/foo'
,
function
()
use
(
$app
)
{
return
new
Response
(
$app
[
'request'
]
->
getRequestUri
());
});
$app
->
error
(
function
(
$e
)
use
(
$app
)
{
return
new
Response
(
$app
[
'request'
]
->
getRequestUri
());
});
foreach
(
array
(
'/foo'
,
'/bar'
)
as
$path
)
{
foreach
(
array
(
'/foo'
,
'/bar'
)
as
$path
)
{
$request
=
Request
::
create
(
$path
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertContains
(
$path
,
$response
->
getContent
());
...
...
@@ -163,6 +167,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
public
function
testTrailingSlashBehavior
()
{
$app
=
new
Application
();
$app
->
get
(
'/foo/'
,
function
()
use
(
$app
)
{
return
new
Response
(
'ok'
);
});
...
...
@@ -174,6 +179,34 @@ class RouterTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
'/foo/'
,
$response
->
headers
->
get
(
'Location'
));
}
public
function
testRequireHttpRedirect
()
{
$app
=
new
Application
();
$app
->
match
(
'/secured'
,
function
()
{
return
'secured content'
;
})
->
requireHttp
();
$request
=
Request
::
create
(
'https://example.com/secured'
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertTrue
(
$response
->
isRedirect
(
'http://example.com/secured'
));
}
public
function
testRequireHttpsRedirect
()
{
$app
=
new
Application
();
$app
->
match
(
'/secured'
,
function
()
{
return
'secured content'
;
})
->
requireHttps
();
$request
=
Request
::
create
(
'http://example.com/secured'
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertTrue
(
$response
->
isRedirect
(
'https://example.com/secured'
));
}
public
function
testClassNameControllerSyntax
()
{
$app
=
new
Application
();
...
...
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