Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Y
yii2-httpclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christoffer Benítez
yii2-httpclient
Commits
c54d71a5
Commit
c54d71a5
authored
8 years ago
by
Klimov Paul
Browse files
Options
Downloads
Patches
Plain Diff
Fixed inability to use URL with query parameters as `Client::$baseUrl`
parent
14f9850a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+3
-2
3 additions, 2 deletions
CHANGELOG.md
Request.php
+14
-9
14 additions, 9 deletions
Request.php
tests/RequestTest.php
+43
-12
43 additions, 12 deletions
tests/RequestTest.php
with
60 additions
and
23 deletions
CHANGELOG.md
+
3
−
2
View file @
c54d71a5
...
...
@@ -6,6 +6,7 @@ Yii Framework 2 HTTP client extension Change Log
-
Bug #74: Fixed unable to reuse
`Request`
instance for sending several requests with different data (klimov-paul)
-
Bug #76: Fixed
`HttpClientPanel`
triggers
`E_WARNING`
on attempt to view history debug entry, generated without panel being attached (klimov-paul)
-
Bug #79: Fixed inability to use URL with query parameters as
`Client::$baseUrl`
(klimov-paul)
2.0.2 October 31, 2016
...
...
@@ -26,8 +27,8 @@ Yii Framework 2 HTTP client extension Change Log
-
Enh #43: Events
`EVENT_BEFORE_SEND`
and
`EVENT_AFTER_SEND`
added to
`Request`
and
`Client`
(klimov-paul)
-
Enh #46: Added
`Request::getFullUrl()`
allowing getting the full actual request URL (klimov-paul)
-
Enh #47: Added
`Message::addData()`
allowing addition of the content data to already existing one (klimov-paul)
-
Enh #50: Option 'protocolVersion' added to
`Request::options`
allowing specification of the HTTP protocol version (klimov-paul)
-
Enh #58: Added
`UrlEncodedFormatter::charset`
allowing specification of content charset (klimov-paul)
-
Enh #50: Option 'protocolVersion' added to
`Request::
$
options`
allowing specification of the HTTP protocol version (klimov-paul)
-
Enh #58: Added
`UrlEncodedFormatter::
$
charset`
allowing specification of content charset (klimov-paul)
-
Enh: Added
`XmlFormatter::useTraversableAsArray`
allowing processing
`\Traversable`
as array (klimov-paul)
...
...
This diff is collapsed.
Click to expand it.
Request.php
+
14
−
9
View file @
c54d71a5
...
...
@@ -275,7 +275,19 @@ class Request extends Message
if
(
isset
(
$params
[
0
]))
{
$url
=
$params
[
0
];
unset
(
$params
[
0
]);
}
else
{
$url
=
''
;
}
}
if
(
!
empty
(
$this
->
client
->
baseUrl
))
{
if
(
empty
(
$url
))
{
$url
=
$this
->
client
->
baseUrl
;
}
elseif
(
!
preg_match
(
'/^https?:\\/\\//i'
,
$url
))
{
$url
=
$this
->
client
->
baseUrl
.
'/'
.
$url
;
}
}
if
(
!
empty
(
$params
))
{
if
(
strpos
(
$url
,
'?'
)
===
false
)
{
$url
.
=
'?'
;
...
...
@@ -284,13 +296,6 @@ class Request extends Message
}
$url
.
=
http_build_query
(
$params
);
}
}
if
(
!
empty
(
$this
->
client
->
baseUrl
))
{
if
(
!
preg_match
(
'/^https?:\\/\\//i'
,
$url
))
{
$url
=
$this
->
client
->
baseUrl
.
'/'
.
$url
;
}
}
return
$url
;
}
...
...
This diff is collapsed.
Click to expand it.
tests/RequestTest.php
+
43
−
12
View file @
c54d71a5
...
...
@@ -129,26 +129,57 @@ EOL;
$this
->
assertContains
(
'some content'
,
$result
);
}
/**
* Data provider for [[testGetFullUrl()]]
* @return array test data
*/
public
function
dataProviderGetFullUrl
()
{
return
[
[
'http://some-domain.com'
,
'test/url'
,
'http://some-domain.com/test/url'
],
[
'http://some-domain.com'
,
'http://another-domain.com/test'
,
'http://another-domain.com/test'
,
],
[
'http://some-domain.com'
,
[
'test/url'
,
'param1'
=>
'name1'
],
'http://some-domain.com/test/url?param1=name1'
],
[
'http://some-domain.com?base-param=base'
,
null
,
'http://some-domain.com?base-param=base'
,
],
[
'http://some-domain.com?base-param=base'
,
[
'param1'
=>
'name1'
],
'http://some-domain.com?base-param=base¶m1=name1'
,
],
];
}
/**
* @depends testSetupUrl
* @dataProvider dataProviderGetFullUrl
*
* @param string $baseUrl
* @param mixed $url
* @param string $expectedFullUrl
*/
public
function
testGetFullUrl
()
public
function
testGetFullUrl
(
$baseUrl
,
$url
,
$expectedFullUrl
)
{
$client
=
new
Client
();
$client
->
baseUrl
=
'http://some-domain.com'
;
$client
->
baseUrl
=
$baseUrl
;
$request
=
new
Request
([
'client'
=>
$client
]);
$url
=
'test/url'
;
$request
->
setUrl
(
$url
);
$this
->
assertEquals
(
'http://some-domain.com/test/url'
,
$request
->
getFullUrl
());
$url
=
'http://another-domain.com/test'
;
$request
->
setUrl
(
$url
);
$this
->
assertEquals
(
$url
,
$request
->
getFullUrl
());
$url
=
[
'test/url'
,
'param1'
=>
'name1'
];
$request
->
setUrl
(
$url
);
$this
->
assertEquals
(
'http://some-domain.com/test/url?param1=name1'
,
$request
->
getFullUrl
());
$this
->
assertEquals
(
$expectedFullUrl
,
$request
->
getFullUrl
());
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment