Laravel version update
Laravel version update
This commit is contained in:
170
vendor/zendframework/zend-http/CHANGELOG.md
vendored
170
vendor/zendframework/zend-http/CHANGELOG.md
vendored
@@ -2,7 +2,163 @@
|
||||
|
||||
All notable changes to this project will be documented in this file, in reverse chronological order by release.
|
||||
|
||||
## 2.5.6 - TBD
|
||||
## 2.8.1 - 2018-08-01
|
||||
|
||||
### Added
|
||||
|
||||
- Nothing.
|
||||
|
||||
### Changed
|
||||
|
||||
- This release modifies how `Zend\Http\PhpEnvironment\Request` marshals the
|
||||
request URI. In prior releases, we would attempt to inspect the
|
||||
`X-Rewrite-Url` and `X-Original-Url` headers, using their values, if present.
|
||||
These headers are issued by the ISAPI_Rewrite module for IIS (developed by
|
||||
HeliconTech). However, we have no way of guaranteeing that the module is what
|
||||
issued the headers, making it an unreliable source for discovering the URI. As
|
||||
such, we have removed this feature in this release of zend-http.
|
||||
|
||||
If you are developing a zend-mvc application, you can mimic the
|
||||
functionality by adding a bootstrap listener like the following:
|
||||
|
||||
```php
|
||||
public function onBootstrap(MvcEvent $mvcEvent)
|
||||
{
|
||||
$request = $mvcEvent->getRequest();
|
||||
$requestUri = null;
|
||||
|
||||
$httpXRewriteUrl = $request->getHeader('X-Rewrite-Url');
|
||||
if ($httpXRewriteUrl) {
|
||||
$requestUri = $httpXRewriteUrl->getFieldValue();
|
||||
}
|
||||
|
||||
$httpXOriginalUrl = $request->getHeader('X-Original-Url');
|
||||
if ($httpXOriginalUrl) {
|
||||
$requestUri = $httpXOriginalUrl->getFieldValue();
|
||||
}
|
||||
|
||||
if ($requestUri) {
|
||||
$request->setUri($requestUri)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If you use a listener such as the above, make sure you also instruct your web
|
||||
server to strip any incoming headers of the same name so that you can
|
||||
guarantee they are issued by the ISAPI_Rewrite module.
|
||||
|
||||
### Deprecated
|
||||
|
||||
- Nothing.
|
||||
|
||||
### Removed
|
||||
|
||||
- Nothing.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Nothing.
|
||||
|
||||
## 2.8.0 - 2018-04-26
|
||||
|
||||
### Added
|
||||
|
||||
- [#135](https://github.com/zendframework/zend-http/pull/135) adds a package suggestion of paragonie/certainty, which provides automated
|
||||
management of cacert.pem files.
|
||||
|
||||
- [#143](https://github.com/zendframework/zend-http/pull/143) adds support for PHP 7.2.
|
||||
|
||||
### Changed
|
||||
|
||||
- Nothing.
|
||||
|
||||
### Deprecated
|
||||
|
||||
- Nothing.
|
||||
|
||||
### Removed
|
||||
|
||||
- Nothing.
|
||||
|
||||
### Fixed
|
||||
|
||||
- [#140](https://github.com/zendframework/zend-http/pull/140) fixes retrieval of headers when multiple headers of the same name
|
||||
are added to the `Headers` instance; it now ensures that the last header added of the same
|
||||
type is retrieved when it is not a multi-value type. Previous values are overwritten.
|
||||
|
||||
- [#112](https://github.com/zendframework/zend-http/pull/112) provides performance improvements when parsing large chunked messages.
|
||||
|
||||
- introduces changes to `Response::fromString()` to pull the next line of the response
|
||||
and parse it for the status when a 100 status code is initially encountered, per https://tools.ietf.org/html/rfc7231\#section-6.2.1
|
||||
|
||||
- [#122](https://github.com/zendframework/zend-http/pull/122) fixes an issue with the stream response whereby if the `outputstream`
|
||||
option is set, the output file was opened twice; it is now opened exactly once.
|
||||
|
||||
- [#147](https://github.com/zendframework/zend-http/pull/147) fixes an issue with header retrieval when the header line is malformed.
|
||||
Previously, an exception would be raised if a specific `HeaderInterface` implementation determined
|
||||
the header line was invalid. Now, `Header::has()` will return false for such headers, allowing
|
||||
`Request::getHeader()` to return `false` or the provided default value. Additionally, in cases
|
||||
where the header name is malformed (e.g., `Useragent` instead of `User-Agent`, users can still
|
||||
retrieve by the submitted header name; they will receive a `GenericHeader` instance in such
|
||||
cases, however.
|
||||
|
||||
- [#133](https://github.com/zendframework/zend-http/pull/133) Adds back missing
|
||||
sprintf placeholder in CacheControl exception message
|
||||
|
||||
## 2.7.0 - 2017-10-13
|
||||
|
||||
### Added
|
||||
|
||||
- [#110](https://github.com/zendframework/zend-http/pull/110) Adds status
|
||||
codes 226, 308, 444, 499, 510, 599 with their corresponding constants and
|
||||
reason phrases.
|
||||
|
||||
### Changed
|
||||
|
||||
- [#120](https://github.com/zendframework/zend-http/pull/120) Changes handling
|
||||
of Cookie Max-Age parameter to conform to specification
|
||||
[rfc6265#section-5.2.2](https://tools.ietf.org/html/rfc6265#section-5.2.2).
|
||||
Specifically, non-numeric values are ignored and negative numbers are changed
|
||||
to 0.
|
||||
|
||||
### Deprecated
|
||||
|
||||
- Nothing.
|
||||
|
||||
### Removed
|
||||
|
||||
- [#115](https://github.com/zendframework/zend-http/pull/115) dropped php 5.5
|
||||
support
|
||||
|
||||
### Fixed
|
||||
|
||||
- [#130](https://github.com/zendframework/zend-http/pull/130) Fixed cURL
|
||||
adapter not resetting headers from previous request when used with output
|
||||
stream.
|
||||
|
||||
## 2.6.0 - 2017-01-31
|
||||
|
||||
### Added
|
||||
- [#99](https://github.com/zendframework/zend-http/pull/99) added
|
||||
TimeoutException for cURL adapter.
|
||||
- [#98](https://github.com/zendframework/zend-http/pull/98) added connection
|
||||
timeout (`connecttimeout`) for cURL and Socket adapters.
|
||||
- [#97](https://github.com/zendframework/zend-http/pull/97) added support to
|
||||
`sslcafile` and `sslcapath` to cURL adapter.
|
||||
|
||||
### Deprecated
|
||||
|
||||
- Nothing.
|
||||
|
||||
### Removed
|
||||
|
||||
- Nothing.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Nothing.
|
||||
|
||||
## 2.5.6 - 2017-01-31
|
||||
|
||||
### Added
|
||||
|
||||
@@ -18,7 +174,17 @@ All notable changes to this project will be documented in this file, in reverse
|
||||
|
||||
### Fixed
|
||||
|
||||
- Nothing.
|
||||
- [#107](https://github.com/zendframework/zend-http/pull/107) fixes the
|
||||
`Expires` header to allow values of `0` or `'0'`; these now resolve
|
||||
to the start of the unix epoch (1970-01-01).
|
||||
- [#102](https://github.com/zendframework/zend-http/pull/102) fixes the Curl
|
||||
adapter timeout detection.
|
||||
- [#93](https://github.com/zendframework/zend-http/pull/93) fixes the Content
|
||||
Security Policy CSP HTTP header when it is `none` (empty value).
|
||||
- [#92](https://github.com/zendframework/zend-http/pull/92) fixes the flatten
|
||||
cookies value for array value (also multidimensional).
|
||||
- [#34](https://github.com/zendframework/zend-http/pull/34) fixes the
|
||||
standard separator (&) for application/x-www-form-urlencoded.
|
||||
|
||||
## 2.5.5 - 2016-08-08
|
||||
|
||||
|
43
vendor/zendframework/zend-http/CONDUCT.md
vendored
43
vendor/zendframework/zend-http/CONDUCT.md
vendored
@@ -1,43 +0,0 @@
|
||||
# Contributor Code of Conduct
|
||||
|
||||
The Zend Framework project adheres to [The Code Manifesto](http://codemanifesto.com)
|
||||
as its guidelines for contributor interactions.
|
||||
|
||||
## The Code Manifesto
|
||||
|
||||
We want to work in an ecosystem that empowers developers to reach their
|
||||
potential — one that encourages growth and effective collaboration. A space that
|
||||
is safe for all.
|
||||
|
||||
A space such as this benefits everyone that participates in it. It encourages
|
||||
new developers to enter our field. It is through discussion and collaboration
|
||||
that we grow, and through growth that we improve.
|
||||
|
||||
In the effort to create such a place, we hold to these values:
|
||||
|
||||
1. **Discrimination limits us.** This includes discrimination on the basis of
|
||||
race, gender, sexual orientation, gender identity, age, nationality, technology
|
||||
and any other arbitrary exclusion of a group of people.
|
||||
2. **Boundaries honor us.** Your comfort levels are not everyone’s comfort
|
||||
levels. Remember that, and if brought to your attention, heed it.
|
||||
3. **We are our biggest assets.** None of us were born masters of our trade.
|
||||
Each of us has been helped along the way. Return that favor, when and where
|
||||
you can.
|
||||
4. **We are resources for the future.** As an extension of #3, share what you
|
||||
know. Make yourself a resource to help those that come after you.
|
||||
5. **Respect defines us.** Treat others as you wish to be treated. Make your
|
||||
discussions, criticisms and debates from a position of respectfulness. Ask
|
||||
yourself, is it true? Is it necessary? Is it constructive? Anything less is
|
||||
unacceptable.
|
||||
6. **Reactions require grace.** Angry responses are valid, but abusive language
|
||||
and vindictive actions are toxic. When something happens that offends you,
|
||||
handle it assertively, but be respectful. Escalate reasonably, and try to
|
||||
allow the offender an opportunity to explain themselves, and possibly correct
|
||||
the issue.
|
||||
7. **Opinions are just that: opinions.** Each and every one of us, due to our
|
||||
background and upbringing, have varying opinions. The fact of the matter, is
|
||||
that is perfectly acceptable. Remember this: if you respect your own
|
||||
opinions, you should respect the opinions of others.
|
||||
8. **To err is human.** You might not intend it, but mistakes do happen and
|
||||
contribute to build experience. Tolerate honest mistakes, and don't hesitate
|
||||
to apologize if you make one yourself.
|
234
vendor/zendframework/zend-http/CONTRIBUTING.md
vendored
234
vendor/zendframework/zend-http/CONTRIBUTING.md
vendored
@@ -1,234 +0,0 @@
|
||||
# CONTRIBUTING
|
||||
|
||||
## RESOURCES
|
||||
|
||||
If you wish to contribute to Zend Framework, please be sure to
|
||||
read/subscribe to the following resources:
|
||||
|
||||
- [Coding Standards](https://github.com/zendframework/zf2/wiki/Coding-Standards)
|
||||
- [Contributor's Guide](http://framework.zend.com/participate/contributor-guide)
|
||||
- ZF Contributor's mailing list:
|
||||
Archives: http://zend-framework-community.634137.n4.nabble.com/ZF-Contributor-f680267.html
|
||||
Subscribe: zf-contributors-subscribe@lists.zend.com
|
||||
- ZF Contributor's IRC channel:
|
||||
#zftalk.dev on Freenode.net
|
||||
|
||||
If you are working on new features or refactoring [create a proposal](https://github.com/zendframework/zend-http/issues/new).
|
||||
|
||||
## Reporting Potential Security Issues
|
||||
|
||||
If you have encountered a potential security vulnerability, please **DO NOT** report it on the public
|
||||
issue tracker: send it to us at [zf-security@zend.com](mailto:zf-security@zend.com) instead.
|
||||
We will work with you to verify the vulnerability and patch it as soon as possible.
|
||||
|
||||
When reporting issues, please provide the following information:
|
||||
|
||||
- Component(s) affected
|
||||
- A description indicating how to reproduce the issue
|
||||
- A summary of the security vulnerability and impact
|
||||
|
||||
We request that you contact us via the email address above and give the project
|
||||
contributors a chance to resolve the vulnerability and issue a new release prior
|
||||
to any public exposure; this helps protect users and provides them with a chance
|
||||
to upgrade and/or update in order to protect their applications.
|
||||
|
||||
For sensitive email communications, please use [our PGP key](http://framework.zend.com/zf-security-pgp-key.asc).
|
||||
|
||||
## RUNNING TESTS
|
||||
|
||||
> ### Note: testing versions prior to 2.4
|
||||
>
|
||||
> This component originates with Zend Framework 2. During the lifetime of ZF2,
|
||||
> testing infrastructure migrated from PHPUnit 3 to PHPUnit 4. In most cases, no
|
||||
> changes were necessary. However, due to the migration, tests may not run on
|
||||
> versions < 2.4. As such, you may need to change the PHPUnit dependency if
|
||||
> attempting a fix on such a version.
|
||||
|
||||
To run tests:
|
||||
|
||||
- Clone the repository:
|
||||
|
||||
```console
|
||||
$ git clone git@github.com:zendframework/zend-http.git
|
||||
$ cd
|
||||
```
|
||||
|
||||
- Install dependencies via composer:
|
||||
|
||||
```console
|
||||
$ curl -sS https://getcomposer.org/installer | php --
|
||||
$ ./composer.phar install
|
||||
```
|
||||
|
||||
If you don't have `curl` installed, you can also download `composer.phar` from https://getcomposer.org/
|
||||
|
||||
- Run the tests via `phpunit` and the provided PHPUnit config, like in this example:
|
||||
|
||||
```console
|
||||
$ ./vendor/bin/phpunit
|
||||
```
|
||||
|
||||
You can turn on conditional tests with the phpunit.xml file.
|
||||
To do so:
|
||||
|
||||
- Copy `phpunit.xml.dist` file to `phpunit.xml`
|
||||
- Edit `phpunit.xml` to enable any specific functionality you
|
||||
want to test, as well as to provide test values to utilize.
|
||||
|
||||
## Running Coding Standards Checks
|
||||
|
||||
This component uses [php-cs-fixer](http://cs.sensiolabs.org/) for coding
|
||||
standards checks, and provides configuration for our selected checks.
|
||||
`php-cs-fixer` is installed by default via Composer.
|
||||
|
||||
To run checks only:
|
||||
|
||||
```console
|
||||
$ ./vendor/bin/php-cs-fixer fix . -v --diff --dry-run --config-file=.php_cs
|
||||
```
|
||||
|
||||
To have `php-cs-fixer` attempt to fix problems for you, omit the `--dry-run`
|
||||
flag:
|
||||
|
||||
```console
|
||||
$ ./vendor/bin/php-cs-fixer fix . -v --diff --config-file=.php_cs
|
||||
```
|
||||
|
||||
If you allow php-cs-fixer to fix CS issues, please re-run the tests to ensure
|
||||
they pass, and make sure you add and commit the changes after verification.
|
||||
|
||||
## Recommended Workflow for Contributions
|
||||
|
||||
Your first step is to establish a public repository from which we can
|
||||
pull your work into the master repository. We recommend using
|
||||
[GitHub](https://github.com), as that is where the component is already hosted.
|
||||
|
||||
1. Setup a [GitHub account](http://github.com/), if you haven't yet
|
||||
2. Fork the repository (http://github.com/zendframework/zend-http)
|
||||
3. Clone the canonical repository locally and enter it.
|
||||
|
||||
```console
|
||||
$ git clone git://github.com:zendframework/zend-http.git
|
||||
$ cd zend-http
|
||||
```
|
||||
|
||||
4. Add a remote to your fork; substitute your GitHub username in the command
|
||||
below.
|
||||
|
||||
```console
|
||||
$ git remote add {username} git@github.com:{username}/zend-http.git
|
||||
$ git fetch {username}
|
||||
```
|
||||
|
||||
### Keeping Up-to-Date
|
||||
|
||||
Periodically, you should update your fork or personal repository to
|
||||
match the canonical ZF repository. Assuming you have setup your local repository
|
||||
per the instructions above, you can do the following:
|
||||
|
||||
|
||||
```console
|
||||
$ git checkout master
|
||||
$ git fetch origin
|
||||
$ git rebase origin/master
|
||||
# OPTIONALLY, to keep your remote up-to-date -
|
||||
$ git push {username} master:master
|
||||
```
|
||||
|
||||
If you're tracking other branches -- for example, the "develop" branch, where
|
||||
new feature development occurs -- you'll want to do the same operations for that
|
||||
branch; simply substitute "develop" for "master".
|
||||
|
||||
### Working on a patch
|
||||
|
||||
We recommend you do each new feature or bugfix in a new branch. This simplifies
|
||||
the task of code review as well as the task of merging your changes into the
|
||||
canonical repository.
|
||||
|
||||
A typical workflow will then consist of the following:
|
||||
|
||||
1. Create a new local branch based off either your master or develop branch.
|
||||
2. Switch to your new local branch. (This step can be combined with the
|
||||
previous step with the use of `git checkout -b`.)
|
||||
3. Do some work, commit, repeat as necessary.
|
||||
4. Push the local branch to your remote repository.
|
||||
5. Send a pull request.
|
||||
|
||||
The mechanics of this process are actually quite trivial. Below, we will
|
||||
create a branch for fixing an issue in the tracker.
|
||||
|
||||
```console
|
||||
$ git checkout -b hotfix/9295
|
||||
Switched to a new branch 'hotfix/9295'
|
||||
```
|
||||
|
||||
... do some work ...
|
||||
|
||||
|
||||
```console
|
||||
$ git commit
|
||||
```
|
||||
|
||||
... write your log message ...
|
||||
|
||||
|
||||
```console
|
||||
$ git push {username} hotfix/9295:hotfix/9295
|
||||
Counting objects: 38, done.
|
||||
Delta compression using up to 2 threads.
|
||||
Compression objects: 100% (18/18), done.
|
||||
Writing objects: 100% (20/20), 8.19KiB, done.
|
||||
Total 20 (delta 12), reused 0 (delta 0)
|
||||
To ssh://git@github.com/{username}/zend-http.git
|
||||
b5583aa..4f51698 HEAD -> master
|
||||
```
|
||||
|
||||
To send a pull request, you have two options.
|
||||
|
||||
If using GitHub, you can do the pull request from there. Navigate to
|
||||
your repository, select the branch you just created, and then select the
|
||||
"Pull Request" button in the upper right. Select the user/organization
|
||||
"zendframework" as the recipient.
|
||||
|
||||
If using your own repository - or even if using GitHub - you can use `git
|
||||
format-patch` to create a patchset for us to apply; in fact, this is
|
||||
**recommended** for security-related patches. If you use `format-patch`, please
|
||||
send the patches as attachments to:
|
||||
|
||||
- zf-devteam@zend.com for patches without security implications
|
||||
- zf-security@zend.com for security patches
|
||||
|
||||
#### What branch to issue the pull request against?
|
||||
|
||||
Which branch should you issue a pull request against?
|
||||
|
||||
- For fixes against the stable release, issue the pull request against the
|
||||
"master" branch.
|
||||
- For new features, or fixes that introduce new elements to the public API (such
|
||||
as new public methods or properties), issue the pull request against the
|
||||
"develop" branch.
|
||||
|
||||
### Branch Cleanup
|
||||
|
||||
As you might imagine, if you are a frequent contributor, you'll start to
|
||||
get a ton of branches both locally and on your remote.
|
||||
|
||||
Once you know that your changes have been accepted to the master
|
||||
repository, we suggest doing some cleanup of these branches.
|
||||
|
||||
- Local branch cleanup
|
||||
|
||||
```console
|
||||
$ git branch -d <branchname>
|
||||
```
|
||||
|
||||
- Remote branch removal
|
||||
|
||||
```console
|
||||
$ git push {username} :<branchname>
|
||||
```
|
||||
|
||||
|
||||
## Conduct
|
||||
|
||||
Please see our [CONDUCT.md](CONDUCT.md) to understand expected behavior when interacting with others in the project.
|
13
vendor/zendframework/zend-http/LICENSE.md
vendored
13
vendor/zendframework/zend-http/LICENSE.md
vendored
@@ -1,16 +1,15 @@
|
||||
Copyright (c) 2005-2015, Zend Technologies USA, Inc.
|
||||
|
||||
Copyright (c) 2005-2018, Zend Technologies USA, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
- Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
- Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
- Neither the name of Zend Technologies USA, Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
|
8
vendor/zendframework/zend-http/README.md
vendored
8
vendor/zendframework/zend-http/README.md
vendored
@@ -1,15 +1,15 @@
|
||||
# zend-http
|
||||
|
||||
[](https://secure.travis-ci.org/zendframework/zend-http)
|
||||
[](https://coveralls.io/r/zendframework/zend-http?branch=master)
|
||||
[](https://coveralls.io/github/zendframework/zend-http?branch=master)
|
||||
|
||||
zend-http provides the HTTP message abstraction used by
|
||||
[zend-mvc](https://zendframework.github.io/zend-mvc/), and also provides an
|
||||
[zend-mvc](https://docs.zendframework.com/zend-mvc/), and also provides an
|
||||
extensible, adapter-driven HTTP client library.
|
||||
|
||||
This library **does not** support [PSR-7](http://www.php-fig.org/psr/psr-7), as
|
||||
it predates that specification. For PSR-7 support, please see our
|
||||
[Diactoros component](https://zendframework.github.io/zend-diactoros/).
|
||||
[Diactoros component](https://docs.zendframework.com/zend-diactoros/).
|
||||
|
||||
- File issues at https://github.com/zendframework/zend-http/issues
|
||||
- Documentation is at https://zendframework.github.io/zend-http/
|
||||
- Documentation is at https://docs.zendframework.com/zend-http/
|
||||
|
60
vendor/zendframework/zend-http/composer.json
vendored
60
vendor/zendframework/zend-http/composer.json
vendored
@@ -1,29 +1,36 @@
|
||||
{
|
||||
"name": "zendframework/zend-http",
|
||||
"description": "provides an easy interface for performing Hyper-Text Transfer Protocol (HTTP) requests",
|
||||
"description": "Provides an easy interface for performing Hyper-Text Transfer Protocol (HTTP) requests",
|
||||
"license": "BSD-3-Clause",
|
||||
"keywords": [
|
||||
"zf2",
|
||||
"http"
|
||||
"zf",
|
||||
"zend",
|
||||
"zendframework",
|
||||
"http",
|
||||
"HTTP client"
|
||||
],
|
||||
"homepage": "https://github.com/zendframework/zend-http",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.5-dev",
|
||||
"dev-develop": "2.6-dev"
|
||||
}
|
||||
"support": {
|
||||
"docs": "https://docs.zendframework.com/zend-http/",
|
||||
"issues": "https://github.com/zendframework/zend-http/issues",
|
||||
"source": "https://github.com/zendframework/zend-http",
|
||||
"rss": "https://github.com/zendframework/zend-http/releases.atom",
|
||||
"chat": "https://zendframework-slack.herokuapp.com",
|
||||
"forum": "https://discourse.zendframework.com/c/questions/components"
|
||||
},
|
||||
"require": {
|
||||
"php": "^5.5 || ^7.0",
|
||||
"zendframework/zend-loader": "^2.5",
|
||||
"zendframework/zend-stdlib": "^2.5 || ^3.0",
|
||||
"zendframework/zend-uri": "^2.5",
|
||||
"zendframework/zend-validator": "^2.5"
|
||||
"php": "^5.6 || ^7.0",
|
||||
"zendframework/zend-loader": "^2.5.1",
|
||||
"zendframework/zend-stdlib": "^3.1 || ^2.7.7",
|
||||
"zendframework/zend-uri": "^2.5.2",
|
||||
"zendframework/zend-validator": "^2.10.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"fabpot/php-cs-fixer": "1.7.*",
|
||||
"phpunit/PHPUnit": "^4.0",
|
||||
"zendframework/zend-config": "^2.5"
|
||||
"phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.3",
|
||||
"zendframework/zend-coding-standard": "~1.0.0",
|
||||
"zendframework/zend-config": "^3.1 || ^2.6"
|
||||
},
|
||||
"suggest": {
|
||||
"paragonie/certainty": "For automated management of cacert.pem"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@@ -34,5 +41,24 @@
|
||||
"psr-4": {
|
||||
"ZendTest\\Http\\": "test/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.8.x-dev",
|
||||
"dev-develop": "2.9.x-dev"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"check": [
|
||||
"@cs-check",
|
||||
"@test"
|
||||
],
|
||||
"cs-check": "phpcs",
|
||||
"cs-fix": "phpcbf",
|
||||
"test": "phpunit --colors=always",
|
||||
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
|
||||
}
|
||||
}
|
||||
|
@@ -1,529 +0,0 @@
|
||||
# HTTP Client Connection Adapters
|
||||
|
||||
`Zend\Http\Client` is based on a connection adapter design. The connection adapter is the object in
|
||||
charge of performing the actual connection to the server, as well as writing requests and reading
|
||||
responses. This connection adapter can be replaced, and you can create and extend the default
|
||||
connection adapters to suit your special needs, without the need to extend or replace the entire
|
||||
HTTP client class.
|
||||
|
||||
Currently, zend-http provides four built-in client connection adapters:
|
||||
|
||||
- `Zend\Http\Client\Adapter\Socket` (default)
|
||||
- `Zend\Http\Client\Adapter\Proxy`
|
||||
- `Zend\Http\Client\Adapter\Curl`
|
||||
- `Zend\Http\Client\Adapter\Test`
|
||||
|
||||
The client can accept an adapter via either its `setAdapter()` method, or during
|
||||
instantiation via its `adapter` configuration option. When using configuration,
|
||||
the value of the `adapter` option may be one of:
|
||||
|
||||
- an adapter instance
|
||||
- the fully qualified class name of an adapter
|
||||
|
||||
## The Socket adapter
|
||||
|
||||
The default connection adapter used when none is specified is the
|
||||
`Zend\Http\Client\Adapter\Socket` adapter. The `Socket` adapter is based on
|
||||
PHP's built-in `fsockopen()` function, and does not require any special
|
||||
extensions or compilation flags.
|
||||
|
||||
The `Socket` adapter allows several extra configuration options that can be set
|
||||
via either the client's constructor or `setOptions()` method:
|
||||
|
||||
Parameter | Description | Expected Type | Default Value
|
||||
---------------------|--------------------------------------------------------------------------------------|---------------|--------------
|
||||
`persistent` | Whether to use persistent TCP connections | boolean | `FALSE`
|
||||
`ssltransport` | SSL transport layer (eg. `sslv2`, `tls`) | string | `ssl`
|
||||
`sslcert` | Path to a PEM encoded SSL certificate | string | `NULL`
|
||||
`sslpassphrase` | Passphrase for the SSL certificate file | string | `NULL`
|
||||
`sslverifypeer` | Whether to verify the SSL peer | string | `TRUE`
|
||||
`sslcapath` | Path to SSL certificate directory | string | `NULL`
|
||||
`sslallowselfsigned` | Whether to allow self-signed certificates | string | `FALSE`
|
||||
`sslusecontext` | Enables proxied connections to use SSL even if the proxy connection itself does not. | boolean | `FALSE`
|
||||
|
||||
> ### Persistent TCP connections
|
||||
>
|
||||
> Using persistent TCP connections can potentially speed up HTTP requests, but
|
||||
> in most use cases, will have little positive effect and might overload the
|
||||
> HTTP server you are connecting to. It is recommended to use persistent TCP
|
||||
> connections only if you connect to the same server very frequently, and are
|
||||
> sure that the server is capable of handling a large number of concurrent
|
||||
> connections. In any case you are encouraged to benchmark the effect of
|
||||
> persistent connections on both the client speed and server load before using
|
||||
> this option.
|
||||
>
|
||||
> Additionally, when using persistent connections, we recommend enabling
|
||||
> Keep-Alive HTTP requests as described in [the client configuration section](intro.md#configuration);
|
||||
> otherwise persistent connections might have little or no effect.
|
||||
|
||||
> ### HTTPS SSL stream parameters
|
||||
>
|
||||
> `ssltransport`, `sslcert` and `sslpassphrase` are only relevant when
|
||||
> connecting using HTTPS. While the default SSL/TLS settings should work for
|
||||
> most applications, you might need to change them if the server you are
|
||||
> connecting to requires special client setup. If so, please read the
|
||||
> [PHP manual chapter on SSL and TLS transport options](http://php.net/transports.inet).
|
||||
|
||||
### Changing the HTTPS transport layer
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
// Set the configuration parameters
|
||||
$config = [
|
||||
'adapter' => Client\Adapter\Socket::class,
|
||||
'ssltransport' => 'tls',
|
||||
];
|
||||
|
||||
// Instantiate a client object
|
||||
$client = new Client('https://www.example.com', $config);
|
||||
|
||||
// The following request will be sent over a TLS secure connection.
|
||||
$response = $client->send();
|
||||
```
|
||||
|
||||
The result of the example above will be similar to opening a TCP connection
|
||||
using the following PHP command:
|
||||
|
||||
```php
|
||||
fsockopen('tls://www.example.com', 443);
|
||||
```
|
||||
|
||||
### Customizing and accessing the Socket adapter stream context
|
||||
|
||||
`Zend\Http\Client\Adapter\Socket` provides direct access to the underlying
|
||||
[stream context](http://php.net/stream.contexts) used to connect to the remote
|
||||
server. This allows the user to pass specific options and parameters to the TCP
|
||||
stream, and to the SSL wrapper in case of HTTPS connections.
|
||||
|
||||
You can access the stream context using the following methods of
|
||||
`Zend\Http\Client\Adapter\Socket`:
|
||||
|
||||
- `setStreamContext($context)`: Sets the stream context to be used by the
|
||||
adapter. Can accept either a stream context resource created using the
|
||||
[stream_context_create()](http://php.net/stream_context_create) PHP function,
|
||||
or an array of stream context options, in the same format provided to this
|
||||
function. Providing an array will create a new stream context using these
|
||||
options, and set it.
|
||||
- `getStreamContext()`: Get the current stream context of the adapter. If no
|
||||
stream context was set, this method will create a default stream context and
|
||||
return it. You can then set or get the value of different context options
|
||||
using regular PHP stream context functions.
|
||||
|
||||
#### Setting stream context options for the Socket adapter
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
// Array of options
|
||||
$options = [
|
||||
'socket' => [
|
||||
// Bind local socket side to a specific interface
|
||||
'bindto' => '10.1.2.3:50505',
|
||||
],
|
||||
'ssl' => [
|
||||
// Verify server side certificate,
|
||||
// do not accept invalid or self-signed SSL certificates
|
||||
'verify_peer' => true,
|
||||
'allow_self_signed' => false,
|
||||
|
||||
// Capture the peer's certificate
|
||||
'capture_peer_cert' => true,
|
||||
],
|
||||
];
|
||||
|
||||
// Create an adapter object and attach it to the HTTP client:
|
||||
$adapter = new Client\Adapter\Socket();
|
||||
$client = new Client();
|
||||
$client->setAdapter($adapter);
|
||||
|
||||
// Method 1: pass the options array to setStreamContext():
|
||||
$adapter->setStreamContext($options);
|
||||
|
||||
// Method 2: create a stream context and pass it to setStreamContext():
|
||||
$context = stream_context_create($options);
|
||||
$adapter->setStreamContext($context);
|
||||
|
||||
// Method 3: get the default stream context and set the options on it:
|
||||
$context = $adapter->getStreamContext();
|
||||
stream_context_set_option($context, $options);
|
||||
|
||||
// Now, perform the request:
|
||||
$response = $client->send();
|
||||
|
||||
// If everything went well, you can now access the context again:
|
||||
$opts = stream_context_get_options($adapter->getStreamContext());
|
||||
echo $opts['ssl']['peer_certificate'];
|
||||
```
|
||||
|
||||
> #### Set stream context options prior to requests
|
||||
>
|
||||
> Note that you must set any stream context options before using the adapter to
|
||||
> perform actual requests. If no context is set before performing HTTP requests
|
||||
> with the `Socket` adapter, a default stream context will be created. This
|
||||
> context resource could be accessed after performing any requests using the
|
||||
> `getStreamContext()` method.
|
||||
|
||||
## The Proxy adapter
|
||||
|
||||
`Zend\Http\Client\Adapter\Proxy` is similar to the default `Socket` adapter; the
|
||||
primary difference is that the connection is made through an HTTP proxy server
|
||||
instead of a direct connection to the target server. This allows usage of
|
||||
`Zend\Http\Client` behind proxy servers, which is sometimes required for
|
||||
security or performance reasons.
|
||||
|
||||
Using the `Proxy` adapter requires several additional client configuration
|
||||
parameters to be set, in addition to the default `adapter` option:
|
||||
|
||||
Parameter | Description | Expected Type | Example Value
|
||||
-------------|--------------------------------|---------------|--------------
|
||||
`proxy_host` | Proxy server address | string | 'proxy.myhost.com'’ or '10.1.2.3'
|
||||
`proxy_port` | Proxy server TCP port | integer | 8080 (default) or 81
|
||||
`proxy_user` | Proxy user name, if required | string | 'shahar' or '' for none (default)
|
||||
`proxy_pass` | Proxy password, if required | string | 'secret' or '' for none (default)
|
||||
`proxy_auth` | Proxy HTTP authentication type | string | `Zend\Http\Client::AUTH_BASIC` (default)
|
||||
|
||||
`proxy_host` should always be set; if it is not set, the client will fall back
|
||||
to a direct connection using `Zend\Http\Client\Adapter\Socket`. `proxy_port`
|
||||
defaults to '8080'; if your proxy listens on a different port, you must set this
|
||||
one as well.
|
||||
|
||||
`proxy_user` and `proxy_pass` are only required if your proxy server requires
|
||||
you to authenticate. Providing these will add a 'Proxy-Authentication' header
|
||||
to the request. If your proxy does not require authentication, you can leave
|
||||
these two options out.
|
||||
|
||||
`proxy_auth` sets the proxy authentication type, if your proxy server requires
|
||||
authentication. Possible values are similar to the ones accepted by the
|
||||
`Zend\Http\Client::setAuth()` method. Currently, only basic authentication
|
||||
(`Zend\Http\Client::AUTH_BASIC`) is supported.
|
||||
|
||||
### Using Zend\\Http\\Client behind a proxy server
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
// Set the configuration parameters
|
||||
$config = [
|
||||
'adapter' => Client\Adapter\Proxy::class,
|
||||
'proxy_host' => 'proxy.int.zend.com',
|
||||
'proxy_port' => 8000,
|
||||
'proxy_user' => 'shahar.e',
|
||||
'proxy_pass' => 'bananashaped',
|
||||
];
|
||||
|
||||
// Instantiate a client object
|
||||
$client = new Client('http://www.example.com', $config);
|
||||
|
||||
// Continue working...
|
||||
```
|
||||
|
||||
As mentioned, if `proxy_host` is not set or is set to a blank string, the
|
||||
connection will fall back to a regular direct connection. This allows you to
|
||||
write your application in a way that allows a proxy to be used optionally,
|
||||
according to a configuration parameter.
|
||||
|
||||
> ### Access to stream context
|
||||
>
|
||||
> Since the proxy adapter inherits from `Zend\Http\Client\Adapter\Socket`, you
|
||||
> can use the stream context access method (see
|
||||
> [above](#setting-stream-context-options-for-the-socket-adapter)) to set stream
|
||||
> context options on `Proxy` connections.
|
||||
|
||||
## The cURL Adapter
|
||||
|
||||
cURL is a standard HTTP client library that is distributed with many operating
|
||||
systems and can be used in PHP via the cURL extension. It offers functionality
|
||||
for many special cases which can occur for a HTTP client and make it a perfect
|
||||
choice for a HTTP adapter. It supports secure connections, proxies, and multiple
|
||||
authentication mechanisms. In particular, it is very performant with regards to
|
||||
transfering large files.
|
||||
|
||||
### Setting cURL options
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
$config = [
|
||||
'adapter' => Client\Adapter\Curl::class,
|
||||
'curloptions' => [CURLOPT_FOLLOWLOCATION => true],
|
||||
];
|
||||
$client = new Client($uri, $config);
|
||||
```
|
||||
|
||||
By default, the cURL adapter is configured to behave exactly like the `Socket`
|
||||
adapter, and it also accepts the same configuration parameters as the `Socket`
|
||||
and `Proxy` adapters. You can also change the cURL options by either specifying
|
||||
the 'curloptions' key in the constructor of the adapter, or by calling
|
||||
`setCurlOption($name, $value)`; option names correspond to the `CURL_*`
|
||||
constants of the cURL extension. You can get access to the underling cURL handle
|
||||
by calling `$adapter->getHandle();`
|
||||
|
||||
### Transfering files by handle
|
||||
|
||||
You can use cURL to transfer very large files over HTTP by filehandle.
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
$putFileSize = filesize('filepath');
|
||||
$putFileHandle = fopen('filepath', 'r');
|
||||
|
||||
$adapter = new Client\Adapter\Curl();
|
||||
$client = new Client();
|
||||
$client->setAdapter($adapter);
|
||||
$client->setMethod('PUT');
|
||||
$adapter->setOptions([
|
||||
'curloptions' => [
|
||||
CURLOPT_INFILE => $putFileHandle,
|
||||
CURLOPT_INFILESIZE => $putFileSize,
|
||||
],
|
||||
]);
|
||||
$client->send();
|
||||
```
|
||||
|
||||
## The Test adapter
|
||||
|
||||
Testing code that relies on HTTP connections poses difficulties. For example,
|
||||
testing an application that pulls an RSS feed from a remote server will require
|
||||
a network connection, which is not always available.
|
||||
|
||||
`Zend\Http\Client\Adapter\Test` provides a solution for these situations and
|
||||
acts as a mock object for unit tests. You can write your application to use
|
||||
`Zend\Http\Client`, and, when testing (either in your unit test suite, or in
|
||||
non-production environments), replace the default adapter with the test adapter,
|
||||
allowing you to run tests without actually performing server connections.
|
||||
|
||||
`Zend\Http\Client\Adapter\Test` provides two additional methods, `setResponse()`
|
||||
and `addResponse()`. Each takes one parameter, which represents an HTTP
|
||||
response as either text or a `Zend\Http\Response` object. `setResponse()` sets
|
||||
an individual response to always return from any request; `addResponse()` allows
|
||||
aggregating a sequence of responses. In both cases, responses are returned
|
||||
without performing actual HTTP requests.
|
||||
|
||||
### Testing against a single HTTP response stub
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
// Instantiate a new adapter and client
|
||||
$adapter = new Client\Adapter\Test();
|
||||
$client = new Client(
|
||||
'http://www.example.com',
|
||||
['adapter' => $adapter]
|
||||
);
|
||||
|
||||
// Set the expected response
|
||||
$adapter->setResponse(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
. "Content-type: text/xml\r\n"
|
||||
. "\r\n"
|
||||
. '<?xml version="1.0" encoding="UTF-8"?>'
|
||||
. '<rss version="2.0" '
|
||||
. ' xmlns:content="http://purl.org/rss/1.0/modules/content/"'
|
||||
. ' xmlns:wfw="http://wellformedweb.org/CommentAPI/"'
|
||||
. ' xmlns:dc="http://purl.org/dc/elements/1.1/">'
|
||||
. ' <channel>'
|
||||
. ' <title>Premature Optimization</title>'
|
||||
// and so on...
|
||||
. '</rss>'
|
||||
);
|
||||
|
||||
$response = $client->send();
|
||||
// .. continue parsing $response..
|
||||
```
|
||||
|
||||
The above example shows how you can preset your HTTP client to return the
|
||||
response you need. Then, you can continue testing your own code, without being
|
||||
dependent on a network connection, the server's response, etc. In this case, the
|
||||
test would continue to check how the application parses the XML in the response
|
||||
body.
|
||||
|
||||
Sometimes, a single method call to an object can result in that object
|
||||
performing multiple HTTP transactions. In this case, it's not possible to use
|
||||
`setResponse()` alone because there's no opportunity to set the next response(s)
|
||||
your program might need before returning to the caller.
|
||||
|
||||
### Testing Against Multiple HTTP Response Stubs
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
// Instantiate a new adapter and client
|
||||
$adapter = new Client\Adapter\Test();
|
||||
$client = new Client(
|
||||
'http://www.example.com',
|
||||
['adapter' => $adapter]
|
||||
);
|
||||
|
||||
// Set the first expected response
|
||||
$adapter->setResponse(
|
||||
"HTTP/1.1 302 Found\r\n"
|
||||
. "Location: /\r\n"
|
||||
. "Content-Type: text/html\r\n"
|
||||
. "\r\n"
|
||||
. '<html>'
|
||||
. ' <head><title>Moved</title></head>'
|
||||
. ' <body><p>This page has moved.</p></body>'
|
||||
. '</html>'
|
||||
);
|
||||
|
||||
// Set the next successive response
|
||||
$adapter->addResponse(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
. "Content-Type: text/html\r\n"
|
||||
. "\r\n"
|
||||
. '<html>'
|
||||
. ' <head><title>My Pet Store Home Page</title></head>'
|
||||
. ' <body><p>...</p></body>'
|
||||
. '</html>'
|
||||
);
|
||||
|
||||
// inject the http client object ($client) into your object
|
||||
// being tested and then test your object's behavior below
|
||||
```
|
||||
|
||||
The `setResponse()` method clears any responses in the adapter's buffer and sets
|
||||
the first response that will be returned. The `addResponse()` method will add
|
||||
successive responses.
|
||||
|
||||
The responses will be replayed in the order that they were added. If more
|
||||
requests are made than the number of responses stored, the responses will cycle
|
||||
again in order.
|
||||
|
||||
In the example above, the adapter is configured to test your object's behavior
|
||||
when it encounters a 302 redirect. Depending on your application, following a
|
||||
redirect may or may not be desired behavior. In our example, we expect that the
|
||||
redirect will be followed and we configure the test adapter to help us test
|
||||
this. The initial 302 response is set up with the `setResponse()` method and the
|
||||
200 response to be returned next is added with the `addResponse()` method. After
|
||||
configuring the test adapter, inject the HTTP client containing the adapter into
|
||||
your object under test and test its behavior.
|
||||
|
||||
### Forcing the adapter to fail
|
||||
|
||||
If you need the adapter to fail on demand you can use
|
||||
`setNextRequestWillFail($flag)`. The method will cause the next call to
|
||||
`connect()` to throw an `Zend\Http\Client\Adapter\Exception\RuntimeException`.
|
||||
This can be useful when our application caches content from an external site (in
|
||||
case the site goes down) and you want to test this feature.
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
// Instantiate a new adapter and client
|
||||
$adapter = new Client\Adapter\Test();
|
||||
$client = new Client(
|
||||
'http://www.example.com',
|
||||
['adapter' => $adapter]
|
||||
);
|
||||
|
||||
// Force the next request to fail with an exception
|
||||
$adapter->setNextRequestWillFail(true);
|
||||
|
||||
try {
|
||||
// This call will result in an exception.
|
||||
$client->send();
|
||||
} catch (Client\Adapter\Exception\RuntimeException $e) {
|
||||
// ...
|
||||
}
|
||||
|
||||
// Further requests will work as expected until
|
||||
// you call setNextRequestWillFail(true) again
|
||||
```
|
||||
|
||||
## Creating your own connection adapters
|
||||
|
||||
`Zend\Http\Client` has been designed so that you can create and use your own
|
||||
connection adapters. You could, for example, create a connection adapter that
|
||||
uses persistent sockets, or a connection adapter with caching abilities, and use
|
||||
them as needed in your application.
|
||||
|
||||
In order to do so, you must create your own adapter class that implements
|
||||
`Zend\Http\Client\Adapter\AdapterInterface`. The following example shows the
|
||||
skeleton of a user-implemented adapter class. All the public functions defined
|
||||
in this example must be defined in your adapter as well.
|
||||
|
||||
```php
|
||||
namespace MyApp\Http\Client\Adapter;
|
||||
|
||||
use Zend\Http\Client\Adapter\AdapterInterface;
|
||||
|
||||
class BananaProtocol implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Set Adapter Options
|
||||
*
|
||||
* @param array $config
|
||||
*/
|
||||
public function setOptions($config = [])
|
||||
{
|
||||
// This rarely changes - you should usually copy the
|
||||
// implementation in Zend\Http\Client\Adapter\Socket.
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the remote server
|
||||
*
|
||||
* @param string $host
|
||||
* @param int $port
|
||||
* @param boolean $secure
|
||||
*/
|
||||
public function connect($host, $port = 80, $secure = false)
|
||||
{
|
||||
// Set up the connection to the remote server
|
||||
}
|
||||
|
||||
/**
|
||||
* Send request to the remote server
|
||||
*
|
||||
* @param string $method
|
||||
* @param Zend\Uri\Http $url
|
||||
* @param string $http_ver
|
||||
* @param array $headers
|
||||
* @param string $body
|
||||
* @return string Request as text
|
||||
*/
|
||||
public function write(
|
||||
$method,
|
||||
$url,
|
||||
$http_ver = '1.1',
|
||||
$headers = [],
|
||||
$body = ''
|
||||
) {
|
||||
// Send request to the remote server.
|
||||
// This function is expected to return the full request
|
||||
// (headers and body) as a string
|
||||
}
|
||||
|
||||
/**
|
||||
* Read response from server
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
// Read response from remote server and return it as a string
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection to the server
|
||||
*
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
// Close the connection to the remote server - called last.
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Use the adapter as you would any other:
|
||||
|
||||
```php
|
||||
use MyApp\Http\Client\Adapter\BananaProtocol;
|
||||
use Zend\Http\Client;
|
||||
|
||||
$client = new Client([
|
||||
'adapter' => BananaProtocol::class,
|
||||
]);
|
||||
```
|
@@ -1,357 +0,0 @@
|
||||
# HTTP Client Advanced Usage
|
||||
|
||||
## HTTP redirections
|
||||
|
||||
`Zend\Http\Client` automatically handles HTTP redirections, and by default
|
||||
will follow up to 5 redirections. This can be changed by setting the
|
||||
`maxredirects` configuration parameter.
|
||||
|
||||
According to the HTTP/1.1 RFC, HTTP 301 and 302 responses should be treated by
|
||||
the client by resending the same request to the specified location, using the
|
||||
same request method. However, most clients to not implement this and always use
|
||||
a `GET` request when redirecting. By default, `Zend\Http\Client` does the same;
|
||||
when redirecting on a 301 or 302 response, all query and body parameters are
|
||||
reset, and a `GET` request is sent to the new location. This behavior can be
|
||||
changed by setting the `strictredirects` configuration parameter to boolean
|
||||
`TRUE`:
|
||||
|
||||
```php
|
||||
// Strict Redirections
|
||||
$client->setOptions(['strictredirects' => true]);
|
||||
|
||||
// Non-strict Redirections
|
||||
$client->setOptions(['strictredirects' => false]);
|
||||
```
|
||||
|
||||
You can always get the number of redirections done after sending a request
|
||||
using the `getRedirectionsCount()` method.
|
||||
|
||||
## Adding cookies and using cookie persistence
|
||||
|
||||
`Zend\Http\Client` provides an interface for adding cookies to your request, so
|
||||
that no direct header modification is required. Cookies can be added using
|
||||
either the addCookie() or `setCookies()` method. `addCookie()` can accept
|
||||
either a name and value, a `SetCookie` header instance, or an array of
|
||||
`SetCookie` header instances.
|
||||
|
||||
```php
|
||||
use Zend\Http\Header\SetCookie;
|
||||
|
||||
// Basic usage: provide a cookie name and cookie value:
|
||||
$client->addCookie('flavor', 'chocolate chips');
|
||||
|
||||
// Or provide a SetCookie instance:
|
||||
$cookie = SetCookie::fromString('Set-Cookie: flavor=chocolate%20chips');
|
||||
$client->addCookie($cookie);
|
||||
|
||||
// Multiple cookies can be set at once by providing an
|
||||
// array of SetCookie instances:
|
||||
$cookies = [
|
||||
SetCookie::fromString('Set-Cookie: flavorOne=chocolate%20chips'),
|
||||
SetCookie::fromString('Set-Cookie: flavorTwo=vanilla'),
|
||||
];
|
||||
$client->addCookie($cookies);
|
||||
```
|
||||
|
||||
The `setCookies()` method works in a similar manner, except that it requires an
|
||||
array of cookie name/value pairs as its only argument, and also clears the
|
||||
cookie container before adding the new cookies:
|
||||
|
||||
```php
|
||||
// setCookies accepts an array of cookie values as $name => $value
|
||||
$client->setCookies([
|
||||
'flavor' => 'chocolate chips',
|
||||
'amount' => 10,
|
||||
]);
|
||||
```
|
||||
|
||||
See the [Headers documentation](../headers.md#setcookie) for more detail on the
|
||||
`SetCookie` class.
|
||||
|
||||
### Enabling Cookie Stickiness
|
||||
|
||||
`Zend\Http\Client` also provides a means for simplifying cookie "stickiness"
|
||||
— i.e., having the client internally store all sent and received cookies,
|
||||
and resending them on subsequent requests. — via the `Zend\Http\Cookies`
|
||||
class. This is useful when you need to log in to a remote site first and
|
||||
receive an authentication or session ID cookie before sending further requests.
|
||||
|
||||
```php
|
||||
$headers = $client->getRequest()->getHeaders();
|
||||
$cookies = new Zend\Http\Cookies($headers);
|
||||
|
||||
// First request: log in and start a session
|
||||
$client->setUri('http://example.com/login.php');
|
||||
$client->setParameterPost(['user' => 'h4x0r', 'password' => 'l33t']);
|
||||
$client->setMethod('POST');
|
||||
|
||||
$response = $client->getResponse();
|
||||
$cookies->addCookiesFromResponse($response, $client->getUri());
|
||||
|
||||
// Now we can send our next request
|
||||
$client->setUri('http://example.com/read_member_news.php');
|
||||
$client->setCookies($cookies->getMatchingCookies($client->getUri()));
|
||||
$client->setMethod('GET');
|
||||
```
|
||||
|
||||
See the chapter on [cookies](cookies.md) for more detail.
|
||||
|
||||
## Setting custom request headers
|
||||
|
||||
Setting custom headers is performed by first fetching the header container from
|
||||
the client's `Zend\Http\Request` instance. This `Headers` container offers a
|
||||
number of methods for setting headers:
|
||||
|
||||
```php
|
||||
use Zend\Http\Header;
|
||||
|
||||
// Fetch the container
|
||||
$headers = $client->getRequest()->getHeaders();
|
||||
|
||||
// Setting a single header using a name and value. Will not overwrite any //
|
||||
previously-added headers of the same name.
|
||||
$headers->addHeaderLine('Host', 'www.example.com');
|
||||
|
||||
// You can also use a full header line:
|
||||
$headers->addHeaderLine('Host: www.example.com');
|
||||
|
||||
// Sometimes you may want to use a HeaderInterface instance:
|
||||
$headers->addHeader(Header\Host::fromString('Host: www.example.com'));
|
||||
|
||||
// You can also add multiple headers at once by passing an
|
||||
// array to addHeaders() using any of the formats below:
|
||||
$headers->addHeaders([
|
||||
// Zend\Http\Header\* instance:
|
||||
Header\Host::fromString('Host: www.example.com'),
|
||||
|
||||
// Header name/value pair:
|
||||
'Cookie' => 'PHPSESSID=1234567890abcdef1234567890abcdef',
|
||||
|
||||
// Raw header string:
|
||||
'Cookie: language=he',
|
||||
]);
|
||||
```
|
||||
|
||||
`Zend\Http\Client` also provides a convenience method for setting request
|
||||
headers, `setHeaders()`. This method will create a new header container, add
|
||||
the specified headers, and then store the new header container in its
|
||||
`Zend\Http\Request` instance. As a consequence, any pre-existing headers will
|
||||
be erased:
|
||||
|
||||
```php
|
||||
use Zend\Http\Header;
|
||||
|
||||
// Setting multiple headers via the client; removes all existing headers,
|
||||
// replacing the request header container with the following:
|
||||
$client->setHeaders([
|
||||
Zend\Http\Header\Host::fromString('Host: www.example.com'),
|
||||
['Accept-Encoding' => 'gzip,deflate'],
|
||||
'X-Powered-By: Zend Framework',
|
||||
]);
|
||||
```
|
||||
|
||||
## File uploads
|
||||
|
||||
You can upload files through HTTP using the `setFileUpload()` method. This
|
||||
method takes a file name as the first parameter, a form name as the second
|
||||
parameter, and data as a third optional parameter. If the third data parameter
|
||||
is `NULL`, the first file name parameter is considered to be a real file on
|
||||
disk, and `Zend\Http\Client` will try to read this file and upload it. If the
|
||||
data parameter is not `NULL`, the first file name parameter will be sent as the
|
||||
file name, but no actual file needs to exist on the disk. The second form name
|
||||
parameter is always required, and is equivalent to the "name" attribute of an
|
||||
`<input>` tag, if the file was to be uploaded through an HTML form. A fourth
|
||||
optional parameter provides the file's `Content-Type`. If not specified, and
|
||||
`Zend\Http\Client` reads the file from the disk, the `mime_content_type()`
|
||||
function will be used to guess the file's content type, if it is available. In
|
||||
any case, the default MIME type will be `application/octet-stream`.
|
||||
|
||||
```php
|
||||
// Uploading arbitrary data as a file:
|
||||
$text = 'this is some plain text';
|
||||
$client->setFileUpload('some_text.txt', 'upload', $text, 'text/plain');
|
||||
|
||||
// Uploading an existing file:
|
||||
$client->setFileUpload('/tmp/Backup.tar.gz', 'bufile');
|
||||
|
||||
// Send the files:
|
||||
$client->setMethod('POST');
|
||||
$client->send();
|
||||
```
|
||||
|
||||
In the first example, the `$text` variable is uploaded and will be available as
|
||||
`$_FILES['upload']` on the server side. In the second example, the existing
|
||||
file `/tmp/Backup.tar.gz` is uploaded to the server and will be available as
|
||||
`$_FILES['bufile']`. The content type will be guessed automatically if
|
||||
possible, defaulting to `application/octet-stream`.
|
||||
|
||||
> ### Uploading files
|
||||
>
|
||||
> When uploading files, the HTTP request `Content-Type` is automatically set to
|
||||
> `multipart/form-data`. Keep in mind that you must send a POST or PUT request
|
||||
> in order to upload files; most servers will ignore the request body on other
|
||||
> request methods.
|
||||
|
||||
## Sending raw POST data
|
||||
|
||||
You can send raw POST data via `Zend\Http\Client` using the `setRawBody()`
|
||||
method. This method takes one parameter: the data to send in the request body.
|
||||
When sending raw POST data, it is advisable to also set the encoding type using
|
||||
`setEncType()`.
|
||||
|
||||
```php
|
||||
$xml = '<book>'
|
||||
. ' <title>Islands in the Stream</title>'
|
||||
. ' <author>Ernest Hemingway</author>'
|
||||
. ' <year>1970</year>'
|
||||
. '</book>';
|
||||
$client->setMethod('POST');
|
||||
$client->setRawBody($xml);
|
||||
$client->setEncType('text/xml');
|
||||
$client->send();
|
||||
```
|
||||
|
||||
The data should be available on the server side through PHP's `php://input`
|
||||
stream.
|
||||
|
||||
> ### Raw POST data overrides other content
|
||||
>
|
||||
> Setting raw POST data for a request will override any POST parameters or file
|
||||
> uploads; you should not try to use both on the same request. Keep in mind
|
||||
> that most servers will ignore the request body unless you send a POST
|
||||
> request.
|
||||
|
||||
## HTTP authentication
|
||||
|
||||
Currently, `Zend\Http\Client` only supports basic HTTP authentication. This feature is utilized
|
||||
using the `setAuth()` method, or by specifying a username and a password in the URI. The `setAuth()`
|
||||
method takes 3 parameters: the user name, the password and an optional authentication type
|
||||
parameter.
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
// Using basic authentication
|
||||
$client->setAuth('shahar', 'myPassword!', Client::AUTH_BASIC);
|
||||
|
||||
// Since basic auth is default, you can just do this:
|
||||
$client->setAuth('shahar', 'myPassword!');
|
||||
|
||||
// You can also specify username and password in the URI
|
||||
$client->setUri('http://christer:secret@example.com');
|
||||
```
|
||||
|
||||
## Sending multiple requests with the same client
|
||||
|
||||
`Zend\Http\Client` was also designed specifically to handle several consecutive
|
||||
requests with the same object. This is useful in cases where a script requires
|
||||
data to be fetched from several places, or when accessing a specific HTTP
|
||||
resource requires logging in and obtaining a session cookie, for example.
|
||||
|
||||
When performing several requests to the same host, it is highly recommended to
|
||||
enable the 'keepalive' configuration flag. This way, if the server supports
|
||||
keep-alive connections, the connection to the server will only be closed once
|
||||
all requests are done and the `Client` object is destroyed. This prevents the
|
||||
overhead of opening and closing TCP connections to the server.
|
||||
|
||||
When you perform several requests with the same client, but want to make sure
|
||||
all the request-specific parameters are cleared, you should use the
|
||||
`resetParameters()` method. This ensures that GET and POST parameters, request
|
||||
body, and request headers are reset and are not reused in the next request.
|
||||
|
||||
> ### Resetting parameters
|
||||
>
|
||||
> Note that cookies are not reset by default when the `resetParameters()`
|
||||
> method is used. To clean all cookies as well, use `resetParameters(true)`, or
|
||||
> call `clearCookies()` after calling `resetParameters()`.
|
||||
|
||||
Another feature designed specifically for consecutive requests is the
|
||||
`Zend\Http\Cookies` object. This "Cookie Jar" allow you to save cookies set by
|
||||
the server in a request, and send them back on consecutive requests
|
||||
transparently. This allows, for example, going through an authentication
|
||||
request before sending the actual data-fetching request.
|
||||
|
||||
If your application requires one authentication request per user, and
|
||||
consecutive requests might be performed in more than one script in your
|
||||
application, it might be a good idea to store the `Cookies` object in the user's
|
||||
session. This way, you will only need to authenticate the user once every
|
||||
session.
|
||||
|
||||
### Performing consecutive requests with one client
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
use Zend\Http\Cookies;
|
||||
|
||||
// First, instantiate the client
|
||||
$client = new Client(
|
||||
'http://www.example.com/fetchdata.php',
|
||||
['keepalive' => true]
|
||||
);
|
||||
|
||||
// Do we have the cookies stored in our session?
|
||||
if (isset($_SESSION['cookiejar'])
|
||||
&& $_SESSION['cookiejar'] instanceof Cookies
|
||||
) {
|
||||
$cookieJar = $_SESSION['cookiejar'];
|
||||
} else {
|
||||
// If we don't, authenticate and store cookies
|
||||
$client->setUri('http://www.example.com/login.php');
|
||||
$client->setParameterPost([
|
||||
'user' => 'shahar',
|
||||
'pass' => 'somesecret',
|
||||
]);
|
||||
$response = $client->setMethod('POST')->send();
|
||||
$cookieJar = Cookies::fromResponse($response);
|
||||
|
||||
// Now, clear parameters and set the URI to the original one
|
||||
// (note that the cookies that were set by the server are now
|
||||
// stored in the jar)
|
||||
$client->resetParameters();
|
||||
$client->setUri('http://www.example.com/fetchdata.php');
|
||||
}
|
||||
|
||||
// Add the cookies to the new request
|
||||
$client->setCookies($cookieJar->getMatchingCookies($client->getUri()));
|
||||
$response = $client->setMethod('GET')->send();
|
||||
|
||||
// Store cookies in session, for next page
|
||||
$_SESSION['cookiejar'] = $cookieJar;
|
||||
```
|
||||
|
||||
## Data streaming
|
||||
|
||||
By default, `Zend\Http\Client` accepts and returns data as PHP strings.
|
||||
However, in many cases there are big files to be received, thus keeping them in
|
||||
memory might be unnecessary or too expensive. For these cases,
|
||||
`Zend\Http\Client` supports writing data to files (streams).
|
||||
|
||||
In order to receive data from the server as stream, use `setStream()`. The
|
||||
single, optional argument specifies the filename where the data will be stored.
|
||||
If the argument is just `TRUE` (default), a temporary file will be used and
|
||||
will be deleted once the response object is destroyed. Setting the argument to
|
||||
`FALSE` disables the streaming functionality.
|
||||
|
||||
When using streaming, the `send()` method will return an object of class
|
||||
`Zend\Http\Response\Stream`, which has two useful methods: `getStreamName()`
|
||||
will return the name of the file where the response is stored, and
|
||||
`getStream()` will return stream from which the response could be read.
|
||||
|
||||
You can either write the response to pre-defined file, or use temporary file
|
||||
for storing it and send it out or write it to another file using regular stream
|
||||
functions.
|
||||
|
||||
```php
|
||||
$client-setStream(); // will use temp file
|
||||
$response = $client-send();
|
||||
|
||||
// copy file:
|
||||
copy($response-getStreamName(), 'my/downloads/file');
|
||||
|
||||
// use stream:
|
||||
$fp = fopen('my/downloads/file2', 'w');
|
||||
stream_copy_to_stream($response-getStream(), $fp);
|
||||
|
||||
// write to an existing file:
|
||||
$client-setStream('my/downloads/myfile')-send();
|
||||
```
|
@@ -1,128 +0,0 @@
|
||||
# Client Cookies
|
||||
|
||||
`Zend\Http\Cookies` can be used with `Zend\Http\Client` to manage sending
|
||||
cookies in the request and setting cookies from the response; it is populated
|
||||
from the `Set-Cookie` headers obtained from a client response, and then used to
|
||||
populate the `Cookie` headers for a client request. This is highly useful in
|
||||
cases where you need to maintain a user session over consecutive HTTP requests,
|
||||
automatically sending the session ID cookies when required. Additionally, the
|
||||
`Zend\Http\Cookies` object can be serialized and stored in `$_SESSION` when
|
||||
needed.
|
||||
|
||||
`Zend\Http\Client` already provides methods for managing cookies for requests;
|
||||
`Zend\Http\Cookies` manages the parsing of `Set-Cookie` headers returned in the
|
||||
response, and allows persisting them. Additionally, `Cookies` can return a
|
||||
subset of cookies that match the current request, ensuring you are only sending
|
||||
relevant cookies.
|
||||
|
||||
## Usage
|
||||
|
||||
`Cookies` is an extension of `Zend\Http\Headers`, and inherits its methods. It
|
||||
can be instantiated without any arguments.
|
||||
|
||||
```php
|
||||
use Zend\Http\Cookies;
|
||||
|
||||
$cookies = new Cookies();
|
||||
```
|
||||
|
||||
On your first client request, you likely won't have any cookies, so the
|
||||
instance does nothing.
|
||||
|
||||
Once you've made your first request, you can start using it. Populate it from
|
||||
the response:
|
||||
|
||||
```php
|
||||
$response = $client->send();
|
||||
|
||||
$cookies->addCookiesFromResponse($response, $client->getUri());
|
||||
```
|
||||
|
||||
Alternately, you can create your initial `Cookies` instance using the static `fromResponse()` method:
|
||||
|
||||
```php
|
||||
$cookies = Cookies::fromResponse($response, $client->getUri());
|
||||
```
|
||||
|
||||
On subsequent requests, we'll notify the client of our cookies. To do this, we
|
||||
should use the same URI we'll use for the request.
|
||||
|
||||
```php
|
||||
$client->setUri($uri);
|
||||
$client->setCookies($cookies->getMatchingCookies($uri));
|
||||
```
|
||||
|
||||
After the request, don't forget to add any cookies returned!
|
||||
|
||||
Essentially, `Cookies` aggregates all cookies for our client interactions, and
|
||||
allows us to send only those relevant to a given request.
|
||||
|
||||
## Serializing and caching cookies
|
||||
|
||||
To cache cookies — e.g., to store in `$_SESSION`, or between job
|
||||
invocations — you will need to serialize them. `Zend\Http\Cookies`
|
||||
provides this functionality via the `getAllCookies()` method.
|
||||
|
||||
If your cache storage allows array structures, use the `COOKIE_STRING_ARRAY` constant:
|
||||
|
||||
```php
|
||||
$cookiesToCache = $cookies->getAllCookies($cookies::COOKIE_STRING_ARRAY);
|
||||
```
|
||||
|
||||
If your cache storage only allows string values, use `COOKIE_STRING_CONCAT`:
|
||||
|
||||
```php
|
||||
$cookiesToCache = $cookies->getAllCookies($cookies::COOKIE_STRING_CONCAT);
|
||||
```
|
||||
|
||||
When you retrieve the value later, you can test its type to determine how to
|
||||
deserialize the values:
|
||||
|
||||
```php
|
||||
use Zend\Http\Cookies;
|
||||
use Zend\Http\Headers;
|
||||
|
||||
$cookies = new Cookies();
|
||||
|
||||
if (is_array($cachedCookies)) {
|
||||
foreach ($cachedCookies as $cookie) {
|
||||
$cookies->addCookie($cookie);
|
||||
}
|
||||
} elseif (is_string($cachedCookies)) {
|
||||
foreach (Headers::fromString($cachedCookies) as $cookie) {
|
||||
$cookies->addCookie($cookie);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Public methods
|
||||
|
||||
Besides the methods demonstrated in the examples, `Zend\Http\Cookies` defines the following:
|
||||
|
||||
Method signature | Description
|
||||
------------------------------------------------------------------- | -----------
|
||||
`static fromResponse(Response $response, string $refUri) : Cookies` | Create a `Cookies` instance from a response and the request URI. Parses all `Set-Cookie` headers, maps them to the URI, and aggregates them.
|
||||
`addCookie(string|SetCookie $cookie, string $refUri = null) : void` | Add a cookie, mapping it to the given URI. If no URI is provided, it will be inferred from the cookie value's domain and path.
|
||||
`addCookiesFromResponse(Response $response, string $refUri) : void` | Add all `Set-Cookie` values from the provided response, mapping to the given URI.
|
||||
`getAllCookies(int $retAs = self::COOKIE_OBJECT) : array|string` | Retrieve all cookies. Returned array will have either `SetCookie` instances (the default), strings for each `Set-Cookie` declaration, or a single string containing all declarations, based on the `COOKIE_*` constant used.
|
||||
`getCookie(/* ... */) : string|SetCookie` | Retrieve a single cookie by name for the given URI. See below for argument details.
|
||||
`getMatchingCookies(/* ... */) : array` | See below for details.
|
||||
`isEmpty() : bool` | Whether or not the instance aggregates any cookies currently.
|
||||
`reset() : void` | Clear all aggregated cookies from the instance.
|
||||
|
||||
`getCookie()` accepts the following arguments, in the following order:
|
||||
|
||||
Argument | Description
|
||||
---------------------------------- | -----------
|
||||
`string $uri` | URI to match when retrieving the cookie. Will use its protocol, domain, and path.
|
||||
`string $cookieName` | The specific cookie name to retrieve.
|
||||
`int $retAs = self::COOKIE_OBJECT` | How to return matched cookies; defaults to `SetCookie` objects. Can be any of the `Cookies::COOKIE_*` constant values.
|
||||
|
||||
`getMatchingCookies()` accepts the following arguments, in the following order:
|
||||
|
||||
Argument | Description
|
||||
---------------------------------- | -----------
|
||||
`string $uri` | URI to match when retrieving cookies. Will use its protocol, domain, and path.
|
||||
`bool $matchSessionCookies = true` | Whether or not to also return related session cookies.
|
||||
`int $retAs = self::COOKIE_OBJECT` | How to return matched cookies; defaults to `SetCookie` objects. Can be any of the `Cookies::COOKIE_*` constant values.
|
||||
`int $now = null` | Timestamp against which to match; defaults to `time()`. Any expired cookies will be ignored.
|
@@ -1,258 +0,0 @@
|
||||
# HTTP Client
|
||||
|
||||
`Zend\Http\Client` provides an interface for performing Hyper-Text Transfer
|
||||
Protocol (HTTP) requests. `Zend\Http\Client` supports all basic features
|
||||
expected from an HTTP client, as well as some more complex features such as HTTP
|
||||
authentication and file uploads. Successful requests (and most unsuccessful ones
|
||||
too) return a `Zend\Http\Response` object, which provides access to the
|
||||
response's headers and body (see the chapter on [Responses](../response.md) for
|
||||
more details).
|
||||
|
||||
## Quick Start
|
||||
|
||||
The class constructor optionally accepts a URL as its first parameter (which can
|
||||
be either a string or a `Zend\Uri\Http` object), and an array or `Traversable`
|
||||
object containing configuration options. The `send()` method is used to submit
|
||||
the request to the remote server, and a `Zend\Http\Response` object is returned:
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
$client = new Client(
|
||||
'http://example.org',
|
||||
[
|
||||
'maxredirects' => 0,
|
||||
'timeout' => 30,
|
||||
]
|
||||
);
|
||||
$response = $client->send();
|
||||
```
|
||||
|
||||
Both constructor parameters can be left out, and set later using the `setUri()`
|
||||
and `setOptions()` methods:
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
$client = new Client();
|
||||
$client->setUri('http://example.org');
|
||||
$client->setOptions([
|
||||
'maxredirects' => 0,
|
||||
'timeout' => 30,
|
||||
]);
|
||||
$response = $client->send();
|
||||
```
|
||||
|
||||
`Zend\Http\Client` can also dispatch requests using a separately configured
|
||||
`request` object (see the [Request](../request.md) manual for full details of
|
||||
the methods available):
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
use Zend\Http\Request;
|
||||
|
||||
$request = new Request();
|
||||
$request->setUri('http://example.org');
|
||||
|
||||
$client = new Client();
|
||||
|
||||
$response = $client->send($request);
|
||||
```
|
||||
|
||||
> ### URL validation
|
||||
>
|
||||
> `Zend\Http\Client` uses `Zend\Uri\Http` to validate URLs. See the
|
||||
> [zend-uri](http://framework.zend.com/manual/current/en/index.html#zend-uri)
|
||||
> documentation for more information.
|
||||
|
||||
## Configuration
|
||||
|
||||
The constructor and `setOptions()` method accept an associative array or
|
||||
`Traversable` instance containing configuration parameters. Setting these
|
||||
parameters is optional, as they all have default values.
|
||||
|
||||
Parameter | Description | Expected Values | Default Value
|
||||
------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|--------------
|
||||
`maxredirects` | Maximum number of redirections to follow (0 = none) | integer | 5
|
||||
`strictredirects` | Whether to strictly follow the RFC when redirecting (see this section) | boolean | FALSE
|
||||
`useragent` | User agent identifier string (sent in request headers) | string | `Zend\Http\Client`
|
||||
`timeout` | Connection timeout (seconds) | integer | 10
|
||||
`httpversion` | HTTP protocol version (usually '1.1' or '1.0') | string | 1.1
|
||||
`adapter` | Connection adapter class to use (see this section) | mixed | `Zend\Http\Client\Adapter\Socket`
|
||||
`keepalive` | Whether to enable keep-alive connections with the server. Useful and might improve performance if several consecutive requests to the same server are performed. | boolean | FALSE
|
||||
`storeresponse` | Whether to store last response for later retrieval with getLastResponse(). If set to FALSE, getLastResponse() will return NULL. | boolean | TRUE
|
||||
`encodecookies` | Whether to pass the cookie value through urlencode/urldecode. Enabling this breaks support with some web servers. Disabling this limits the range of values the cookies can contain. | boolean | TRUE
|
||||
`outputstream` | Destination for streaming of received data (options: string (filename), true for temp file, false/null to disable streaming) | boolean | FALSE
|
||||
`rfc3986strict` | Whether to strictly adhere to RFC 3986 (in practice, this means replacing '+' with '%20') | boolean | FALSE
|
||||
|
||||
The options are also passed to the adapter class upon instantiation, so the same
|
||||
configuration can be used for adapter configuration. See the
|
||||
[adapters](adapters.md) section for more information on the adapter-specific
|
||||
options available.
|
||||
|
||||
## Examples
|
||||
|
||||
### Performing a GET request
|
||||
|
||||
GET is the default method used, and requires no special configuration.
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
$client = new Client('http://example.org');
|
||||
$response = $client->send();
|
||||
```
|
||||
|
||||
### Using request methods other than GET
|
||||
|
||||
The request method can be set using `setMethod()`. If no method is specified,
|
||||
the method set by the last `setMethod()` call is used. If `setMethod()` was
|
||||
never called, the default request method is `GET`.
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
$client = new Client('http://example.org');
|
||||
|
||||
// Performing a POST request
|
||||
$client->setMethod('POST');
|
||||
$response = $client->send();
|
||||
```
|
||||
|
||||
For convenience, `Zend\Http\Request` defines all request methods as class
|
||||
constants: `Zend\Http\Request::METHOD_GET`, `Zend\Http\Request::METHOD_POST` and
|
||||
so on.
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
use Zend\Http\Request;
|
||||
|
||||
$client = new Client('http://example.org');
|
||||
|
||||
// Performing a POST request
|
||||
$client->setMethod(Request::METHOD_POST);
|
||||
$response = $client->send();
|
||||
```
|
||||
|
||||
### Setting query parameters
|
||||
|
||||
Adding query parameters to an HTTP request can be done either by specifying them
|
||||
as part of the URL, or by using the `setParameterGet()` method. This method
|
||||
takes the query parameters as an associative array of name/value pairs.
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
$client = new Client();
|
||||
|
||||
// This is equivalent to setting a URL in the Client's constructor:
|
||||
$client->setUri('http://example.com/index.php?knight=lancelot');
|
||||
|
||||
// Adding several parameters with one call
|
||||
$client->setParameterGet([
|
||||
'first_name' => 'Bender',
|
||||
'middle_name' => 'Bending',
|
||||
'last_name' => 'Rodríguez',
|
||||
'made_in' => 'Mexico',
|
||||
]);
|
||||
```
|
||||
|
||||
### Setting form-encoded body parameters
|
||||
|
||||
While query parameters can be sent with every request method, other methods can
|
||||
accept parameters via the request body. In many cases, these are
|
||||
`application/x-www-form-urlencoded` parameters; zend-http allows you to specify
|
||||
such parameters usingthe `setParameterPost()` method, which is identical to the
|
||||
`setParameterGet()` method in structure.
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
$client = new Client();
|
||||
|
||||
// Setting several POST parameters, one of them with several values
|
||||
$client->setParameterPost([
|
||||
'language' => 'es',
|
||||
'country' => 'ar',
|
||||
'selection' => [45, 32, 80],
|
||||
]);
|
||||
```
|
||||
|
||||
Note that when sending `POST` requests (or an request allowing a request body),
|
||||
you can set both query and `POST` parameters. On the other hand, setting POST
|
||||
parameters on a `GET` request will not trigger an error, rendering it useless.
|
||||
|
||||
### Connecting to SSL URLs
|
||||
|
||||
If you are trying to connect to an SSL or TLS (https) URL and are using the
|
||||
default (`Zend\Http\Client\Adapter\Socket`) adapter, you may need to set the
|
||||
`sslcapath` configuration option in order to allow PHP to validate the SSL
|
||||
certificate:
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
$client = new Client(
|
||||
'https://example.org',
|
||||
[
|
||||
'sslcapath' => '/etc/ssl/certs',
|
||||
]
|
||||
);
|
||||
$response = $client->send();
|
||||
```
|
||||
|
||||
The exact path to use will vary depending on your operating system. Without this
|
||||
you'll get the exception "Unable to enable crypto on TCP connection" when trying
|
||||
to connect.
|
||||
|
||||
Alternatively, you could switch to the curl adapter, which negotiates SSL
|
||||
connections more transparently:
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
$client = new Client(
|
||||
'https://example.org',
|
||||
[
|
||||
'adapter' => 'Zend\Http\Client\Adapter\Curl',
|
||||
]
|
||||
);
|
||||
$response = $client->send();
|
||||
```
|
||||
|
||||
## Complete Example
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
|
||||
$client = new Client();
|
||||
$client->setUri('http://www.example.com');
|
||||
$client->setMethod('POST');
|
||||
$client->setParameterPost([
|
||||
'foo' => 'bar',
|
||||
]);
|
||||
|
||||
$response = $client->send();
|
||||
|
||||
if ($response->isSuccess()) {
|
||||
// the POST was successful
|
||||
}
|
||||
```
|
||||
|
||||
or the same thing, using a request object:
|
||||
|
||||
```php
|
||||
use Zend\Http\Client;
|
||||
use Zend\Http\Request;
|
||||
|
||||
$request = new Request();
|
||||
$request->setUri('http://www.example.com');
|
||||
$request->setMethod('POST');
|
||||
$request->getPost()->set('foo', 'bar');
|
||||
|
||||
$client = new Client();
|
||||
$response = $client->send($request);
|
||||
|
||||
if ($response->isSuccess()) {
|
||||
// the POST was successful
|
||||
}
|
||||
```
|
@@ -1,66 +0,0 @@
|
||||
# HTTP Client - Static Usage
|
||||
|
||||
zend-http provides another client implementation, `Zend\Http\ClientStatic`, a
|
||||
static HTTP client which exposes a simplified API for quickly performing one-off `GET`
|
||||
and `POST` operations.
|
||||
|
||||
## Quick Start
|
||||
|
||||
```php
|
||||
use Zend\Http\ClientStatic;
|
||||
|
||||
// Simple GET request
|
||||
$response = ClientStatic::get('http://example.org');
|
||||
|
||||
// More complex GET request, specifying query string 'foo=bar' and adding a
|
||||
// custom header to request JSON data be returned (Accept: application/json):
|
||||
$response = ClientStatic::get(
|
||||
'http://example.org',
|
||||
['foo' => 'bar'],
|
||||
['Accept' => 'application/json']
|
||||
);
|
||||
|
||||
// We can also do a POST request using the same format. Here we POST
|
||||
// login credentials (username/password) to a login page:
|
||||
$response = ClientStatic::post(
|
||||
'https://example.org/login.php',
|
||||
[
|
||||
'username' => 'foo',
|
||||
'password' => 'bar',
|
||||
]
|
||||
);
|
||||
```
|
||||
|
||||
## Available Methods
|
||||
|
||||
### get()
|
||||
|
||||
```php
|
||||
get(
|
||||
string $url,
|
||||
array $query = [],
|
||||
array $headers = [],
|
||||
mixed $body = null,
|
||||
$clientOptions = null
|
||||
) : Response
|
||||
```
|
||||
|
||||
Perform an HTTP `GET` request using the provided URL, query string variables,
|
||||
headers, and request body. The fifth parameter can be used to pass configuration
|
||||
options to the HTTP client instance.
|
||||
|
||||
### post()
|
||||
|
||||
```php
|
||||
post(
|
||||
string $url,
|
||||
array $params,
|
||||
array $headers = [],
|
||||
mixed $body = null,
|
||||
$clientOptions = null
|
||||
) : Response
|
||||
```
|
||||
|
||||
Perform an HTTP `POST` request using the provided URL, parameters, headers, and
|
||||
request body. The fifth parameter can be used to pass configuration options to
|
||||
the HTTP client instance.
|
594
vendor/zendframework/zend-http/doc/book/headers.md
vendored
594
vendor/zendframework/zend-http/doc/book/headers.md
vendored
@@ -1,594 +0,0 @@
|
||||
# Headers
|
||||
|
||||
`Zend\Http\Headers` is a container for HTTP headers. It is typically accessed as
|
||||
part of a `Zend\Http\Request` or `Zend\Http\Response` instance, via a
|
||||
`getHeaders()` call. The `Headers` container will lazily load actual
|
||||
`Zend\Http\Header\HeaderInterface` instances as to reduce the overhead of header
|
||||
specific parsing.
|
||||
|
||||
The class under the `Zend\Http\Header` namespace are the domain specific
|
||||
implementations for the various types of headers that one might encounter during
|
||||
the typical HTTP request. If a header of unknown type is encountered, it will be
|
||||
implemented as a `Zend\Http\Header\GenericHeader` instance. See the below table
|
||||
for a list of the various HTTP headers and the API that is specific to each
|
||||
header type.
|
||||
|
||||
## Quick Start
|
||||
|
||||
The quickest way to get started interacting with header objects is by retrieving
|
||||
an already populated `Headers` container from a request or response instance.
|
||||
|
||||
```php
|
||||
// $client is an instance of Zend\Http\Client
|
||||
|
||||
// You can retrieve the request headers by first retrieving
|
||||
// the Request object and then calling getHeaders on it
|
||||
$requestHeaders = $client->getRequest()->getHeaders();
|
||||
|
||||
// The same method also works for retrieving Response headers
|
||||
$responseHeaders = $client->getResponse()->getHeaders();
|
||||
```
|
||||
|
||||
`Zend\Http\Headers` can also extract headers from a string:
|
||||
|
||||
```php
|
||||
use Zend\Http\Headers;
|
||||
|
||||
$headerString = <<<EOB
|
||||
Host: www.example.com
|
||||
Content-Type: text/html
|
||||
Content-Length: 1337
|
||||
EOB;
|
||||
|
||||
$headers = Headers::fromString($headerString);
|
||||
// $headers is now populated with three objects
|
||||
// (1) Zend\Http\Header\Host
|
||||
// (2) Zend\Http\Header\ContentType
|
||||
// (3) Zend\Http\Header\ContentLength
|
||||
```
|
||||
|
||||
Now that you have an instance of `Zend\Http\Headers`, you can manipulate the
|
||||
individual headers it contains using the provided public API methods outlined in
|
||||
the [Available Methods](#available-methods) section.
|
||||
|
||||
## Configuration Options
|
||||
|
||||
No configuration options are available.
|
||||
|
||||
## Available Methods
|
||||
|
||||
The following is a list of methods available to `Zend\Http\Headers`. For
|
||||
brevity, we map the following references to the following classes or namespaces:
|
||||
|
||||
- `HeaderInterface`: `Zend\Http\Header\HeaderInterface`
|
||||
- `Headers`: `Zend\Http\Headers`
|
||||
- `PluginClassLocator`: `Zend\Loader\PluginClassLocator`
|
||||
|
||||
Method signature | Description
|
||||
------------------------------------------------------------------------- | -----------
|
||||
`static fromString(string $string) : Headers` | Parses a string for headers, and aggregates them, in order, a new `Headers` instance, primarily as strings until they are needed (they will be lazy loaded).
|
||||
`setPluginClassLoader(PluginClassLocator $pluginClassLoader) : self` | Set an alternate implementation for the plugin class loader.
|
||||
`getPluginClassLoader() : PluginClassLocator` | Return an instance of a `PluginClassLocator`; lazy-load and inject map if necessary.
|
||||
`addHeaders(array|Traversable $headers) : self` | Add many headers at once; expects an array (or `Traversable` object) of type/value pairs.
|
||||
`addHeaderLine(string $headerFieldNameOrLine, string $fieldValue) : self` | Add a raw header line, either as separate name and value arguments, or as a single string in the form `name: value` This method allows for lazy-loading in that the parsing and instantiation of a `HeaderInterface` implementation will be delayed until they are retrieved by either `get()` or `current()`.
|
||||
`addHeader(HeaderInterface $header) : self` | Add a header instance to the container; for raw values see `addHeaderLine()` and `addHeaders()`.
|
||||
`removeHeader(HeaderInterface $header) : bool` | Remove a Header from the container.
|
||||
`clearHeaders() : self` | Removes all headers from the container.
|
||||
`get(string $name) : false|HeaderInterface|ArrayIterator` | Get all values for a given header. If none are found, `false` is returned. If the header is a single-value header, a `HeaderInterface` is returned. If the header is a multi-value header, an `ArrayIterator` containing all values is returned.
|
||||
`has(string $name) : bool` | Test for existence of a header.
|
||||
`next() : void` | Advance the pointer for this object as an iterator.
|
||||
`key() : mixed` | Return the current key for this object as an iterator.
|
||||
`valid() : bool` | Is this iterator still valid?
|
||||
`rewind() : void` | Reset the internal pointer for this object as an iterator.
|
||||
`current() : HeaderInterface` | Return the current value for this iterator, lazy loading it if need be.
|
||||
`count() : int` | Return the number of headers in this container. If all headers have not been parsed, the actual count could decrease if `MultipleHeader` instances exist. If you need an exact count, iterate.
|
||||
`toString() : string` | Render all headers at once. This method handles the normal iteration of headers; it is up to the concrete classes to prepend with the appropriate status/request line.
|
||||
`toArray() : array` | Return all headers as an associative array.
|
||||
`forceLoading() : bool` | By calling this, it will force parsing and loading of all headers, ensuring `count()` is accurate.
|
||||
|
||||
## HeaderInterface Methods
|
||||
|
||||
The following are methods available to all `HeaderInterface` implementations.
|
||||
|
||||
Method signature | Description
|
||||
--------------------------------------------------------- | -----------
|
||||
`static fromString(string $headerLine) : HeaderInterface` | Factory to generate a header object from a string.
|
||||
`getFieldName() : string` | Retrieve header field name.
|
||||
`getFieldValue() : string` | Retrieve header field value.
|
||||
`toString() : string` | Cast the header to a well-formed HTTP header line (`Name: Value`).
|
||||
|
||||
## AbstractAccept Methods
|
||||
|
||||
`Zend\Http\Header\AbstractAccept` defines the following methods in addition to
|
||||
those it inherits from the [HeaderInterface](#headerinterface-methods). The
|
||||
`Accept`, `AcceptCharset`, `AcceptEncoding`, and `AcceptLanguage` header types
|
||||
inherit from it.
|
||||
|
||||
For brevity, we map the following references to the following classes or
|
||||
namespaces:
|
||||
|
||||
- `AcceptFieldValuePart`: `Zend\Http\Header\Accept\FieldValuePart\AcceptFieldValuePart`
|
||||
- `InvalidArgumentException`: `Zend\Http\Header\Exception\InvalidArgumentException`
|
||||
|
||||
Method signature | Description
|
||||
--------------------------------------------------------------- | -----------
|
||||
`parseHeaderLine(string $headerLine) : void` | Parse the given header line and add the values discovered to the instance.
|
||||
`getFieldValuePartsFromHeaderLine(string $headerLine) : array` | Parse the field value parts represented by an Accept* header line. Throws `InvalidArgumentException` if the header is invalid.
|
||||
`getFieldValue(array|null $values = null) : string` | Get field value.
|
||||
`match(array|string $matchAgainst) : bool|AcceptFieldValuePart` | Match a media string against this header. Returns the matched value or false.
|
||||
`getPrioritized() : array` | Returns all the keys, values and parameters this header represents.
|
||||
|
||||
## AbstractDate Methods
|
||||
|
||||
`Zend\Http\Header\AbstractDate` defines the following methods in addition to
|
||||
those it inherits from the [HeaderInterface](#headerinterface-methods). The
|
||||
`Date`, `Expires`, `IfModifiedSince`, `IfUnmodifiedSince`, `LastModified`, and
|
||||
`RetryAfter` header types inherit from it.
|
||||
|
||||
For brevity, we map the following references to the following classes or
|
||||
namespaces:
|
||||
|
||||
- `InvalidArgumentException`: `Zend\Http\Header\Exception\InvalidArgumentException`
|
||||
|
||||
Method signature | Description
|
||||
---------------------------------------------------- | -----------
|
||||
`static fromTimestamp(int $time) : AbstractDate` | Create date-based header from Unix timestamp.
|
||||
`static fromTimeString(string $time) : AbstractDate` | Create date-based header from `strtotime()`-compatible string.
|
||||
`static setDateFormat(int $format) : void` | Set date output format; should be an index from the implementation's `$dateFormat` static property.
|
||||
`static getDateFormat() : string` | Return current date output format.
|
||||
`setDate(string|DateTime $date) : self` | Set the date for this header; this can be a string or an instance of `DateTime`. Throws `InvalidArgumentException` if the date is neither a valid string nor an instance of `DateTime`.
|
||||
`getDate() : string` | Return string representation of the date for this header.
|
||||
`compareTo(string|DateTime $date) : int` | Compare provided date to date for this header. Returns `< 0` if date in header is less than `$date`; `> 0` if it's greater, and `= 0` if they are equal. See [strcmp](http://www.php.net/manual/en/function.strcmp.php).
|
||||
`date() | DateTime` | Return date for this header as an instance of `DateTime`.
|
||||
|
||||
## AbstractLocation Methods
|
||||
|
||||
`Zend\Http\Header\AbstractLocation` defines the following methods in addition to
|
||||
those it inherits from the [HeaderInterface](#headerinterface-methods). The
|
||||
`ContentLocation`, `Location`, and `Referer` header types inherit from it.
|
||||
|
||||
For brevity, we map the following references to the following classes or
|
||||
namespaces:
|
||||
|
||||
- `Uri`: `Zend\Uri\UriInterface`
|
||||
- `InvalidArgumentException`: `Zend\Http\Header\Exception\InvalidArgumentException`
|
||||
|
||||
Method signature | Description
|
||||
-------------------------------- | -----------
|
||||
`setUri(string|Uri $uri) : self` | Set the URI for this header; throws `InvalidArgumentException` for invalid `$uri` arguments.
|
||||
`getUri() : string` | Return the URI for this header.
|
||||
`uri() : Uri` | Return the `Uri` instance for this header.
|
||||
|
||||
## List of HTTP Header Types
|
||||
|
||||
Some header classes expose methods for manipulating their value. The following
|
||||
list contains all of the classes available in the `Zend\Http\Header\*`
|
||||
namespace, as well as any specific methods they contain. Each class implements
|
||||
`Zend\Http\Header\HeaderInterface`.
|
||||
|
||||
### Accept
|
||||
|
||||
Extends [AbstractAccept](#abstractaccept-methods).
|
||||
|
||||
Method signature | Description
|
||||
------------------------------------------------------------ | -----------
|
||||
`addMediaType(string $type, int|float $priority = 1) : self` | Add a media type, with the given priority.
|
||||
`hasMediaType(string $type): bool` | Does the header have the requested media type?
|
||||
|
||||
### AcceptCharset
|
||||
|
||||
Extends [AbstractAccept](#abstractaccept-methods).
|
||||
|
||||
Method signature | Description
|
||||
---------------------------------------------------------- | -----------
|
||||
`addCharset(string $type, int|float $priority = 1) : self` | Add a charset, with the given priority.
|
||||
`hasCharset(string $type) : bool` | Does the header have the requested charset?
|
||||
|
||||
### AcceptEncoding
|
||||
|
||||
Extends [AbstractAccept](#abstractaccept-methods).
|
||||
|
||||
Method signature | Description
|
||||
----------------------------------------------------------- | -----------
|
||||
`addEncoding(string $type, int|float $priority = 1) : self` | Add an encoding, with the given priority.
|
||||
`hasEncoding(string $type) : bool` | Does the header have the requested encoding?
|
||||
|
||||
### AcceptLanguage
|
||||
|
||||
Extends [AbstractAccept](#abstractaccept-methods).
|
||||
|
||||
Method signature | Description
|
||||
---------------------------------------------------------- | -----------
|
||||
`addLanguage(string $type, int|float $priority = 1): self` | Add a language, with the given priority.
|
||||
`hasLanguage(string $type) : bool` | Does the header have the requested language?
|
||||
|
||||
### AcceptRanges
|
||||
|
||||
Method signature | Description
|
||||
--------------------------------------- | -----------
|
||||
`getRangeUnit() : mixed` | (unknown)
|
||||
`setRangeUnit(mixed $rangeUnit) : self` | (unkown)
|
||||
|
||||
### Age
|
||||
|
||||
Method signature | Description
|
||||
-------------------------------------- | -----------
|
||||
`getDeltaSeconds() : int` | Get number of seconds.
|
||||
`setDeltaSeconds(int $seconds) : self` | Set number of seconds
|
||||
|
||||
### Allow
|
||||
|
||||
Method signature | Description
|
||||
---------------------------------------------------- | -----------
|
||||
`getAllMethods() : string[]` | Get list of all defined methods.
|
||||
`getAllowedMethods() : string[]` | Get list of allowed methods.
|
||||
`allowMethods(array|string $allowedMethods) : self` | Allow methods or list of methods.
|
||||
`disallowMethods(array|string $allowedMethods) self` | Disallow methods or list of methods.
|
||||
`denyMethods(array|string $allowedMethods) : self` | Convenience alias for `disallowMethods()`.
|
||||
`isAllowedMethod(string $method) : bool` | Check whether method is allowed.
|
||||
|
||||
### AuthenticationInfo
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Authorization
|
||||
|
||||
No additional methods.
|
||||
|
||||
### CacheControl
|
||||
|
||||
Method signature | Description
|
||||
------------------------------------------------------------- | -----------
|
||||
`isEmpty(): bool` | Checks if the internal directives array is empty.
|
||||
`addDirective(string $key, string|bool $value = true) : self` | Add a directive. For directives like `max-age=60`, call as `addDirective('max-age', 60)`. For directives like `private`, use the default `$value` (`true`).
|
||||
`hasDirective(string $key) : bool` | Check the internal directives array for a directive.
|
||||
`getDirective(string $key) : null|string` | Fetch the value of a directive from the internal directive array.
|
||||
`removeDirective(string $key) : self` | Remove a directive.
|
||||
|
||||
### Connection
|
||||
|
||||
Method signature | Description
|
||||
---------------------------------- | -----------
|
||||
`setValue($value) : self` | Set arbitrary header value. RFC allows any token as value; 'close' and 'keep-alive' are commonly used.
|
||||
`isPersistent() : bool` | Whether or not the connection is persistent.
|
||||
`setPersistent(bool $flag) : self` | Set Connection header to define persistent connection.
|
||||
|
||||
### ContentDisposition
|
||||
|
||||
No additional methods.
|
||||
|
||||
### ContentEncoding
|
||||
|
||||
No additional methods.
|
||||
|
||||
### ContentLanguage
|
||||
|
||||
No additional methods.
|
||||
|
||||
### ContentLength
|
||||
|
||||
No additional methods.
|
||||
|
||||
### ContentLocation
|
||||
|
||||
See [AbstractLocation](#abstractlocation-methods).
|
||||
|
||||
### ContentMD5
|
||||
|
||||
No additional methods.
|
||||
|
||||
### ContentRange
|
||||
|
||||
No additional methods.
|
||||
|
||||
### ContentSecurityPolicy
|
||||
|
||||
Method signature | Description
|
||||
--------------------------------------------------- | -----------
|
||||
`getDirectives(): array` | Retrieve the defined directives for the policy.
|
||||
`setDirective(string $name, array $sources) : self` | Set the directive with the given name to include the sources. See below for an example.
|
||||
|
||||
As an example: an auction site wishes to load images from any URI, plugin
|
||||
content from a list of trusted media providers (including a content distribution
|
||||
network), and scripts only from a server under its control hosting sanitized
|
||||
Javacript:
|
||||
|
||||
```php
|
||||
// http://www.w3.org/TR/2012/CR-CSP-20121115/#sample-policy-definitions
|
||||
$csp = new ContentSecurityPolicy();
|
||||
$csp->setDirective('default-src', []); // No sources
|
||||
$csp->setDirective('img-src', ['*']);
|
||||
$csp->setDirective('object-src', ['media1.example.com', 'media2.example.com', '*.cdn.example.com']);
|
||||
$csp->setDirective('script-src', ['trustedscripts.example.com']);
|
||||
```
|
||||
|
||||
### ContentTransferEncoding
|
||||
|
||||
No additional methods.
|
||||
|
||||
### ContentType
|
||||
|
||||
Method signature | Description
|
||||
------------------------------------------------- | -----------
|
||||
`match(array|string $matchAgainst) : bool|string` | Determine if the mediatype value in this header matches the provided criteria.
|
||||
`getMediaType() : string` | Get the media type.
|
||||
`setMediaType(string $mediaType) : self` | Set the media type.
|
||||
`getParameters() : array` | Get any additional content-type parameters currently set.
|
||||
`setParameters(array $parameters) : self` | Set additional content-type parameters.
|
||||
`getCharset() : null|string` | Get the content-type character set encoding, if any.
|
||||
`setCharset(string $charset) : self` | Set the content-type character set encoding.
|
||||
|
||||
### Cookie
|
||||
|
||||
Extends `ArrayObject`.
|
||||
|
||||
Method signature | Description
|
||||
------------------------------------------------------- | -----------
|
||||
`static fromSetCookieArray(array $setCookies) : Cookie` | Create an instance from the `$_COOKIE` array, or one structured like it.
|
||||
`setEncodeValue(bool $encode) : self` | Set flag indicating whether or not to `urlencode()` the cookie values.
|
||||
`getEncodeValue() : bool` | Get flag indicating whether or not to `urlencode()` the cookie values.
|
||||
|
||||
### Date
|
||||
|
||||
See [AbstractDate](#abstractdate-methods).
|
||||
|
||||
### Etag
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Expect
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Expires
|
||||
|
||||
See [AbstractDate](#abstractdate-methods).
|
||||
|
||||
### From
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Host
|
||||
|
||||
No additional methods.
|
||||
|
||||
### IfMatch
|
||||
|
||||
No additional methods.
|
||||
|
||||
### IfModifiedSince
|
||||
|
||||
See [AbstractDate](#abstractdate-methods).
|
||||
|
||||
### IfNoneMatch
|
||||
|
||||
No additional methods.
|
||||
|
||||
### IfRange
|
||||
|
||||
No additional methods.
|
||||
|
||||
### IfUnmodifiedSince
|
||||
|
||||
See [AbstractDate](#abstractdate-methods).
|
||||
|
||||
### KeepAlive
|
||||
|
||||
No additional methods.
|
||||
|
||||
### LastModified
|
||||
|
||||
See [AbstractDate](#abstractdate-methods).
|
||||
|
||||
### Location
|
||||
|
||||
See [AbstractLocation](#abstractlocation-methods).
|
||||
|
||||
### MaxForwards
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Origin
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Pragma
|
||||
|
||||
No additional methods.
|
||||
|
||||
### ProxyAuthenticate
|
||||
|
||||
Method signature | Description
|
||||
-------------------------------------------------- | -----------
|
||||
`toStringMultipleHeaders(array $headers) : string` | Creates a string representation when multiple values are present.
|
||||
|
||||
### ProxyAuthorization
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Range
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Referer
|
||||
|
||||
See [AbstractLocation](#abstractlocation-methods).
|
||||
|
||||
### Refresh
|
||||
|
||||
No additional methods.
|
||||
|
||||
### RetryAfter
|
||||
|
||||
See [AbstractDate](#abstractdate-methods).
|
||||
|
||||
Method signature | Description
|
||||
------------------------------------ | -----------
|
||||
`setDeltaSeconds(int $delta) : self` | Set number of seconds.
|
||||
`getDeltaSeconds() : int` | Get number of seconds.
|
||||
|
||||
### Server
|
||||
|
||||
No additional methods.
|
||||
|
||||
### SetCookie
|
||||
|
||||
Method signature | Description
|
||||
--------------------------------------------------------------------- | -----------
|
||||
`static matchCookieDomain(string $cookieDomain, string $host) : bool` | Check if a cookie's domain matches a host name.
|
||||
`static matchCookiePath(string $cookiePath, string $path) : bool` | Check if a cookie's path matches a URL path.
|
||||
`getName() : string` | Retrieve the cookie name.
|
||||
`setName(string $name) : self` | Set the cookie name.
|
||||
`getValue() : string` | Retrieve the cookie value.
|
||||
`setValue(string $value) : self` | Set the cookie value.
|
||||
`getExpires() : int` | Retrieve the expiration date for the cookie.
|
||||
`setExpires(int|string $expires) : self` | Set the cookie expiration timestamp; null indicates a session cookie.
|
||||
`getPath() : string` | Retrieve the URI path the cookie is bound to.
|
||||
`setPath(string $path) : self` | Set the URI path the cookie is bound to.
|
||||
`getDomain() : string` | Retrieve the domain the cookie is bound to.
|
||||
`setDomain(string $domain) : self` | Set the domain the cookie is bound to.
|
||||
`getMaxAge() : int` | Retrieve the maximum age for the cookie.
|
||||
`setMaxAge(int|string $maxAge) : self` | Set the maximum age for the cookie.
|
||||
`getVersion() : int` | Retrieve the cookie version.
|
||||
`setVersion(int|string $version) : self` | Set the cookie version.
|
||||
`isSecure(): bool` | Whether the cookies contains the Secure flag.
|
||||
`setSecure(bool $secure) : self` | Set whether the cookies contain the Secure flag.
|
||||
`isHttponly() : bool` | Whether the cookies can be accessed via the HTTP protocol only.
|
||||
`setHttponly(bool $httponly) : self` | Set whether the cookies can be accessed only via HTTP protocol.
|
||||
`isExpired() : bool` | Whether the cookie is expired.
|
||||
`isSessionCookie() : bool` | Whether the cookie is a session cookie.
|
||||
`setQuoteFieldValue(bool $quotedValue) : self` | Set whether the value for this cookie should be quoted.
|
||||
`hasQuoteFieldValue() : bool` | Check whether the value for this cookie should be quoted.
|
||||
`isValidForRequest() : bool` | Whether the cookie is valid for a given request domain, path and isSecure.
|
||||
`match(string $uri, bool $matchSessionCookies, int $now) : bool` | Checks whether the cookie should be sent or not in a specific scenario.
|
||||
`toStringMultipleHeaders(array $headers) : string` | Returns string representation when multiple values are present.
|
||||
|
||||
### TE
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Trailer
|
||||
|
||||
No additional methods.
|
||||
|
||||
### TransferEncoding
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Upgrade
|
||||
|
||||
No additional methods.
|
||||
|
||||
### UserAgent
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Vary
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Via
|
||||
|
||||
No additional methods.
|
||||
|
||||
### Warning
|
||||
|
||||
No additional methods.
|
||||
|
||||
### WWWAuthenticate
|
||||
|
||||
Defines a `toStringMultipleHeaders(array $headers)` method for serializing to
|
||||
string when multiple values are present.
|
||||
|
||||
## Examples
|
||||
|
||||
### Retrieving headers from a Headers object
|
||||
|
||||
```php
|
||||
// $client is an instance of Zend\Http\Client
|
||||
$response = $client->send();
|
||||
$headers = $response->getHeaders();
|
||||
|
||||
// We can check if the Request contains a specific header by
|
||||
// using the ``has`` method. Returns boolean ``TRUE`` if at least
|
||||
// one matching header found, and ``FALSE`` otherwise
|
||||
$headers->has('Content-Type');
|
||||
|
||||
// We can retrieve all instances of a specific header by using
|
||||
// the ``get`` method:
|
||||
$contentTypeHeaders = $headers->get('Content-Type');
|
||||
```
|
||||
|
||||
There are three possibilities for the return value of the above call to the `get` method:
|
||||
|
||||
- If no `Content-Type` header was set in the `Request`, `get` will return `false`.
|
||||
- If only one `Content-Type` header was set in the `Request`, `get` will return
|
||||
an instance of `Zend\Http\Header\ContentType`.
|
||||
- If more than one `Content-Type` header was set in the `Request`, `get` will
|
||||
return an `ArrayIterator` containing one `Zend\Http\Header\ContentType`
|
||||
instance per header.
|
||||
|
||||
### Adding headers to a Headers object
|
||||
|
||||
```php
|
||||
use Zend\Http\Header;
|
||||
use Zend\Http\Headers;
|
||||
|
||||
$headers = new Headers();
|
||||
|
||||
// We can directly add any object that implements Zend\Http\Header\HeaderInterface
|
||||
$typeHeader = Header\ContentType::fromString('Content-Type: text/html');
|
||||
$headers->addHeader($typeHeader);
|
||||
|
||||
// We can add headers using the raw string representation, either
|
||||
// passing the header name and value as separate arguments...
|
||||
$headers->addHeaderLine('Content-Type', 'text/html');
|
||||
|
||||
// .. or we can pass the entire header as the only argument
|
||||
$headers->addHeaderLine('Content-Type: text/html');
|
||||
|
||||
// We can also add headers in bulk using addHeaders, which accepts
|
||||
// an array of individual header definitions that can be in any of
|
||||
// the accepted formats outlined below:
|
||||
$headers->addHeaders([
|
||||
// An object implementing Header\HeaderInterface
|
||||
Header\ContentType::fromString('Content-Type: text/html'),
|
||||
|
||||
// A raw header string
|
||||
'Content-Type: text/html',
|
||||
|
||||
// We can also pass the header name as the array key and the
|
||||
// header content as that array key's value
|
||||
'Content-Type' => 'text/html',
|
||||
]);
|
||||
```
|
||||
|
||||
### Removing headers from a Headers object
|
||||
|
||||
We can remove all headers of a specific type using the `removeHeader` method,
|
||||
which accepts a single object implementing `Zend\Http\Header\HeaderInterface`
|
||||
|
||||
```php
|
||||
use ArrayIterator;
|
||||
use Zend\Http\Header\HeaderInterface;
|
||||
|
||||
// $headers is a pre-configured instance of Zend\Http\Headers
|
||||
|
||||
// We can also delete individual headers or groups of headers
|
||||
$matches = $headers->get('Content-Type');
|
||||
|
||||
if ($matches instanceof ArrayIterator) {
|
||||
// If more than one header was found, iterate over the collection
|
||||
// and remove each one individually
|
||||
foreach ($headers as $header) {
|
||||
$headers->removeHeader($header);
|
||||
}
|
||||
} elseif ($matches instanceof HeaderInterface) {
|
||||
// If only a single header was found, remove it directly
|
||||
$headers->removeHeader($header);
|
||||
}
|
||||
|
||||
// In addition to this, we can clear all the headers currently stored in
|
||||
// the container by calling the clearHeaders() method
|
||||
$matches->clearHeaders();
|
||||
```
|
@@ -1,10 +0,0 @@
|
||||
<div class="container">
|
||||
<div class="jumbotron">
|
||||
<h1>zend-http</h1>
|
||||
|
||||
<p>HTTP message and header abstractions, and HTTP client implementation. (Not a PSR-7 implementation; see <a href="//zendframework.github.io/zend-diactoros">Diactoros</a> for PSR-7 support.</p>
|
||||
|
||||
<pre><code class="language-bash">$ composer require zendframework/zend-http</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -1 +0,0 @@
|
||||
../../README.md
|
35
vendor/zendframework/zend-http/doc/book/intro.md
vendored
35
vendor/zendframework/zend-http/doc/book/intro.md
vendored
@@ -1,35 +0,0 @@
|
||||
# Introduction
|
||||
|
||||
zend-http provides the HTTP message abstraction used by
|
||||
[zend-mvc](https://zendframework.github.io/zend-mvc/), and also provides an
|
||||
extensible, adapter-driven HTTP client library. It provides the following
|
||||
abstractions:
|
||||
|
||||
- Context-less `Request` and `Response` classes that expose a fluent API for
|
||||
introspecting several aspects of HTTP messages:
|
||||
- Request line information and response status information
|
||||
- Parameters, such as those found in POST and GET
|
||||
- Message Body
|
||||
- Headers
|
||||
- A client implementation with various adapters that allow for sending requests
|
||||
and introspecting responses.
|
||||
|
||||
> ### Not PSR-7!
|
||||
>
|
||||
> This library **does not** support [PSR-7](http://www.php-fig.org/psr/psr-7), as
|
||||
> it predates that specification. For PSR-7 support, please see our
|
||||
> [Diactoros component](https://zendframework.github.io/zend-diactoros/).
|
||||
|
||||
## Zend\Http Request, Response and Headers
|
||||
|
||||
The request, response and headers implementations of the zend-http component
|
||||
provides a fluent, object-oriented interface for introspecting information from
|
||||
all the various parts of an HTTP request or HTTP response. The primary classes
|
||||
are `Zend\Http\Request` and `Zend\Http\Response`. Both are “context-less”,
|
||||
meaning that they model a request or response in the same way whether it is
|
||||
presented by a client (to **send** a request and **receive** a response) or by a
|
||||
server (to **receive** a request and **send** a response). In other words,
|
||||
regardless of the context, the API remains the same for introspecting their
|
||||
various respective parts. Each attempts to fully model a request or response so
|
||||
that a developer can create these objects from a factory, or create and populate
|
||||
them manually.
|
177
vendor/zendframework/zend-http/doc/book/request.md
vendored
177
vendor/zendframework/zend-http/doc/book/request.md
vendored
@@ -1,177 +0,0 @@
|
||||
# The Request Class
|
||||
|
||||
`Zend\Http\Request` is responsible for providing a fluent API that allows a
|
||||
developer to interact with all the various parts of an HTTP request.
|
||||
|
||||
A typical HTTP request looks like this:
|
||||
|
||||
```text
|
||||
| METHOD | URI | VERSION |
|
||||
| HEADERS |
|
||||
| BODY |
|
||||
```
|
||||
|
||||
In simplified terms, the request consists of a method, URI, and HTTP version
|
||||
number; together, they make up the "Request Line." This line is followed by zero
|
||||
or more HTTP headers, which is followed by an empty line and then the request
|
||||
body; the body is typically used when a client wishes to send data — which
|
||||
could be urlencoded parameters, a JSON document, an XML document, or even one or
|
||||
more files — to the server. More information on the structure and
|
||||
specification of a HTTP request can be found in
|
||||
[RFC-2616 on the W3.org site](http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html).
|
||||
|
||||
## Quick Start
|
||||
|
||||
Request objects can either be created from the provided `fromString()` factory,
|
||||
or, if you wish to have a completely empty object to start with, by
|
||||
manually instantiating the `Zend\Http\Request` class with no parameters.
|
||||
|
||||
```php
|
||||
use Zend\Http\Request;
|
||||
|
||||
$request = Request::fromString(<<<EOS
|
||||
POST /foo HTTP/1.1
|
||||
HeaderField1: header-field-value1
|
||||
HeaderField2: header-field-value2
|
||||
|
||||
foo=bar
|
||||
EOS
|
||||
);
|
||||
|
||||
// OR, the completely equivalent
|
||||
|
||||
$request = new Request();
|
||||
$request->setMethod(Request::METHOD_POST);
|
||||
$request->setUri('/foo');
|
||||
$request->getHeaders()->addHeaders([
|
||||
'HeaderField1' => 'header-field-value1',
|
||||
'HeaderField2' => 'header-field-value2',
|
||||
]);
|
||||
$request->getPost()->set('foo', 'bar');
|
||||
```
|
||||
|
||||
## Configuration Options
|
||||
|
||||
No configuration options are available.
|
||||
|
||||
## Available Methods
|
||||
|
||||
The following table details available methods, their signatures, and a brief
|
||||
description. Note that the following references refer to the following
|
||||
fully qualified class names and/or namespaces:
|
||||
|
||||
- `HeaderInterface`: `Zend\Http\Header\HeaderInterface`
|
||||
- `Headers`: `Zend\Http\Headers`
|
||||
- `Header`: `Zend\Http\Header`
|
||||
- `Parameters`: `Zend\Stdlib\ParametersInterface`
|
||||
- `Request`: `Zend\Http\Request`
|
||||
- `Uri`: `Zend\Uri\Http`
|
||||
|
||||
Method signature | Description
|
||||
--------------------------------------------------------------------------- | -----------
|
||||
`static fromString(string $string) : Request` | A factory that produces a `Request` object from a well-formed HTTP request message string.
|
||||
`setMethod(string $method) : self` | Set the method for this request.
|
||||
`getMethod() : string` | Return the method for this request.
|
||||
`setUri(string|Uri $uri) : self` | Set the URI/URL for this request; this can be a string or an instance of `Zend\Uri\Http`.
|
||||
`getUri() : Uri` | Return the URI for this request object.
|
||||
`getUriString() : string` | Return the URI for this request object as a string.
|
||||
`setVersion(string $version) : self` | Set the HTTP version for this object, one of 1.0 or 1.1 (`Request::VERSION_10`, `Request::VERSION_11`).
|
||||
`getVersion() : string` | Return the HTTP version for this request.
|
||||
`setQuery(Parameters $query) : self` | Provide an alternate Parameter Container implementation for query parameters in this object. (This is NOT the primary API for value setting; for that, see `getQuery()`).
|
||||
`getQuery(string|null $name, mixed|null $default) : null|string|Parameters` | Return the parameter container responsible for query parameters or a single query parameter based on `$name`.
|
||||
`setPost(Parameters $post) : self` | Provide an alternate Parameter Container implementation for POST parameters in this object. (This is NOT the primary API for value setting; for that, see `getPost()`).
|
||||
`getPost(string|null $name, mixed|null $default) : null|string|Parameters` | Return the parameter container responsible for POST parameters or a single POST parameter, based on `$name`.
|
||||
`getCookie() : Header\Cookie` | Return the Cookie header, this is the same as calling `$request->getHeaders()->get('Cookie');`.
|
||||
`setFiles(Parameters $files) : self` | Provide an alternate Parameter Container implementation for file parameters in this object, (This is NOT the primary API for value setting; for that, see `getFiles()`).
|
||||
`getFiles(string|null $name, mixed|null $default) : null|string|Parameters` | Return the parameter container responsible for file parameters or a single file parameter, based on `$name`.
|
||||
`setHeaders(Headers $headers) : self` | Provide an alternate Parameter Container implementation for headers in this object, (this is NOT the primary API for value setting, for that see `getHeaders()`).
|
||||
`getHeaders(string|null $name, mixed|null $default) : mixed` | Return the container responsible for storing HTTP headers. This container exposes the primary API for manipulating headers set in the HTTP request. See the section on [Headers](headers.md) for more information. Return value is based on `$name`; `null` returns `Headers`, while a matched header returns a `Header\HeaderInterface` implementation for single-value headers or an `ArrayIterator` for multi-value headers.
|
||||
`setMetadata(string|int|array|Traversable $spec, mixed $value) : self` | Set message metadata. Non-destructive setting of message metadata; always adds to the metadata, never overwrites the entire metadata container.
|
||||
`getMetadata(null|string|int $key, null|mixed $default) : mixed` | Retrieve all metadata or a single metadatum as specified by key.
|
||||
`setContent(mixed $value) : self` | Set request body (content).
|
||||
`getContent() : mixed` | Get request body (content).
|
||||
`isOptions() : bool` | Is this an OPTIONS method request?
|
||||
`isGet() : bool` | Is this a GET method request?
|
||||
`isHead() : bool` | Is this a HEAD method request?
|
||||
`isPost() : bool` | Is this a POST method request?
|
||||
`isPut() : bool` | Is this a PUT method request?
|
||||
`isDelete() : bool` | Is this a DELETE method request?
|
||||
`isTrace() : bool` | Is this a TRACE method request?
|
||||
`isConnect() : bool` | Is this a CONNECT method request?
|
||||
`isPatch() : bool` | Is this a PATCH method request?
|
||||
`isXmlHttpRequest() : bool` | Is this a Javascript XMLHttpRequest?
|
||||
`isFlashRequest() : bool` | Is this a Flash request?
|
||||
`renderRequestLine() : string` | Return the formatted request line (first line) for this HTTP request.
|
||||
`toString() : string` | Returns string
|
||||
`__toString() : string` | Allow PHP casting of this object.
|
||||
|
||||
## Examples
|
||||
|
||||
### Generating a Request object from a string
|
||||
|
||||
```php
|
||||
use Zend\Http\Request;
|
||||
|
||||
$string = "GET /foo HTTP/1.1\r\n\r\nSome Content";
|
||||
$request = Request::fromString($string);
|
||||
|
||||
$request->getMethod(); // returns Request::METHOD_GET
|
||||
$request->getUri(); // returns Zend\Uri\Http object
|
||||
$request->getUriString(); // returns '/foo'
|
||||
$request->getVersion(); // returns Request::VERSION_11 or '1.1'
|
||||
$request->getContent(); // returns 'Some Content'
|
||||
```
|
||||
|
||||
### Retrieving and setting headers
|
||||
|
||||
```php
|
||||
use Zend\Http\Request;
|
||||
use Zend\Http\Header\Cookie;
|
||||
|
||||
$request = new Request();
|
||||
$request->getHeaders()->get('Content-Type'); // return content type
|
||||
$request->getHeaders()->addHeader(new Cookie(['foo' => 'bar']));
|
||||
foreach ($request->getHeaders() as $header) {
|
||||
printf("%s with value %s\n", $header->getFieldName(), $header->getFieldValue());
|
||||
}
|
||||
```
|
||||
|
||||
### Retrieving and setting GET and POST values
|
||||
|
||||
```php
|
||||
use Zend\Http\Request;
|
||||
|
||||
$request = new Request();
|
||||
|
||||
// getPost() and getQuery() both return, by default, a Parameters object, which
|
||||
// extends ArrayObject
|
||||
$request->getPost()->foo = 'Foo value';
|
||||
$request->getQuery()->bar = 'Bar value';
|
||||
$request->getPost('foo'); // returns 'Foo value'
|
||||
$request->getQuery()->offsetGet('bar'); // returns 'Bar value'
|
||||
```
|
||||
|
||||
### Generating a formatted HTTP Request from a Request object
|
||||
|
||||
```php
|
||||
use Zend\Http\Request;
|
||||
|
||||
$request = new Request();
|
||||
$request->setMethod(Request::METHOD_POST);
|
||||
$request->setUri('/foo');
|
||||
$request->getHeaders()->addHeaders([
|
||||
'HeaderField1' => 'header-field-value1',
|
||||
'HeaderField2' => 'header-field-value2',
|
||||
]);
|
||||
$request->getPost()->set('foo', 'bar');
|
||||
$request->setContent($request->getPost()->toString());
|
||||
echo $request->toString();
|
||||
|
||||
/** Will produce:
|
||||
POST /foo HTTP/1.1
|
||||
HeaderField1: header-field-value1
|
||||
HeaderField2: header-field-value2
|
||||
|
||||
foo=bar
|
||||
*/
|
||||
```
|
140
vendor/zendframework/zend-http/doc/book/response.md
vendored
140
vendor/zendframework/zend-http/doc/book/response.md
vendored
@@ -1,140 +0,0 @@
|
||||
# The Response Class
|
||||
|
||||
`Zend\Http\Response` is responsible for providing a fluent API that allows a
|
||||
developer to interact with all the various parts of an HTTP response.
|
||||
|
||||
A typical HTTP Response looks like this:
|
||||
|
||||
```text
|
||||
| VERSION | CODE | REASON |
|
||||
| HEADERS |
|
||||
| BODY |
|
||||
```
|
||||
|
||||
The first line of the response consists of the HTTP version, status code, and
|
||||
the reason string for the provided status code; this is called the Response
|
||||
Line. Next is a set of zero or more headers. The remainder of the response is
|
||||
the response body, which is typically a string of HTML that will render on the
|
||||
client's browser, but which can also be a place for request/response payload
|
||||
data typical of an AJAX request. More information on the structure and
|
||||
specification of an HTTP response can be found in
|
||||
[RFC-2616 on the W3.org site](http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html).
|
||||
|
||||
## Quick Start
|
||||
|
||||
Response objects can either be created from the provided `fromString()` factory,
|
||||
or, if you wish to have a completely empty object to start with, by
|
||||
instantiating the `Zend\Http\Response` class with no arguments.
|
||||
|
||||
```php
|
||||
use Zend\Http\Response;
|
||||
$response = Response::fromString(<<<EOS
|
||||
HTTP/1.0 200 OK
|
||||
HeaderField1: header-field-value
|
||||
HeaderField2: header-field-value2
|
||||
|
||||
<html>
|
||||
<body>
|
||||
Hello World
|
||||
</body>
|
||||
</html>
|
||||
EOS);
|
||||
|
||||
// OR
|
||||
|
||||
$response = new Response();
|
||||
$response->setStatusCode(Response::STATUS_CODE_200);
|
||||
$response->getHeaders()->addHeaders([
|
||||
'HeaderField1' => 'header-field-value',
|
||||
'HeaderField2' => 'header-field-value2',
|
||||
]);
|
||||
$response->setContent(<<<EOS
|
||||
<html>
|
||||
<body>
|
||||
Hello World
|
||||
</body>
|
||||
</html>
|
||||
EOS
|
||||
);
|
||||
```
|
||||
|
||||
## Configuration Options
|
||||
|
||||
No configuration options are available.
|
||||
|
||||
## Available Methods
|
||||
|
||||
The following table details available methods, their signatures, and a brief
|
||||
description. Note that the following references refer to the following
|
||||
fully qualified class names and/or namespaces:
|
||||
|
||||
- `Headers`: `Zend\Http\Headers`
|
||||
- `Response`: `Zend\Http\Response`
|
||||
|
||||
Method signature | Description
|
||||
---------------------------------------------------------------------- | -----------
|
||||
`stati fromString(string $string) : Response` | Populate object from string.
|
||||
`renderStatusLine() : string` | Render the status line header
|
||||
`setHeaders(Headers $headers) : self` | Provide an alternate Parameter Container implementation for headers in this object. (This is NOT the primary API for value setting; for that, see `getHeaders()`.)
|
||||
`getHeaders() : Headers` | Return the container responsible for storing HTTP headers. This container exposes the primary API for manipulating headers set in the HTTP response. See the section on [Headers](headers.md) for more information.
|
||||
`setVersion(string $version) : self` | Set the HTTP version for this object, one of 1.0 or 1.1 (`Request::VERSION_10`, `Request::VERSION_11`).
|
||||
`getVersion() : string` | Return the HTTP version for this request.
|
||||
`setStatusCode(int $code) : self` | Set HTTP status code.
|
||||
`getStatusCode() : int` | Retrieve HTTP status code.
|
||||
`setReasonPhrase(string $reasonPhrase) : self` | Set custom HTTP status message.
|
||||
`getReasonPhrase() : string` | Get HTTP status message.
|
||||
`isClientError() : bool` | Does the status code indicate a client error?
|
||||
`isForbidden() : bool` | Is the request forbidden due to ACLs?
|
||||
`isInformational() : bool` | Is the current status "informational"?
|
||||
`isNotFound() : bool` | Does the status code indicate the resource is not found?
|
||||
`isOk() : bool` | Do we have a normal, OK response?
|
||||
`isServerError() : bool` | Does the status code reflect a server error?
|
||||
`isRedirect() : bool` | Do we have a redirect?
|
||||
`isSuccess() : bool` | Was the response successful?
|
||||
`decodeChunkedBody(string $body) : string` | Decode a "chunked" transfer-encoded body and return the decoded text.
|
||||
`decodeGzip(string $body) : string` | Decode a gzip encoded message (when `Content-Encoding` indicates gzip). Currently requires PHP with zlib support.
|
||||
`decodeDeflate(string $body) : string` | Decode a zlib deflated message (when `Content-Encoding` indicates deflate). Currently requires PHP with zlib support.
|
||||
`setMetadata(string|int|array|Traversable $spec, mixed $value) : self` | Non-destructive setting of message metadata; always adds to the metadata, never overwrites the entire metadata container.
|
||||
`getMetadata(null|string|int $key, null|mixed $default) : mixed` | Retrieve all metadata or a single metadatum as specified by key.
|
||||
`setContent(mixed $value) : self` | Set message content.
|
||||
`getContent() : mixed` | Get raw message content.
|
||||
`getBody() : mixed` | Get decoded message content.
|
||||
`toString() : string` | Returns string representation of response.
|
||||
|
||||
## Examples
|
||||
|
||||
### Generating a Response object from a string
|
||||
|
||||
```php
|
||||
use Zend\Http\Response;
|
||||
$request = Response::fromString(<<<EOS
|
||||
HTTP/1.0 200 OK
|
||||
HeaderField1: header-field-value
|
||||
HeaderField2: header-field-value2
|
||||
|
||||
<html>
|
||||
<body>
|
||||
Hello World
|
||||
</body>
|
||||
</html>
|
||||
EOS);
|
||||
```
|
||||
|
||||
### Generating a formatted HTTP Response from a Response object
|
||||
|
||||
```php
|
||||
use Zend\Http\Response;
|
||||
$response = new Response();
|
||||
$response->setStatusCode(Response::STATUS_CODE_200);
|
||||
$response->getHeaders()->addHeaders([
|
||||
'HeaderField1' => 'header-field-value',
|
||||
'HeaderField2' => 'header-field-value2',
|
||||
]);
|
||||
$response->setContent(<<<EOS
|
||||
<html>
|
||||
<body>
|
||||
Hello World
|
||||
</body>
|
||||
</html>
|
||||
EOS);
|
||||
```
|
19
vendor/zendframework/zend-http/mkdocs.yml
vendored
19
vendor/zendframework/zend-http/mkdocs.yml
vendored
@@ -1,19 +0,0 @@
|
||||
docs_dir: doc/book
|
||||
site_dir: doc/html
|
||||
pages:
|
||||
- index.md
|
||||
- Intro: intro.md
|
||||
- Reference:
|
||||
- Request: request.md
|
||||
- Response: response.md
|
||||
- Headers: headers.md
|
||||
- Client:
|
||||
- Intro: client/intro.md
|
||||
- Adapters: client/adapters.md
|
||||
- "Static Client": client/static.md
|
||||
- "Cookie Persistence": client/cookies.md
|
||||
- Advanced: client/advanced.md
|
||||
site_name: zend-http
|
||||
site_description: zend-http
|
||||
repo_url: 'https://github.com/zendframework/zend-http'
|
||||
copyright: 'Copyright (c) 2016 <a href="http://www.zend.com/">Zend Technologies USA Inc.</a>'
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http;
|
||||
@@ -33,7 +31,7 @@ abstract class AbstractMessage extends Message
|
||||
/**
|
||||
* @var Headers|null
|
||||
*/
|
||||
protected $headers = null;
|
||||
protected $headers;
|
||||
|
||||
/**
|
||||
* Set the HTTP version for this object, one of 1.0 or 1.1
|
||||
|
264
vendor/zendframework/zend-http/src/Client.php
vendored
264
vendor/zendframework/zend-http/src/Client.php
vendored
@@ -1,16 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http;
|
||||
|
||||
use ArrayIterator;
|
||||
use Traversable;
|
||||
use Zend\Http\Client\Adapter\Curl;
|
||||
use Zend\Http\Client\Adapter\Socket;
|
||||
use Zend\Stdlib;
|
||||
use Zend\Stdlib\ArrayUtils;
|
||||
use Zend\Stdlib\ErrorHandler;
|
||||
@@ -66,7 +66,12 @@ class Client implements Stdlib\DispatchableInterface
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $streamName = null;
|
||||
protected $streamName;
|
||||
|
||||
/**
|
||||
* @var resource|null
|
||||
*/
|
||||
protected $streamHandle = null;
|
||||
|
||||
/**
|
||||
* @var array of Header\SetCookie
|
||||
@@ -81,12 +86,12 @@ class Client implements Stdlib\DispatchableInterface
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
protected $lastRawRequest = null;
|
||||
protected $lastRawRequest;
|
||||
|
||||
/**
|
||||
* @var Response
|
||||
*/
|
||||
protected $lastRawResponse = null;
|
||||
protected $lastRawResponse;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
@@ -101,16 +106,19 @@ class Client implements Stdlib\DispatchableInterface
|
||||
protected $config = [
|
||||
'maxredirects' => 5,
|
||||
'strictredirects' => false,
|
||||
'useragent' => 'Zend\Http\Client',
|
||||
'useragent' => Client::class,
|
||||
'timeout' => 10,
|
||||
'adapter' => 'Zend\Http\Client\Adapter\Socket',
|
||||
'connecttimeout' => null,
|
||||
'adapter' => Socket::class,
|
||||
'httpversion' => Request::VERSION_11,
|
||||
'storeresponse' => true,
|
||||
'keepalive' => false,
|
||||
'outputstream' => false,
|
||||
'encodecookies' => true,
|
||||
'argseparator' => null,
|
||||
'rfc3986strict' => false
|
||||
'rfc3986strict' => false,
|
||||
'sslcafile' => null,
|
||||
'sslcapath' => null,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -121,7 +129,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected static $fileInfoDb = null;
|
||||
protected static $fileInfoDb;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -151,7 +159,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
if ($options instanceof Traversable) {
|
||||
$options = ArrayUtils::iteratorToArray($options);
|
||||
}
|
||||
if (!is_array($options)) {
|
||||
if (! is_array($options)) {
|
||||
throw new Client\Exception\InvalidArgumentException('Config parameter is not valid');
|
||||
}
|
||||
|
||||
@@ -181,8 +189,10 @@ class Client implements Stdlib\DispatchableInterface
|
||||
public function setAdapter($adapter)
|
||||
{
|
||||
if (is_string($adapter)) {
|
||||
if (!class_exists($adapter)) {
|
||||
throw new Client\Exception\InvalidArgumentException('Unable to locate adapter class "' . $adapter . '"');
|
||||
if (! class_exists($adapter)) {
|
||||
throw new Client\Exception\InvalidArgumentException(
|
||||
'Unable to locate adapter class "' . $adapter . '"'
|
||||
);
|
||||
}
|
||||
$adapter = new $adapter;
|
||||
}
|
||||
@@ -301,7 +311,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
*/
|
||||
public function setUri($uri)
|
||||
{
|
||||
if (!empty($uri)) {
|
||||
if (! empty($uri)) {
|
||||
// remember host of last request
|
||||
$lastHost = $this->getRequest()->getUri()->getHost();
|
||||
$this->getRequest()->setUri($uri);
|
||||
@@ -310,7 +320,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
// reasons, see #4215 for a discussion - currently authentication is also
|
||||
// cleared for peer subdomains due to technical limits
|
||||
$nextHost = $this->getRequest()->getUri()->getHost();
|
||||
if (!preg_match('/' . preg_quote($lastHost, '/') . '$/i', $nextHost)) {
|
||||
if (! preg_match('/' . preg_quote($lastHost, '/') . '$/i', $nextHost)) {
|
||||
$this->clearAuth();
|
||||
}
|
||||
|
||||
@@ -384,7 +394,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
*/
|
||||
public function setArgSeparator($argSeparator)
|
||||
{
|
||||
$this->setOptions(["argseparator" => $argSeparator]);
|
||||
$this->setOptions(['argseparator' => $argSeparator]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -546,8 +556,17 @@ class Client implements Stdlib\DispatchableInterface
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @return Client
|
||||
*/
|
||||
public function addCookie($cookie, $value = null, $expire = null, $path = null, $domain = null, $secure = false, $httponly = true, $maxAge = null, $version = null)
|
||||
{
|
||||
public function addCookie(
|
||||
$cookie,
|
||||
$value = null,
|
||||
$expire = null,
|
||||
$path = null,
|
||||
$domain = null,
|
||||
$secure = false,
|
||||
$httponly = true,
|
||||
$maxAge = null,
|
||||
$version = null
|
||||
) {
|
||||
if (is_array($cookie) || $cookie instanceof ArrayIterator) {
|
||||
foreach ($cookie as $setCookie) {
|
||||
if ($setCookie instanceof Header\SetCookie) {
|
||||
@@ -557,7 +576,17 @@ class Client implements Stdlib\DispatchableInterface
|
||||
}
|
||||
}
|
||||
} elseif (is_string($cookie) && $value !== null) {
|
||||
$setCookie = new Header\SetCookie($cookie, $value, $expire, $path, $domain, $secure, $httponly, $maxAge, $version);
|
||||
$setCookie = new Header\SetCookie(
|
||||
$cookie,
|
||||
$value,
|
||||
$expire,
|
||||
$path,
|
||||
$domain,
|
||||
$secure,
|
||||
$httponly,
|
||||
$maxAge,
|
||||
$version
|
||||
);
|
||||
$this->cookies[$this->getCookieId($setCookie)] = $setCookie;
|
||||
} elseif ($cookie instanceof Header\SetCookie) {
|
||||
$this->cookies[$this->getCookieId($cookie)] = $cookie;
|
||||
@@ -659,7 +688,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
*/
|
||||
public function setStream($streamfile = true)
|
||||
{
|
||||
$this->setOptions(["outputstream" => $streamfile]);
|
||||
$this->setOptions(['outputstream' => $streamfile]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -686,22 +715,22 @@ class Client implements Stdlib\DispatchableInterface
|
||||
{
|
||||
$this->streamName = $this->config['outputstream'];
|
||||
|
||||
if (!is_string($this->streamName)) {
|
||||
if (! is_string($this->streamName)) {
|
||||
// If name is not given, create temp name
|
||||
$this->streamName = tempnam(
|
||||
isset($this->config['streamtmpdir']) ? $this->config['streamtmpdir'] : sys_get_temp_dir(),
|
||||
'Zend\Http\Client'
|
||||
Client::class
|
||||
);
|
||||
}
|
||||
|
||||
ErrorHandler::start();
|
||||
$fp = fopen($this->streamName, "w+b");
|
||||
$fp = fopen($this->streamName, 'w+b');
|
||||
$error = ErrorHandler::stop();
|
||||
if (false === $fp) {
|
||||
if ($this->adapter instanceof Client\Adapter\AdapterInterface) {
|
||||
$this->adapter->close();
|
||||
}
|
||||
throw new Exception\RuntimeException("Could not open temp file {$this->streamName}", 0, $error);
|
||||
throw new Exception\RuntimeException(sprintf('Could not open temp file %s', $this->streamName), 0, $error);
|
||||
}
|
||||
|
||||
return $fp;
|
||||
@@ -719,18 +748,21 @@ class Client implements Stdlib\DispatchableInterface
|
||||
*/
|
||||
public function setAuth($user, $password, $type = self::AUTH_BASIC)
|
||||
{
|
||||
if (!defined('static::AUTH_' . strtoupper($type))) {
|
||||
throw new Exception\InvalidArgumentException("Invalid or not supported authentication type: '$type'");
|
||||
if (! defined('static::AUTH_' . strtoupper($type))) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Invalid or not supported authentication type: \'%s\'',
|
||||
$type
|
||||
));
|
||||
}
|
||||
|
||||
if (empty($user)) {
|
||||
throw new Exception\InvalidArgumentException("The username cannot be empty");
|
||||
throw new Exception\InvalidArgumentException('The username cannot be empty');
|
||||
}
|
||||
|
||||
$this->auth = [
|
||||
'user' => $user,
|
||||
'password' => $password,
|
||||
'type' => $type
|
||||
'type' => $type,
|
||||
];
|
||||
|
||||
return $this;
|
||||
@@ -758,25 +790,33 @@ class Client implements Stdlib\DispatchableInterface
|
||||
*/
|
||||
protected function calcAuthDigest($user, $password, $type = self::AUTH_BASIC, $digest = [], $entityBody = null)
|
||||
{
|
||||
if (!defined('self::AUTH_' . strtoupper($type))) {
|
||||
throw new Exception\InvalidArgumentException("Invalid or not supported authentication type: '$type'");
|
||||
if (! defined('self::AUTH_' . strtoupper($type))) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Invalid or not supported authentication type: \'%s\'',
|
||||
$type
|
||||
));
|
||||
}
|
||||
$response = false;
|
||||
switch (strtolower($type)) {
|
||||
case self::AUTH_BASIC :
|
||||
case self::AUTH_BASIC:
|
||||
// In basic authentication, the user name cannot contain ":"
|
||||
if (strpos($user, ':') !== false) {
|
||||
throw new Exception\InvalidArgumentException("The user name cannot contain ':' in Basic HTTP authentication");
|
||||
throw new Exception\InvalidArgumentException(
|
||||
'The user name cannot contain \':\' in Basic HTTP authentication'
|
||||
);
|
||||
}
|
||||
$response = base64_encode($user . ':' . $password);
|
||||
break;
|
||||
case self::AUTH_DIGEST :
|
||||
case self::AUTH_DIGEST:
|
||||
if (empty($digest)) {
|
||||
throw new Exception\InvalidArgumentException("The digest cannot be empty");
|
||||
throw new Exception\InvalidArgumentException('The digest cannot be empty');
|
||||
}
|
||||
foreach ($digest as $key => $value) {
|
||||
if (!defined('self::DIGEST_' . strtoupper($key))) {
|
||||
throw new Exception\InvalidArgumentException("Invalid or not supported digest authentication parameter: '$key'");
|
||||
if (! defined('self::DIGEST_' . strtoupper($key))) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Invalid or not supported digest authentication parameter: \'%s\'',
|
||||
$key
|
||||
));
|
||||
}
|
||||
}
|
||||
$ha1 = md5($user . ':' . $digest['realm'] . ':' . $password);
|
||||
@@ -784,7 +824,9 @@ class Client implements Stdlib\DispatchableInterface
|
||||
$ha2 = md5($this->getMethod() . ':' . $this->getUri()->getPath());
|
||||
} elseif (strtolower($digest['qop']) == 'auth-int') {
|
||||
if (empty($entityBody)) {
|
||||
throw new Exception\InvalidArgumentException("I cannot use the auth-int digest authentication without the entity body");
|
||||
throw new Exception\InvalidArgumentException(
|
||||
'I cannot use the auth-int digest authentication without the entity body'
|
||||
);
|
||||
}
|
||||
$ha2 = md5($this->getMethod() . ':' . $this->getUri()->getPath() . ':' . md5($entityBody));
|
||||
}
|
||||
@@ -838,10 +880,10 @@ class Client implements Stdlib\DispatchableInterface
|
||||
// query
|
||||
$query = $this->getRequest()->getQuery();
|
||||
|
||||
if (!empty($query)) {
|
||||
if (! empty($query)) {
|
||||
$queryArray = $query->toArray();
|
||||
|
||||
if (!empty($queryArray)) {
|
||||
if (! empty($queryArray)) {
|
||||
$newUri = $uri->toString();
|
||||
$queryString = http_build_query($queryArray, null, $this->getArgSeparator());
|
||||
|
||||
@@ -859,7 +901,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
}
|
||||
}
|
||||
// If we have no ports, set the defaults
|
||||
if (!$uri->getPort()) {
|
||||
if (! $uri->getPort()) {
|
||||
$uri->setPort($uri->getScheme() == 'https' ? 443 : 80);
|
||||
}
|
||||
|
||||
@@ -884,15 +926,21 @@ class Client implements Stdlib\DispatchableInterface
|
||||
}
|
||||
|
||||
// check that adapter supports streaming before using it
|
||||
if (is_resource($body) && !($adapter instanceof Client\Adapter\StreamInterface)) {
|
||||
if (is_resource($body) && ! ($adapter instanceof Client\Adapter\StreamInterface)) {
|
||||
throw new Client\Exception\RuntimeException('Adapter does not support streaming');
|
||||
}
|
||||
|
||||
$this->streamHandle = null;
|
||||
// calling protected method to allow extending classes
|
||||
// to wrap the interaction with the adapter
|
||||
$response = $this->doRequest($uri, $method, $secure, $headers, $body);
|
||||
$stream = $this->streamHandle;
|
||||
$this->streamHandle = null;
|
||||
|
||||
if (! $response) {
|
||||
if ($stream !== null) {
|
||||
fclose($stream);
|
||||
}
|
||||
throw new Exception\RuntimeException('Unable to read response, or response is empty');
|
||||
}
|
||||
|
||||
@@ -903,9 +951,11 @@ class Client implements Stdlib\DispatchableInterface
|
||||
}
|
||||
|
||||
if ($this->config['outputstream']) {
|
||||
$stream = $this->getStream();
|
||||
if (!is_resource($stream) && is_string($stream)) {
|
||||
$stream = fopen($stream, 'r');
|
||||
if ($stream === null) {
|
||||
$stream = $this->getStream();
|
||||
if (! is_resource($stream) && is_string($stream)) {
|
||||
$stream = fopen($stream, 'r');
|
||||
}
|
||||
}
|
||||
$streamMetaData = stream_get_meta_data($stream);
|
||||
if ($streamMetaData['seekable']) {
|
||||
@@ -915,7 +965,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
$adapter->setOutputStream(null);
|
||||
$response = Response\Stream::fromStream($response, $stream);
|
||||
$response->setStreamName($this->streamName);
|
||||
if (!is_string($this->config['outputstream'])) {
|
||||
if (! is_string($this->config['outputstream'])) {
|
||||
// we used temp name, will need to clean up
|
||||
$response->setCleanup(true);
|
||||
}
|
||||
@@ -925,7 +975,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
|
||||
// Get the cookies from response (if any)
|
||||
$setCookies = $response->getCookie();
|
||||
if (!empty($setCookies)) {
|
||||
if (! empty($setCookies)) {
|
||||
$this->addCookie($setCookies);
|
||||
}
|
||||
|
||||
@@ -937,16 +987,18 @@ class Client implements Stdlib\DispatchableInterface
|
||||
|
||||
// Check whether we send the exact same request again, or drop the parameters
|
||||
// and send a GET request
|
||||
if ($response->getStatusCode() == 303 ||
|
||||
((! $this->config['strictredirects']) && ($response->getStatusCode() == 302 ||
|
||||
$response->getStatusCode() == 301))) {
|
||||
if ($response->getStatusCode() == 303
|
||||
|| ((! $this->config['strictredirects'])
|
||||
&& ($response->getStatusCode() == 302 || $response->getStatusCode() == 301))
|
||||
) {
|
||||
$this->resetParameters(false, false);
|
||||
$this->setMethod(Request::METHOD_GET);
|
||||
}
|
||||
|
||||
// If we got a well formed absolute URI
|
||||
if (($scheme = substr($location, 0, 6)) &&
|
||||
($scheme == 'http:/' || $scheme == 'https:')) {
|
||||
if (($scheme = substr($location, 0, 6))
|
||||
&& ($scheme == 'http:/' || $scheme == 'https:')
|
||||
) {
|
||||
// setURI() clears parameters if host changed, see #4215
|
||||
$this->setUri($location);
|
||||
} else {
|
||||
@@ -965,7 +1017,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
} else {
|
||||
// Get the current path directory, removing any trailing slashes
|
||||
$path = $this->getUri()->getPath();
|
||||
$path = rtrim(substr($path, 0, strrpos($path, '/')), "/");
|
||||
$path = rtrim(substr($path, 0, strrpos($path, '/')), '/');
|
||||
$this->getUri()->setPath($path . '/' . $location);
|
||||
}
|
||||
}
|
||||
@@ -1021,9 +1073,12 @@ class Client implements Stdlib\DispatchableInterface
|
||||
$data = file_get_contents($filename);
|
||||
$error = ErrorHandler::stop();
|
||||
if ($data === false) {
|
||||
throw new Exception\RuntimeException("Unable to read file '{$filename}' for upload", 0, $error);
|
||||
throw new Exception\RuntimeException(sprintf(
|
||||
'Unable to read file \'%s\' for upload',
|
||||
$filename
|
||||
), 0, $error);
|
||||
}
|
||||
if (!$ctype) {
|
||||
if (! $ctype) {
|
||||
$ctype = $this->detectFileMimeType($filename);
|
||||
}
|
||||
}
|
||||
@@ -1032,7 +1087,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
'formname' => $formname,
|
||||
'filename' => basename($filename),
|
||||
'ctype' => $ctype,
|
||||
'data' => $data
|
||||
'data' => $data,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
@@ -1047,7 +1102,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
public function removeFileUpload($filename)
|
||||
{
|
||||
$file = $this->getRequest()->getFiles()->get($filename);
|
||||
if (!empty($file)) {
|
||||
if (! empty($file)) {
|
||||
$this->getRequest()->getFiles()->set($filename, null);
|
||||
return true;
|
||||
}
|
||||
@@ -1066,7 +1121,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
{
|
||||
$validCookies = [];
|
||||
|
||||
if (!empty($this->cookies)) {
|
||||
if (! empty($this->cookies)) {
|
||||
foreach ($this->cookies as $id => $cookie) {
|
||||
if ($cookie->isExpired()) {
|
||||
unset($this->cookies[$id]);
|
||||
@@ -1102,8 +1157,9 @@ class Client implements Stdlib\DispatchableInterface
|
||||
if ($this->config['httpversion'] == Request::VERSION_11) {
|
||||
$host = $uri->getHost();
|
||||
// If the port is not default, add it
|
||||
if (!(($uri->getScheme() == 'http' && $uri->getPort() == 80) ||
|
||||
($uri->getScheme() == 'https' && $uri->getPort() == 443))) {
|
||||
if (! (($uri->getScheme() == 'http' && $uri->getPort() == 80)
|
||||
|| ($uri->getScheme() == 'https' && $uri->getPort() == 443))
|
||||
) {
|
||||
$host .= ':' . $uri->getPort();
|
||||
}
|
||||
|
||||
@@ -1111,15 +1167,15 @@ class Client implements Stdlib\DispatchableInterface
|
||||
}
|
||||
|
||||
// Set the connection header
|
||||
if (!$this->getRequest()->getHeaders()->has('Connection')) {
|
||||
if (!$this->config['keepalive']) {
|
||||
if (! $this->getRequest()->getHeaders()->has('Connection')) {
|
||||
if (! $this->config['keepalive']) {
|
||||
$headers['Connection'] = 'close';
|
||||
}
|
||||
}
|
||||
|
||||
// Set the Accept-encoding header if not set - depending on whether
|
||||
// zlib is available or not.
|
||||
if (!$this->getRequest()->getHeaders()->has('Accept-Encoding')) {
|
||||
if (! $this->getRequest()->getHeaders()->has('Accept-Encoding')) {
|
||||
if (function_exists('gzinflate')) {
|
||||
$headers['Accept-Encoding'] = 'gzip, deflate';
|
||||
} else {
|
||||
@@ -1127,24 +1183,26 @@ class Client implements Stdlib\DispatchableInterface
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set the user agent header
|
||||
if (!$this->getRequest()->getHeaders()->has('User-Agent') && isset($this->config['useragent'])) {
|
||||
if (! $this->getRequest()->getHeaders()->has('User-Agent') && isset($this->config['useragent'])) {
|
||||
$headers['User-Agent'] = $this->config['useragent'];
|
||||
}
|
||||
|
||||
// Set HTTP authentication if needed
|
||||
if (!empty($this->auth)) {
|
||||
if (! empty($this->auth)) {
|
||||
switch ($this->auth['type']) {
|
||||
case self::AUTH_BASIC :
|
||||
case self::AUTH_BASIC:
|
||||
$auth = $this->calcAuthDigest($this->auth['user'], $this->auth['password'], $this->auth['type']);
|
||||
if ($auth !== false) {
|
||||
$headers['Authorization'] = 'Basic ' . $auth;
|
||||
}
|
||||
break;
|
||||
case self::AUTH_DIGEST :
|
||||
if (!$this->adapter instanceof Client\Adapter\Curl) {
|
||||
throw new Exception\RuntimeException("The digest authentication is only available for curl adapters (Zend\\Http\\Client\\Adapter\\Curl)");
|
||||
case self::AUTH_DIGEST:
|
||||
if (! $this->adapter instanceof Client\Adapter\Curl) {
|
||||
throw new Exception\RuntimeException(sprintf(
|
||||
'The digest authentication is only available for curl adapters (%s)',
|
||||
Curl::class
|
||||
));
|
||||
}
|
||||
|
||||
$this->adapter->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
|
||||
@@ -1154,11 +1212,11 @@ class Client implements Stdlib\DispatchableInterface
|
||||
|
||||
// Content-type
|
||||
$encType = $this->getEncType();
|
||||
if (!empty($encType)) {
|
||||
if (! empty($encType)) {
|
||||
$headers['Content-Type'] = $encType;
|
||||
}
|
||||
|
||||
if (!empty($body)) {
|
||||
if (! empty($body)) {
|
||||
if (is_resource($body)) {
|
||||
$fstat = fstat($body);
|
||||
$headers['Content-Length'] = $fstat['size'];
|
||||
@@ -1176,7 +1234,6 @@ class Client implements Stdlib\DispatchableInterface
|
||||
return $headers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepare the request body (for PATCH, POST and PUT requests)
|
||||
*
|
||||
@@ -1191,17 +1248,17 @@ class Client implements Stdlib\DispatchableInterface
|
||||
}
|
||||
|
||||
$rawBody = $this->getRequest()->getContent();
|
||||
if (!empty($rawBody)) {
|
||||
if (! empty($rawBody)) {
|
||||
return $rawBody;
|
||||
}
|
||||
|
||||
$body = '';
|
||||
$totalFiles = 0;
|
||||
$hasFiles = false;
|
||||
|
||||
if (!$this->getRequest()->getHeaders()->has('Content-Type')) {
|
||||
$totalFiles = count($this->getRequest()->getFiles()->toArray());
|
||||
if (! $this->getRequest()->getHeaders()->has('Content-Type')) {
|
||||
$hasFiles = ! empty($this->getRequest()->getFiles()->toArray());
|
||||
// If we have files to upload, force encType to multipart/form-data
|
||||
if ($totalFiles > 0) {
|
||||
if ($hasFiles) {
|
||||
$this->setEncType(self::ENC_FORMDATA);
|
||||
}
|
||||
} else {
|
||||
@@ -1209,7 +1266,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
}
|
||||
|
||||
// If we have POST parameters or files, encode and add them to the body
|
||||
if (count($this->getRequest()->getPost()->toArray()) > 0 || $totalFiles > 0) {
|
||||
if (! empty($this->getRequest()->getPost()->toArray()) || $hasFiles) {
|
||||
if (stripos($this->getEncType(), self::ENC_FORMDATA) === 0) {
|
||||
$boundary = '---ZENDHTTPCLIENT-' . md5(microtime());
|
||||
$this->setEncType(self::ENC_FORMDATA, $boundary);
|
||||
@@ -1223,14 +1280,23 @@ class Client implements Stdlib\DispatchableInterface
|
||||
// Encode files
|
||||
foreach ($this->getRequest()->getFiles()->toArray() as $file) {
|
||||
$fhead = ['Content-Type' => $file['ctype']];
|
||||
$body .= $this->encodeFormData($boundary, $file['formname'], $file['data'], $file['filename'], $fhead);
|
||||
$body .= $this->encodeFormData(
|
||||
$boundary,
|
||||
$file['formname'],
|
||||
$file['data'],
|
||||
$file['filename'],
|
||||
$fhead
|
||||
);
|
||||
}
|
||||
$body .= "--{$boundary}--\r\n";
|
||||
$body .= '--' . $boundary . '--' . "\r\n";
|
||||
} elseif (stripos($this->getEncType(), self::ENC_URLENCODED) === 0) {
|
||||
// Encode body as application/x-www-form-urlencoded
|
||||
$body = http_build_query($this->getRequest()->getPost()->toArray());
|
||||
$body = http_build_query($this->getRequest()->getPost()->toArray(), null, '&');
|
||||
} else {
|
||||
throw new Client\Exception\RuntimeException("Cannot handle content type '{$this->encType}' automatically");
|
||||
throw new Client\Exception\RuntimeException(sprintf(
|
||||
'Cannot handle content type \'%s\' automatically',
|
||||
$this->encType
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1291,8 +1357,8 @@ class Client implements Stdlib\DispatchableInterface
|
||||
*/
|
||||
public function encodeFormData($boundary, $name, $value, $filename = null, $headers = [])
|
||||
{
|
||||
$ret = "--{$boundary}\r\n" .
|
||||
'Content-Disposition: form-data; name="' . $name . '"';
|
||||
$ret = '--' . $boundary . "\r\n"
|
||||
. 'Content-Disposition: form-data; name="' . $name . '"';
|
||||
|
||||
if ($filename) {
|
||||
$ret .= '; filename="' . $filename . '"';
|
||||
@@ -1300,10 +1366,10 @@ class Client implements Stdlib\DispatchableInterface
|
||||
$ret .= "\r\n";
|
||||
|
||||
foreach ($headers as $hname => $hvalue) {
|
||||
$ret .= "{$hname}: {$hvalue}\r\n";
|
||||
$ret .= $hname . ': ' . $hvalue . "\r\n";
|
||||
}
|
||||
$ret .= "\r\n";
|
||||
$ret .= "{$value}\r\n";
|
||||
$ret .= $value . "\r\n";
|
||||
|
||||
return $ret;
|
||||
}
|
||||
@@ -1324,7 +1390,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
*/
|
||||
protected function flattenParametersArray($parray, $prefix = null)
|
||||
{
|
||||
if (!is_array($parray)) {
|
||||
if (! is_array($parray)) {
|
||||
return $parray;
|
||||
}
|
||||
|
||||
@@ -1336,7 +1402,7 @@ class Client implements Stdlib\DispatchableInterface
|
||||
if (is_int($name)) {
|
||||
$key = $prefix . '[]';
|
||||
} else {
|
||||
$key = $prefix . "[$name]";
|
||||
$key = $prefix . sprintf('[%s]', $name);
|
||||
}
|
||||
} else {
|
||||
$key = $name;
|
||||
@@ -1371,8 +1437,8 @@ class Client implements Stdlib\DispatchableInterface
|
||||
|
||||
if ($this->config['outputstream']) {
|
||||
if ($this->adapter instanceof Client\Adapter\StreamInterface) {
|
||||
$stream = $this->openTempStream();
|
||||
$this->adapter->setOutputStream($stream);
|
||||
$this->streamHandle = $this->openTempStream();
|
||||
$this->adapter->setOutputStream($this->streamHandle);
|
||||
} else {
|
||||
throw new Exception\RuntimeException('Adapter does not support streaming');
|
||||
}
|
||||
@@ -1406,20 +1472,24 @@ class Client implements Stdlib\DispatchableInterface
|
||||
case self::AUTH_BASIC:
|
||||
// In basic authentication, the user name cannot contain ":"
|
||||
if (strpos($user, ':') !== false) {
|
||||
throw new Client\Exception\InvalidArgumentException("The user name cannot contain ':' in 'Basic' HTTP authentication");
|
||||
throw new Client\Exception\InvalidArgumentException(
|
||||
'The user name cannot contain \':\' in \'Basic\' HTTP authentication'
|
||||
);
|
||||
}
|
||||
|
||||
return 'Basic ' . base64_encode($user . ':' . $password);
|
||||
|
||||
//case self::AUTH_DIGEST:
|
||||
/**
|
||||
* @todo Implement digest authentication
|
||||
*/
|
||||
* @todo Implement digest authentication
|
||||
*/
|
||||
// break;
|
||||
|
||||
default:
|
||||
throw new Client\Exception\InvalidArgumentException("Not a supported HTTP authentication type: '$type'");
|
||||
|
||||
throw new Client\Exception\InvalidArgumentException(sprintf(
|
||||
'Not a supported HTTP authentication type: \'%s\'',
|
||||
$type
|
||||
));
|
||||
}
|
||||
|
||||
return;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Adapter;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Adapter;
|
||||
@@ -20,6 +18,13 @@ use Zend\Stdlib\ArrayUtils;
|
||||
*/
|
||||
class Curl implements HttpAdapter, StreamInterface
|
||||
{
|
||||
/**
|
||||
* Operation timeout.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const ERROR_OPERATION_TIMEDOUT = 28;
|
||||
|
||||
/**
|
||||
* Parameters array
|
||||
*
|
||||
@@ -39,7 +44,7 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
*
|
||||
* @var resource|null
|
||||
*/
|
||||
protected $curl = null;
|
||||
protected $curl;
|
||||
|
||||
/**
|
||||
* List of cURL options that should never be overwritten
|
||||
@@ -53,7 +58,7 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $response = null;
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
* Stream for storing output
|
||||
@@ -71,7 +76,7 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (!extension_loaded('curl')) {
|
||||
if (! extension_loaded('curl')) {
|
||||
throw new AdapterException\InitializationException(
|
||||
'cURL extension has to be loaded to use this Zend\Http\Client adapter'
|
||||
);
|
||||
@@ -104,10 +109,11 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
if ($options instanceof Traversable) {
|
||||
$options = ArrayUtils::iteratorToArray($options);
|
||||
}
|
||||
if (!is_array($options)) {
|
||||
throw new AdapterException\InvalidArgumentException(
|
||||
'Array or Traversable object expected, got ' . gettype($options)
|
||||
);
|
||||
if (! is_array($options)) {
|
||||
throw new AdapterException\InvalidArgumentException(sprintf(
|
||||
'Array or Traversable object expected, got %s',
|
||||
gettype($options)
|
||||
));
|
||||
}
|
||||
|
||||
/** Config Key Normalization */
|
||||
@@ -117,7 +123,7 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
}
|
||||
|
||||
if (isset($options['proxyuser']) && isset($options['proxypass'])) {
|
||||
$this->setCurlOption(CURLOPT_PROXYUSERPWD, $options['proxyuser'] . ":" . $options['proxypass']);
|
||||
$this->setCurlOption(CURLOPT_PROXYUSERPWD, $options['proxyuser'] . ':' . $options['proxypass']);
|
||||
unset($options['proxyuser'], $options['proxypass']);
|
||||
}
|
||||
|
||||
@@ -166,7 +172,7 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
*/
|
||||
public function setCurlOption($option, $value)
|
||||
{
|
||||
if (!isset($this->config['curloptions'])) {
|
||||
if (! isset($this->config['curloptions'])) {
|
||||
$this->config['curloptions'] = [];
|
||||
}
|
||||
$this->config['curloptions'][$option] = $value;
|
||||
@@ -195,13 +201,22 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
curl_setopt($this->curl, CURLOPT_PORT, intval($port));
|
||||
}
|
||||
|
||||
if (isset($this->config['timeout'])) {
|
||||
if (isset($this->config['connecttimeout'])) {
|
||||
$connectTimeout = $this->config['connecttimeout'];
|
||||
} elseif (isset($this->config['timeout'])) {
|
||||
$connectTimeout = $this->config['timeout'];
|
||||
} else {
|
||||
$connectTimeout = null;
|
||||
}
|
||||
if ($connectTimeout !== null) {
|
||||
if (defined('CURLOPT_CONNECTTIMEOUT_MS')) {
|
||||
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT_MS, $this->config['timeout'] * 1000);
|
||||
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT_MS, $connectTimeout * 1000);
|
||||
} else {
|
||||
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, $this->config['timeout']);
|
||||
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, $connectTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->config['timeout'])) {
|
||||
if (defined('CURLOPT_TIMEOUT_MS')) {
|
||||
curl_setopt($this->curl, CURLOPT_TIMEOUT_MS, $this->config['timeout'] * 1000);
|
||||
} else {
|
||||
@@ -209,12 +224,19 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->config['sslcafile']) && $this->config['sslcafile']) {
|
||||
curl_setopt($this->curl, CURLOPT_CAINFO, $this->config['sslcafile']);
|
||||
}
|
||||
if (isset($this->config['sslcapath']) && $this->config['sslcapath']) {
|
||||
curl_setopt($this->curl, CURLOPT_CAPATH, $this->config['sslcapath']);
|
||||
}
|
||||
|
||||
if (isset($this->config['maxredirects'])) {
|
||||
// Set Max redirects
|
||||
curl_setopt($this->curl, CURLOPT_MAXREDIRS, $this->config['maxredirects']);
|
||||
}
|
||||
|
||||
if (!$this->curl) {
|
||||
if (! $this->curl) {
|
||||
$this->close();
|
||||
|
||||
throw new AdapterException\RuntimeException('Unable to Connect to ' . $host . ':' . $port);
|
||||
@@ -247,16 +269,17 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
* to wrong host, no PUT file defined, unsupported method, or unsupported
|
||||
* cURL option.
|
||||
* @throws AdapterException\InvalidArgumentException if $method is currently not supported
|
||||
* @throws AdapterException\TimeoutException if connection timed out
|
||||
*/
|
||||
public function write($method, $uri, $httpVersion = 1.1, $headers = [], $body = '')
|
||||
{
|
||||
// Make sure we're properly connected
|
||||
if (!$this->curl) {
|
||||
throw new AdapterException\RuntimeException("Trying to write but we are not connected");
|
||||
if (! $this->curl) {
|
||||
throw new AdapterException\RuntimeException('Trying to write but we are not connected');
|
||||
}
|
||||
|
||||
if ($this->connectedTo[0] != $uri->getHost() || $this->connectedTo[1] != $uri->getPort()) {
|
||||
throw new AdapterException\RuntimeException("Trying to write but we are connected to the wrong host");
|
||||
throw new AdapterException\RuntimeException('Trying to write but we are connected to the wrong host');
|
||||
}
|
||||
|
||||
// set URL
|
||||
@@ -282,8 +305,8 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
if (isset($this->config['curloptions'][CURLOPT_INFILE])) {
|
||||
// Now we will probably already have Content-Length set, so that we have to delete it
|
||||
// from $headers at this point:
|
||||
if (!isset($headers['Content-Length'])
|
||||
&& !isset($this->config['curloptions'][CURLOPT_INFILESIZE])
|
||||
if (! isset($headers['Content-Length'])
|
||||
&& ! isset($this->config['curloptions'][CURLOPT_INFILESIZE])
|
||||
) {
|
||||
throw new AdapterException\RuntimeException(
|
||||
'Cannot set a file-handle for cURL option CURLOPT_INFILE'
|
||||
@@ -303,46 +326,49 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
$curlMethod = CURLOPT_UPLOAD;
|
||||
} else {
|
||||
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
||||
$curlValue = "PUT";
|
||||
$curlValue = 'PUT';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'PATCH':
|
||||
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
||||
$curlValue = "PATCH";
|
||||
$curlValue = 'PATCH';
|
||||
break;
|
||||
|
||||
case 'DELETE':
|
||||
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
||||
$curlValue = "DELETE";
|
||||
$curlValue = 'DELETE';
|
||||
break;
|
||||
|
||||
case 'OPTIONS':
|
||||
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
||||
$curlValue = "OPTIONS";
|
||||
$curlValue = 'OPTIONS';
|
||||
break;
|
||||
|
||||
case 'TRACE':
|
||||
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
||||
$curlValue = "TRACE";
|
||||
$curlValue = 'TRACE';
|
||||
break;
|
||||
|
||||
case 'HEAD':
|
||||
$curlMethod = CURLOPT_CUSTOMREQUEST;
|
||||
$curlValue = "HEAD";
|
||||
$curlValue = 'HEAD';
|
||||
break;
|
||||
|
||||
default:
|
||||
// For now, through an exception for unsupported request methods
|
||||
throw new AdapterException\InvalidArgumentException("Method '$method' currently not supported");
|
||||
throw new AdapterException\InvalidArgumentException(sprintf(
|
||||
'Method \'%s\' currently not supported',
|
||||
$method
|
||||
));
|
||||
}
|
||||
|
||||
if (is_resource($body) && $curlMethod != CURLOPT_UPLOAD) {
|
||||
throw new AdapterException\RuntimeException("Streaming requests are allowed only with PUT");
|
||||
throw new AdapterException\RuntimeException('Streaming requests are allowed only with PUT');
|
||||
}
|
||||
|
||||
// get http version to use
|
||||
$curlHttp = ($httpVersion == 1.1) ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
|
||||
$curlHttp = $httpVersion == 1.1 ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
|
||||
|
||||
// mark as HTTP request and set HTTP method
|
||||
curl_setopt($this->curl, CURLOPT_HTTP_VERSION, $curlHttp);
|
||||
@@ -354,7 +380,7 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
if ($this->outputStream) {
|
||||
// headers will be read into the response
|
||||
curl_setopt($this->curl, CURLOPT_HEADER, false);
|
||||
curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, [$this, "readHeader"]);
|
||||
curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, [$this, 'readHeader']);
|
||||
// and data will be written into the file
|
||||
curl_setopt($this->curl, CURLOPT_FILE, $this->outputStream);
|
||||
} else {
|
||||
@@ -373,7 +399,7 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
}
|
||||
|
||||
// set additional headers
|
||||
if (!isset($headers['Accept'])) {
|
||||
if (! isset($headers['Accept'])) {
|
||||
$headers['Accept'] = '';
|
||||
}
|
||||
$curlHeaders = [];
|
||||
@@ -402,7 +428,7 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
// set additional curl options
|
||||
if (isset($this->config['curloptions'])) {
|
||||
foreach ((array) $this->config['curloptions'] as $k => $v) {
|
||||
if (!in_array($k, $this->invalidOverwritableCurlOptions)) {
|
||||
if (! in_array($k, $this->invalidOverwritableCurlOptions)) {
|
||||
if (curl_setopt($this->curl, $k, $v) == false) {
|
||||
throw new AdapterException\RuntimeException(sprintf(
|
||||
'Unknown or erroreous cURL option "%s" set',
|
||||
@@ -413,19 +439,30 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
}
|
||||
}
|
||||
|
||||
$this->response = '';
|
||||
|
||||
// send the request
|
||||
|
||||
$response = curl_exec($this->curl);
|
||||
// if we used streaming, headers are already there
|
||||
if (!is_resource($this->outputStream)) {
|
||||
if (! is_resource($this->outputStream)) {
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
$request = curl_getinfo($this->curl, CURLINFO_HEADER_OUT);
|
||||
$request .= $body;
|
||||
|
||||
if (empty($this->response)) {
|
||||
throw new AdapterException\RuntimeException("Error in cURL request: " . curl_error($this->curl));
|
||||
if ($response === false || empty($this->response)) {
|
||||
if (curl_errno($this->curl) === static::ERROR_OPERATION_TIMEDOUT) {
|
||||
throw new AdapterException\TimeoutException(
|
||||
'Read timed out',
|
||||
AdapterException\TimeoutException::READ_TIMEOUT
|
||||
);
|
||||
}
|
||||
throw new AdapterException\RuntimeException(sprintf(
|
||||
'Error in cURL request: %s',
|
||||
curl_error($this->curl)
|
||||
));
|
||||
}
|
||||
|
||||
// separating header from body because it is dangerous to accidentially replace strings in the body
|
||||
@@ -434,7 +471,7 @@ class Curl implements HttpAdapter, StreamInterface
|
||||
|
||||
// cURL automatically decodes chunked-messages, this means we have to
|
||||
// disallow the Zend\Http\Response to do it again.
|
||||
$responseHeaders = preg_replace("/Transfer-Encoding:\s*chunked\\r\\n/i", "", $responseHeaders);
|
||||
$responseHeaders = preg_replace("/Transfer-Encoding:\s*chunked\\r\\n/i", '', $responseHeaders);
|
||||
|
||||
// cURL can automatically handle content encoding; prevent double-decoding from occurring
|
||||
if (isset($this->config['curloptions'][CURLOPT_ENCODING])
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Adapter\Exception;
|
||||
|
@@ -1,16 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Adapter\Exception;
|
||||
|
||||
/**
|
||||
*/
|
||||
class InitializationException extends RuntimeException
|
||||
{
|
||||
}
|
||||
|
@@ -1,18 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Adapter\Exception;
|
||||
|
||||
use Zend\Http\Client\Exception;
|
||||
|
||||
/**
|
||||
*/
|
||||
class InvalidArgumentException extends Exception\InvalidArgumentException implements
|
||||
ExceptionInterface
|
||||
{
|
||||
|
@@ -1,18 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Adapter\Exception;
|
||||
|
||||
use Zend\Http\Client\Exception;
|
||||
|
||||
/**
|
||||
*/
|
||||
class OutOfRangeException extends Exception\OutOfRangeException implements
|
||||
ExceptionInterface
|
||||
{
|
||||
|
@@ -1,18 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Adapter\Exception;
|
||||
|
||||
use Zend\Http\Client\Exception;
|
||||
|
||||
/**
|
||||
*/
|
||||
class RuntimeException extends Exception\RuntimeException implements
|
||||
ExceptionInterface
|
||||
{
|
||||
|
@@ -1,16 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Adapter\Exception;
|
||||
|
||||
/**
|
||||
*/
|
||||
class TimeoutException extends RuntimeException implements ExceptionInterface
|
||||
{
|
||||
const READ_TIMEOUT = 1000;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Adapter;
|
||||
@@ -31,19 +29,21 @@ class Proxy extends Socket
|
||||
* @var array
|
||||
*/
|
||||
protected $config = [
|
||||
'persistent' => false,
|
||||
'ssltransport' => 'ssl',
|
||||
'sslcert' => null,
|
||||
'sslpassphrase' => null,
|
||||
'sslverifypeer' => true,
|
||||
'sslcafile' => null,
|
||||
'sslcapath' => null,
|
||||
'sslallowselfsigned' => false,
|
||||
'sslusecontext' => false,
|
||||
'sslverifypeername' => true,
|
||||
'proxy_host' => '',
|
||||
'proxy_port' => 8080,
|
||||
'proxy_user' => '',
|
||||
'proxy_pass' => '',
|
||||
'proxy_auth' => Client::AUTH_BASIC,
|
||||
'persistent' => false
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ class Proxy extends Socket
|
||||
{
|
||||
//enforcing that the proxy keys are set in the form proxy_*
|
||||
foreach ($options as $k => $v) {
|
||||
if (preg_match("/^proxy[a-z]+/", $k)) {
|
||||
if (preg_match('/^proxy[a-z]+/', $k)) {
|
||||
$options['proxy_' . substr($k, 5, strlen($k))] = $v;
|
||||
unset($options[$k]);
|
||||
}
|
||||
@@ -123,25 +123,29 @@ class Proxy extends Socket
|
||||
|
||||
// Make sure we're properly connected
|
||||
if (! $this->socket) {
|
||||
throw new AdapterException\RuntimeException("Trying to write but we are not connected");
|
||||
throw new AdapterException\RuntimeException('Trying to write but we are not connected');
|
||||
}
|
||||
|
||||
$host = $this->config['proxy_host'];
|
||||
$port = $this->config['proxy_port'];
|
||||
|
||||
if ($this->connectedTo[0] != "tcp://$host" || $this->connectedTo[1] != $port) {
|
||||
throw new AdapterException\RuntimeException("Trying to write but we are connected to the wrong proxy server");
|
||||
if ($this->connectedTo[0] != sprintf('tcp://%s', $host) || $this->connectedTo[1] != $port) {
|
||||
throw new AdapterException\RuntimeException(
|
||||
'Trying to write but we are connected to the wrong proxy server'
|
||||
);
|
||||
}
|
||||
|
||||
// Add Proxy-Authorization header
|
||||
if ($this->config['proxy_user'] && ! isset($headers['proxy-authorization'])) {
|
||||
$headers['proxy-authorization'] = Client::encodeAuthHeader(
|
||||
$this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']
|
||||
$this->config['proxy_user'],
|
||||
$this->config['proxy_pass'],
|
||||
$this->config['proxy_auth']
|
||||
);
|
||||
}
|
||||
|
||||
// if we are proxying HTTPS, preform CONNECT handshake with the proxy
|
||||
if ($uri->getScheme() == 'https' && (! $this->negotiated)) {
|
||||
if ($uri->getScheme() == 'https' && ! $this->negotiated) {
|
||||
$this->connectHandshake($uri->getHost(), $uri->getPort(), $httpVer, $headers);
|
||||
$this->negotiated = true;
|
||||
}
|
||||
@@ -155,17 +159,17 @@ class Proxy extends Socket
|
||||
if ($uri->getQuery()) {
|
||||
$path .= '?' . $uri->getQuery();
|
||||
}
|
||||
$request = "$method $path HTTP/$httpVer\r\n";
|
||||
$request = sprintf('%s %s HTTP/%s%s', $method, $path, $httpVer, "\r\n");
|
||||
} else {
|
||||
$request = "$method $uri HTTP/$httpVer\r\n";
|
||||
$request = sprintf('%s %s HTTP/%s%s', $method, $uri, $httpVer, "\r\n");
|
||||
}
|
||||
|
||||
// Add all headers to the request string
|
||||
foreach ($headers as $k => $v) {
|
||||
if (is_string($k)) {
|
||||
$v = "$k: $v";
|
||||
$v = $k . ': ' . $v;
|
||||
}
|
||||
$request .= "$v\r\n";
|
||||
$request .= $v . "\r\n";
|
||||
}
|
||||
|
||||
if (is_resource($body)) {
|
||||
@@ -179,8 +183,8 @@ class Proxy extends Socket
|
||||
ErrorHandler::start();
|
||||
$test = fwrite($this->socket, $request);
|
||||
$error = ErrorHandler::stop();
|
||||
if (!$test) {
|
||||
throw new AdapterException\RuntimeException("Error writing request to proxy server", 0, $error);
|
||||
if (! $test) {
|
||||
throw new AdapterException\RuntimeException('Error writing request to proxy server', 0, $error);
|
||||
}
|
||||
|
||||
if (is_resource($body)) {
|
||||
@@ -203,18 +207,18 @@ class Proxy extends Socket
|
||||
*/
|
||||
protected function connectHandshake($host, $port = 443, $httpVer = '1.1', array &$headers = [])
|
||||
{
|
||||
$request = "CONNECT $host:$port HTTP/$httpVer\r\n" .
|
||||
"Host: " . $host . "\r\n";
|
||||
$request = 'CONNECT ' . $host . ':' . $port . ' HTTP/' . $httpVer . "\r\n"
|
||||
. 'Host: ' . $host . "\r\n";
|
||||
|
||||
// Add the user-agent header
|
||||
if (isset($this->config['useragent'])) {
|
||||
$request .= "User-agent: " . $this->config['useragent'] . "\r\n";
|
||||
$request .= 'User-agent: ' . $this->config['useragent'] . "\r\n";
|
||||
}
|
||||
|
||||
// If the proxy-authorization header is set, send it to proxy but remove
|
||||
// it from headers sent to target host
|
||||
if (isset($headers['proxy-authorization'])) {
|
||||
$request .= "Proxy-authorization: " . $headers['proxy-authorization'] . "\r\n";
|
||||
$request .= 'Proxy-authorization: ' . $headers['proxy-authorization'] . "\r\n";
|
||||
unset($headers['proxy-authorization']);
|
||||
}
|
||||
|
||||
@@ -224,8 +228,8 @@ class Proxy extends Socket
|
||||
ErrorHandler::start();
|
||||
$test = fwrite($this->socket, $request);
|
||||
$error = ErrorHandler::stop();
|
||||
if (!$test) {
|
||||
throw new AdapterException\RuntimeException("Error writing request to proxy server", 0, $error);
|
||||
if (! $test) {
|
||||
throw new AdapterException\RuntimeException('Error writing request to proxy server', 0, $error);
|
||||
}
|
||||
|
||||
// Read response headers only
|
||||
@@ -236,7 +240,7 @@ class Proxy extends Socket
|
||||
$gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
|
||||
if ($gotStatus) {
|
||||
$response .= $line;
|
||||
if (!rtrim($line)) {
|
||||
if (! rtrim($line)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -245,7 +249,10 @@ class Proxy extends Socket
|
||||
|
||||
// Check that the response from the proxy is 200
|
||||
if (Response::fromString($response)->getStatusCode() != 200) {
|
||||
throw new AdapterException\RuntimeException("Unable to connect to HTTPS proxy. Server response: " . $response);
|
||||
throw new AdapterException\RuntimeException(sprintf(
|
||||
'Unable to connect to HTTPS proxy. Server response: %s',
|
||||
$response
|
||||
));
|
||||
}
|
||||
|
||||
// If all is good, switch socket to secure mode. We have to fall back
|
||||
@@ -254,7 +261,7 @@ class Proxy extends Socket
|
||||
STREAM_CRYPTO_METHOD_TLS_CLIENT,
|
||||
STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
|
||||
STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
|
||||
STREAM_CRYPTO_METHOD_SSLv2_CLIENT
|
||||
STREAM_CRYPTO_METHOD_SSLv2_CLIENT,
|
||||
];
|
||||
|
||||
$success = false;
|
||||
@@ -266,14 +273,14 @@ class Proxy extends Socket
|
||||
}
|
||||
|
||||
if (! $success) {
|
||||
throw new AdapterException\RuntimeException("Unable to connect to" .
|
||||
" HTTPS server through proxy: could not negotiate secure connection.");
|
||||
throw new AdapterException\RuntimeException(
|
||||
'Unable to connect to HTTPS server through proxy: could not negotiate secure connection.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection to the server
|
||||
*
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
@@ -283,7 +290,6 @@ class Proxy extends Socket
|
||||
|
||||
/**
|
||||
* Destructor: make sure the socket is disconnected
|
||||
*
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Adapter;
|
||||
@@ -12,6 +10,7 @@ namespace Zend\Http\Client\Adapter;
|
||||
use Traversable;
|
||||
use Zend\Http\Client\Adapter\AdapterInterface as HttpAdapter;
|
||||
use Zend\Http\Client\Adapter\Exception as AdapterException;
|
||||
use Zend\Http\Request;
|
||||
use Zend\Http\Response;
|
||||
use Zend\Stdlib\ArrayUtils;
|
||||
use Zend\Stdlib\ErrorHandler;
|
||||
@@ -39,7 +38,7 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
*
|
||||
* @var resource|null
|
||||
*/
|
||||
protected $socket = null;
|
||||
protected $socket;
|
||||
|
||||
/**
|
||||
* What host/port are we connected to?
|
||||
@@ -53,7 +52,7 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $outStream = null;
|
||||
protected $outStream;
|
||||
|
||||
/**
|
||||
* Parameters array
|
||||
@@ -70,6 +69,7 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
'sslcapath' => null,
|
||||
'sslallowselfsigned' => false,
|
||||
'sslusecontext' => false,
|
||||
'sslverifypeername' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -77,14 +77,14 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $method = null;
|
||||
protected $method;
|
||||
|
||||
/**
|
||||
* Stream context
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $context = null;
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* Adapter constructor, currently empty. Config is set using setOptions()
|
||||
@@ -105,7 +105,7 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
if ($options instanceof Traversable) {
|
||||
$options = ArrayUtils::iteratorToArray($options);
|
||||
}
|
||||
if (!is_array($options)) {
|
||||
if (! is_array($options)) {
|
||||
throw new AdapterException\InvalidArgumentException(
|
||||
'Array or Zend\Config object expected, got ' . gettype($options)
|
||||
);
|
||||
@@ -148,9 +148,10 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
$this->context = stream_context_create($context);
|
||||
} else {
|
||||
// Invalid parameter
|
||||
throw new AdapterException\InvalidArgumentException(
|
||||
"Expecting either a stream context resource or array, got " . gettype($context)
|
||||
);
|
||||
throw new AdapterException\InvalidArgumentException(sprintf(
|
||||
'Expecting either a stream context resource or array, got %s',
|
||||
gettype($context)
|
||||
));
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -194,45 +195,61 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
}
|
||||
|
||||
// Now, if we are not connected, connect
|
||||
if (!is_resource($this->socket) || ! $this->config['keepalive']) {
|
||||
if (! is_resource($this->socket) || ! $this->config['keepalive']) {
|
||||
$context = $this->getStreamContext();
|
||||
|
||||
if ($secure || $this->config['sslusecontext']) {
|
||||
if ($this->config['sslverifypeer'] !== null) {
|
||||
if (!stream_context_set_option($context, 'ssl', 'verify_peer', $this->config['sslverifypeer'])) {
|
||||
if (! stream_context_set_option($context, 'ssl', 'verify_peer', $this->config['sslverifypeer'])) {
|
||||
throw new AdapterException\RuntimeException('Unable to set sslverifypeer option');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->config['sslcafile']) {
|
||||
if (!stream_context_set_option($context, 'ssl', 'cafile', $this->config['sslcafile'])) {
|
||||
if (! stream_context_set_option($context, 'ssl', 'cafile', $this->config['sslcafile'])) {
|
||||
throw new AdapterException\RuntimeException('Unable to set sslcafile option');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->config['sslcapath']) {
|
||||
if (!stream_context_set_option($context, 'ssl', 'capath', $this->config['sslcapath'])) {
|
||||
if (! stream_context_set_option($context, 'ssl', 'capath', $this->config['sslcapath'])) {
|
||||
throw new AdapterException\RuntimeException('Unable to set sslcapath option');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->config['sslallowselfsigned'] !== null) {
|
||||
if (!stream_context_set_option($context, 'ssl', 'allow_self_signed', $this->config['sslallowselfsigned'])) {
|
||||
if (! stream_context_set_option(
|
||||
$context,
|
||||
'ssl',
|
||||
'allow_self_signed',
|
||||
$this->config['sslallowselfsigned']
|
||||
)) {
|
||||
throw new AdapterException\RuntimeException('Unable to set sslallowselfsigned option');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->config['sslcert'] !== null) {
|
||||
if (!stream_context_set_option($context, 'ssl', 'local_cert', $this->config['sslcert'])) {
|
||||
if (! stream_context_set_option($context, 'ssl', 'local_cert', $this->config['sslcert'])) {
|
||||
throw new AdapterException\RuntimeException('Unable to set sslcert option');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->config['sslpassphrase'] !== null) {
|
||||
if (!stream_context_set_option($context, 'ssl', 'passphrase', $this->config['sslpassphrase'])) {
|
||||
if (! stream_context_set_option($context, 'ssl', 'passphrase', $this->config['sslpassphrase'])) {
|
||||
throw new AdapterException\RuntimeException('Unable to set sslpassphrase option');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->config['sslverifypeername'] !== null) {
|
||||
if (! stream_context_set_option(
|
||||
$context,
|
||||
'ssl',
|
||||
'verify_peer_name',
|
||||
$this->config['sslverifypeername']
|
||||
)) {
|
||||
throw new AdapterException\RuntimeException('Unable to set sslverifypeername option');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$flags = STREAM_CLIENT_CONNECT;
|
||||
@@ -240,18 +257,23 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
$flags |= STREAM_CLIENT_PERSISTENT;
|
||||
}
|
||||
|
||||
if (isset($this->config['connecttimeout'])) {
|
||||
$connectTimeout = $this->config['connecttimeout'];
|
||||
} else {
|
||||
$connectTimeout = $this->config['timeout'];
|
||||
}
|
||||
ErrorHandler::start();
|
||||
$this->socket = stream_socket_client(
|
||||
$host . ':' . $port,
|
||||
$errno,
|
||||
$errstr,
|
||||
(int) $this->config['timeout'],
|
||||
(int) $connectTimeout,
|
||||
$flags,
|
||||
$context
|
||||
);
|
||||
$error = ErrorHandler::stop();
|
||||
|
||||
if (!$this->socket) {
|
||||
if (! $this->socket) {
|
||||
$this->close();
|
||||
throw new AdapterException\RuntimeException(
|
||||
sprintf(
|
||||
@@ -266,7 +288,7 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
}
|
||||
|
||||
// Set the stream timeout
|
||||
if (!stream_set_timeout($this->socket, (int) $this->config['timeout'])) {
|
||||
if (! stream_set_timeout($this->socket, (int) $this->config['timeout'])) {
|
||||
throw new AdapterException\RuntimeException('Unable to set the connection timeout');
|
||||
}
|
||||
|
||||
@@ -280,12 +302,12 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
ErrorHandler::start();
|
||||
$test = stream_socket_enable_crypto($this->socket, true, $sslCryptoMethod);
|
||||
$error = ErrorHandler::stop();
|
||||
if (!$test || $error) {
|
||||
if (! $test || $error) {
|
||||
// Error handling is kind of difficult when it comes to SSL
|
||||
$errorString = '';
|
||||
if (extension_loaded('openssl')) {
|
||||
while (($sslError = openssl_error_string()) != false) {
|
||||
$errorString .= "; SSL error: $sslError";
|
||||
$errorString .= sprintf('; SSL error: %s', $sslError);
|
||||
}
|
||||
}
|
||||
$this->close();
|
||||
@@ -293,16 +315,18 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
if ((! $errorString) && $this->config['sslverifypeer']) {
|
||||
// There's good chance our error is due to sslcapath not being properly set
|
||||
if (! ($this->config['sslcafile'] || $this->config['sslcapath'])) {
|
||||
$errorString = 'make sure the "sslcafile" or "sslcapath" option are properly set for the environment.';
|
||||
} elseif ($this->config['sslcafile'] && !is_file($this->config['sslcafile'])) {
|
||||
$errorString = 'make sure the "sslcafile" or "sslcapath" option are properly set for the '
|
||||
. 'environment.';
|
||||
} elseif ($this->config['sslcafile'] && ! is_file($this->config['sslcafile'])) {
|
||||
$errorString = 'make sure the "sslcafile" option points to a valid SSL certificate file';
|
||||
} elseif ($this->config['sslcapath'] && !is_dir($this->config['sslcapath'])) {
|
||||
$errorString = 'make sure the "sslcapath" option points to a valid SSL certificate directory';
|
||||
} elseif ($this->config['sslcapath'] && ! is_dir($this->config['sslcapath'])) {
|
||||
$errorString = 'make sure the "sslcapath" option points to a valid SSL certificate '
|
||||
. 'directory';
|
||||
}
|
||||
}
|
||||
|
||||
if ($errorString) {
|
||||
$errorString = ": $errorString";
|
||||
$errorString = sprintf(': %s', $errorString);
|
||||
}
|
||||
|
||||
throw new AdapterException\RuntimeException(sprintf(
|
||||
@@ -312,7 +336,7 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
), 0, $error);
|
||||
}
|
||||
|
||||
$host = $this->config['ssltransport'] . "://" . $host;
|
||||
$host = $this->config['ssltransport'] . '://' . $host;
|
||||
} else {
|
||||
$host = 'tcp://' . $host;
|
||||
}
|
||||
@@ -355,12 +379,12 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
if ($uri->getQuery()) {
|
||||
$path .= '?' . $uri->getQuery();
|
||||
}
|
||||
$request = "{$method} {$path} HTTP/{$httpVer}\r\n";
|
||||
$request = $method . ' ' . $path . ' HTTP/' . $httpVer . "\r\n";
|
||||
foreach ($headers as $k => $v) {
|
||||
if (is_string($k)) {
|
||||
$v = ucfirst($k) . ": $v";
|
||||
$v = ucfirst($k) . ': ' . $v;
|
||||
}
|
||||
$request .= "$v\r\n";
|
||||
$request .= $v . "\r\n";
|
||||
}
|
||||
|
||||
if (is_resource($body)) {
|
||||
@@ -411,7 +435,7 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
|
||||
$this->_checkSocketReadTimeout();
|
||||
|
||||
$responseObj= Response::fromString($response);
|
||||
$responseObj = Response::fromString($response);
|
||||
|
||||
$statusCode = $responseObj->getStatusCode();
|
||||
|
||||
@@ -427,8 +451,10 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
* Responses to HEAD requests and 204 or 304 responses are not expected
|
||||
* to have a body - stop reading here
|
||||
*/
|
||||
if ($statusCode == 304 || $statusCode == 204 ||
|
||||
$this->method == \Zend\Http\Request::METHOD_HEAD) {
|
||||
if ($statusCode == 304
|
||||
|| $statusCode == 204
|
||||
|| $this->method == Request::METHOD_HEAD
|
||||
) {
|
||||
// Close the connection if requested to do so by the server
|
||||
$connection = $headers->get('connection');
|
||||
if ($connection && $connection->getFieldValue() == 'close') {
|
||||
@@ -452,8 +478,10 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
$chunksize = trim($line);
|
||||
if (! ctype_xdigit($chunksize)) {
|
||||
$this->close();
|
||||
throw new AdapterException\RuntimeException('Invalid chunk size "' .
|
||||
$chunksize . '" unable to read chunked body');
|
||||
throw new AdapterException\RuntimeException(sprintf(
|
||||
'Invalid chunk size "%s" unable to read chunked body',
|
||||
$chunksize
|
||||
));
|
||||
}
|
||||
|
||||
// Convert the hexadecimal value to plain integer
|
||||
@@ -488,14 +516,16 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
ErrorHandler::stop();
|
||||
$this->_checkSocketReadTimeout();
|
||||
|
||||
if (!$this->outStream) {
|
||||
if (! $this->outStream) {
|
||||
$response .= $chunk;
|
||||
}
|
||||
} while ($chunksize > 0);
|
||||
} else {
|
||||
$this->close();
|
||||
throw new AdapterException\RuntimeException('Cannot handle "' .
|
||||
$transferEncoding->getFieldValue() . '" transfer encoding');
|
||||
throw new AdapterException\RuntimeException(sprintf(
|
||||
'Cannot handle "%s" transfer encoding',
|
||||
$transferEncoding->getFieldValue()
|
||||
));
|
||||
}
|
||||
|
||||
// We automatically decode chunked-messages when writing to a stream
|
||||
@@ -590,15 +620,17 @@ class Socket implements HttpAdapter, StreamInterface
|
||||
*
|
||||
* @throws AdapterException\TimeoutException with READ_TIMEOUT code
|
||||
*/
|
||||
// @codingStandardsIgnoreStart
|
||||
protected function _checkSocketReadTimeout()
|
||||
{
|
||||
// @codingStandardsIgnoreEnd
|
||||
if ($this->socket) {
|
||||
$info = stream_get_meta_data($this->socket);
|
||||
$timedout = $info['timed_out'];
|
||||
if ($timedout) {
|
||||
$this->close();
|
||||
throw new AdapterException\TimeoutException(
|
||||
"Read timed out after {$this->config['timeout']} seconds",
|
||||
sprintf('Read timed out after %d seconds', $this->config['timeout']),
|
||||
AdapterException\TimeoutException::READ_TIMEOUT
|
||||
);
|
||||
}
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Adapter;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Adapter;
|
||||
@@ -132,12 +130,12 @@ class Test implements AdapterInterface
|
||||
if ($uri->getQuery()) {
|
||||
$path .= '?' . $uri->getQuery();
|
||||
}
|
||||
$request = "{$method} {$path} HTTP/{$httpVer}\r\n";
|
||||
$request = $method . ' ' . $path . ' HTTP/' . $httpVer . "\r\n";
|
||||
foreach ($headers as $k => $v) {
|
||||
if (is_string($k)) {
|
||||
$v = ucfirst($k) . ": $v";
|
||||
$v = ucfirst($k) . ': ' . $v;
|
||||
}
|
||||
$request .= "$v\r\n";
|
||||
$request .= $v . "\r\n";
|
||||
}
|
||||
|
||||
// Add the request body
|
||||
@@ -209,7 +207,8 @@ class Test implements AdapterInterface
|
||||
{
|
||||
if ($index < 0 || $index >= count($this->responses)) {
|
||||
throw new Exception\OutOfRangeException(
|
||||
'Index out of range of response buffer size');
|
||||
'Index out of range of response buffer size'
|
||||
);
|
||||
}
|
||||
$this->responseIndex = $index;
|
||||
}
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Exception;
|
||||
|
@@ -1,18 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Exception;
|
||||
|
||||
use Zend\Http\Exception;
|
||||
|
||||
/**
|
||||
*/
|
||||
class InvalidArgumentException extends Exception\InvalidArgumentException implements
|
||||
ExceptionInterface
|
||||
{
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Exception;
|
||||
|
@@ -1,18 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Client\Exception;
|
||||
|
||||
use Zend\Http\Exception;
|
||||
|
||||
/**
|
||||
*/
|
||||
class RuntimeException extends Exception\RuntimeException implements
|
||||
ExceptionInterface
|
||||
{
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http;
|
||||
@@ -27,7 +25,7 @@ class ClientStatic
|
||||
*/
|
||||
protected static function getStaticClient($options = null)
|
||||
{
|
||||
if (!isset(static::$client) || $options !== null) {
|
||||
if (! isset(static::$client) || $options !== null) {
|
||||
static::$client = new Client(null, $options);
|
||||
}
|
||||
return static::$client;
|
||||
@@ -49,19 +47,19 @@ class ClientStatic
|
||||
return false;
|
||||
}
|
||||
|
||||
$request= new Request();
|
||||
$request = new Request();
|
||||
$request->setUri($url);
|
||||
$request->setMethod(Request::METHOD_GET);
|
||||
|
||||
if (!empty($query) && is_array($query)) {
|
||||
if (! empty($query) && is_array($query)) {
|
||||
$request->getQuery()->fromArray($query);
|
||||
}
|
||||
|
||||
if (!empty($headers) && is_array($headers)) {
|
||||
if (! empty($headers) && is_array($headers)) {
|
||||
$request->getHeaders()->addHeaders($headers);
|
||||
}
|
||||
|
||||
if (!empty($body)) {
|
||||
if (! empty($body)) {
|
||||
$request->setContent($body);
|
||||
}
|
||||
|
||||
@@ -85,25 +83,25 @@ class ClientStatic
|
||||
return false;
|
||||
}
|
||||
|
||||
$request= new Request();
|
||||
$request = new Request();
|
||||
$request->setUri($url);
|
||||
$request->setMethod(Request::METHOD_POST);
|
||||
|
||||
if (!empty($params) && is_array($params)) {
|
||||
if (! empty($params) && is_array($params)) {
|
||||
$request->getPost()->fromArray($params);
|
||||
} else {
|
||||
throw new Exception\InvalidArgumentException('The array of post parameters is empty');
|
||||
}
|
||||
|
||||
if (!isset($headers['Content-Type'])) {
|
||||
if (! isset($headers['Content-Type'])) {
|
||||
$headers['Content-Type'] = Client::ENC_URLENCODED;
|
||||
}
|
||||
|
||||
if (!empty($headers) && is_array($headers)) {
|
||||
if (! empty($headers) && is_array($headers)) {
|
||||
$request->getHeaders()->addHeaders($headers);
|
||||
}
|
||||
|
||||
if (!empty($body)) {
|
||||
if (! empty($body)) {
|
||||
$request->setContent($body);
|
||||
}
|
||||
|
||||
|
34
vendor/zendframework/zend-http/src/Cookies.php
vendored
34
vendor/zendframework/zend-http/src/Cookies.php
vendored
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http;
|
||||
@@ -35,19 +33,16 @@ class Cookies extends Headers
|
||||
{
|
||||
/**
|
||||
* Return cookie(s) as a Zend\Http\Cookie object
|
||||
*
|
||||
*/
|
||||
const COOKIE_OBJECT = 0;
|
||||
|
||||
/**
|
||||
* Return cookie(s) as a string (suitable for sending in an HTTP request)
|
||||
*
|
||||
*/
|
||||
const COOKIE_STRING_ARRAY = 1;
|
||||
|
||||
/**
|
||||
* Return all cookies as one long string (suitable for sending in an HTTP request)
|
||||
*
|
||||
*/
|
||||
const COOKIE_STRING_CONCAT = 2;
|
||||
|
||||
@@ -66,7 +61,7 @@ class Cookies extends Headers
|
||||
/**
|
||||
* @var \Zend\Http\Headers
|
||||
*/
|
||||
protected $headers = null;
|
||||
protected $headers;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
@@ -104,10 +99,10 @@ class Cookies extends Headers
|
||||
if ($cookie instanceof SetCookie) {
|
||||
$domain = $cookie->getDomain();
|
||||
$path = $cookie->getPath();
|
||||
if (!isset($this->cookies[$domain])) {
|
||||
if (! isset($this->cookies[$domain])) {
|
||||
$this->cookies[$domain] = [];
|
||||
}
|
||||
if (!isset($this->cookies[$domain][$path])) {
|
||||
if (! isset($this->cookies[$domain][$path])) {
|
||||
$this->cookies[$domain][$path] = [];
|
||||
}
|
||||
$this->cookies[$domain][$path][$cookie->getName()] = $cookie;
|
||||
@@ -168,8 +163,8 @@ class Cookies extends Headers
|
||||
) {
|
||||
if (is_string($uri)) {
|
||||
$uri = Uri\UriFactory::factory($uri, 'http');
|
||||
} elseif (!$uri instanceof Uri\Uri) {
|
||||
throw new Exception\InvalidArgumentException("Invalid URI string or object passed");
|
||||
} elseif (! $uri instanceof Uri\Uri) {
|
||||
throw new Exception\InvalidArgumentException('Invalid URI string or object passed');
|
||||
}
|
||||
|
||||
$host = $uri->getHost();
|
||||
@@ -208,7 +203,7 @@ class Cookies extends Headers
|
||||
{
|
||||
if (is_string($uri)) {
|
||||
$uri = Uri\UriFactory::factory($uri, 'http');
|
||||
} elseif (!$uri instanceof Uri\Uri) {
|
||||
} elseif (! $uri instanceof Uri\Uri) {
|
||||
throw new Exception\InvalidArgumentException('Invalid URI specified');
|
||||
}
|
||||
|
||||
@@ -237,7 +232,10 @@ class Cookies extends Headers
|
||||
return $cookie->__toString();
|
||||
|
||||
default:
|
||||
throw new Exception\InvalidArgumentException("Invalid value passed for \$retAs: {$retAs}");
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Invalid value passed for $retAs: %s',
|
||||
$retAs
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,8 +250,10 @@ class Cookies extends Headers
|
||||
* @param int $retAs What value to return
|
||||
* @return array|string
|
||||
*/
|
||||
// @codingStandardsIgnoreStart
|
||||
protected function _flattenCookiesArray($ptr, $retAs = self::COOKIE_OBJECT)
|
||||
{
|
||||
// @codingStandardsIgnoreEnd
|
||||
if (is_array($ptr)) {
|
||||
$ret = ($retAs == self::COOKIE_STRING_CONCAT ? '' : []);
|
||||
foreach ($ptr as $item) {
|
||||
@@ -287,8 +287,10 @@ class Cookies extends Headers
|
||||
* @param string $domain
|
||||
* @return array
|
||||
*/
|
||||
// @codingStandardsIgnoreStart
|
||||
protected function _matchDomain($domain)
|
||||
{
|
||||
// @codingStandardsIgnoreEnd
|
||||
$ret = [];
|
||||
|
||||
foreach (array_keys($this->cookies) as $cdom) {
|
||||
@@ -307,8 +309,10 @@ class Cookies extends Headers
|
||||
* @param string $path
|
||||
* @return array
|
||||
*/
|
||||
// @codingStandardsIgnoreStart
|
||||
protected function _matchPath($domains, $path)
|
||||
{
|
||||
// @codingStandardsIgnoreEnd
|
||||
$ret = [];
|
||||
|
||||
foreach ($domains as $dom => $pathsArray) {
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Exception;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Exception;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Exception;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Exception;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -39,7 +37,6 @@ use stdClass;
|
||||
abstract class AbstractAccept implements HeaderInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var stdClass[]
|
||||
*/
|
||||
protected $fieldValueParts = [];
|
||||
@@ -99,8 +96,8 @@ abstract class AbstractAccept implements HeaderInterface
|
||||
public function getFieldValuePartsFromHeaderLine($headerLine)
|
||||
{
|
||||
// process multiple accept values, they may be between quotes
|
||||
if (!preg_match_all('/(?:[^,"]|"(?:[^\\\"]|\\\.)*")+/', $headerLine, $values)
|
||||
|| !isset($values[0])
|
||||
if (! preg_match_all('/(?:[^,"]|"(?:[^\\\"]|\\\.)*")+/', $headerLine, $values)
|
||||
|| ! isset($values[0])
|
||||
) {
|
||||
throw new Exception\InvalidArgumentException(
|
||||
'Invalid header line for ' . $this->getFieldName() . ' header string'
|
||||
@@ -139,14 +136,14 @@ abstract class AbstractAccept implements HeaderInterface
|
||||
$subtype = '*';
|
||||
|
||||
return (object) [
|
||||
'typeString' => trim($fieldValuePart),
|
||||
'type' => $type,
|
||||
'subtype' => $subtype,
|
||||
'subtypeRaw' => $subtypeWhole,
|
||||
'format' => $format,
|
||||
'priority' => isset($params['q']) ? $params['q'] : 1,
|
||||
'params' => $params,
|
||||
'raw' => trim($raw)
|
||||
'typeString' => trim($fieldValuePart),
|
||||
'type' => $type,
|
||||
'subtype' => $subtype,
|
||||
'subtypeRaw' => $subtypeWhole,
|
||||
'format' => $format,
|
||||
'priority' => isset($params['q']) ? $params['q'] : 1,
|
||||
'params' => $params,
|
||||
'raw' => trim($raw),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -219,8 +216,7 @@ abstract class AbstractAccept implements HeaderInterface
|
||||
*/
|
||||
protected function assembleAcceptParam(&$value, $key)
|
||||
{
|
||||
$separators = ['(', ')', '<', '>', '@', ',', ';', ':',
|
||||
'/', '[', ']', '?', '=', '{', '}', ' ', "\t"];
|
||||
$separators = ['(', ')', '<', '>', '@', ',', ';', ':', '/', '[', ']', '?', '=', '{', '}', ' ', "\t"];
|
||||
|
||||
$escaped = preg_replace_callback(
|
||||
'/[[:cntrl:]"\\\\]/', // escape cntrl, ", \
|
||||
@@ -230,7 +226,7 @@ abstract class AbstractAccept implements HeaderInterface
|
||||
$value
|
||||
);
|
||||
|
||||
if ($escaped == $value && !array_intersect(str_split($value), $separators)) {
|
||||
if ($escaped == $value && ! array_intersect(str_split($value), $separators)) {
|
||||
$value = $key . ($value ? '=' . $value : '');
|
||||
} else {
|
||||
$value = $key . ($value ? '="' . $escaped . '"' : '');
|
||||
@@ -250,7 +246,7 @@ abstract class AbstractAccept implements HeaderInterface
|
||||
*/
|
||||
protected function addType($type, $priority = 1, array $params = [])
|
||||
{
|
||||
if (!preg_match($this->regexAddType, $type)) {
|
||||
if (! preg_match($this->regexAddType, $type)) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'%s expects a valid type; received "%s"',
|
||||
__METHOD__,
|
||||
@@ -258,7 +254,7 @@ abstract class AbstractAccept implements HeaderInterface
|
||||
));
|
||||
}
|
||||
|
||||
if (!is_int($priority) && !is_float($priority) && !is_numeric($priority)
|
||||
if (! is_int($priority) && ! is_float($priority) && ! is_numeric($priority)
|
||||
|| $priority > 1 || $priority < 0
|
||||
) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
@@ -315,8 +311,8 @@ abstract class AbstractAccept implements HeaderInterface
|
||||
}
|
||||
|
||||
if ($left->type == $right->type) {
|
||||
if (($left->subtype == $right->subtype || ($right->subtype == '*' || $left->subtype == '*')) &&
|
||||
($left->format == $right->format || $right->format == '*' || $left->format == '*')
|
||||
if (($left->subtype == $right->subtype || ($right->subtype == '*' || $left->subtype == '*'))
|
||||
&& ($left->format == $right->format || $right->format == '*' || $left->format == '*')
|
||||
) {
|
||||
if ($this->matchAcceptParams($left, $right)) {
|
||||
$left->setMatchedAgainst($right);
|
||||
@@ -349,10 +345,9 @@ abstract class AbstractAccept implements HeaderInterface
|
||||
$pieces
|
||||
);
|
||||
|
||||
if (count($pieces) == 3 &&
|
||||
(version_compare($pieces[1], $match1->params[$key], '<=') xor
|
||||
version_compare($pieces[2], $match1->params[$key], '>=')
|
||||
)
|
||||
if (count($pieces) == 3
|
||||
&& (version_compare($pieces[1], $match1->params[$key], '<=')
|
||||
xor version_compare($pieces[2], $match1->params[$key], '>='))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
@@ -366,7 +361,7 @@ abstract class AbstractAccept implements HeaderInterface
|
||||
}
|
||||
}
|
||||
|
||||
if (!$good) {
|
||||
if (! $good) {
|
||||
return false;
|
||||
}
|
||||
} elseif ($match1->params[$key] != $value) {
|
||||
@@ -411,7 +406,8 @@ abstract class AbstractAccept implements HeaderInterface
|
||||
*/
|
||||
protected function sortFieldValueParts()
|
||||
{
|
||||
$sort = function ($a, $b) { // If A has higher precedence than B, return -1.
|
||||
$sort = function ($a, $b) {
|
||||
// If A has higher precedence than B, return -1.
|
||||
if ($a->priority > $b->priority) {
|
||||
return -1;
|
||||
} elseif ($a->priority < $b->priority) {
|
||||
@@ -434,7 +430,7 @@ abstract class AbstractAccept implements HeaderInterface
|
||||
return 1;
|
||||
}
|
||||
|
||||
//@todo count number of dots in case of type==application in subtype
|
||||
// @todo count number of dots in case of type==application in subtype
|
||||
|
||||
// So far they're still the same. Longest string length may be more specific
|
||||
if (strlen($a->raw) == strlen($b->raw)) {
|
||||
@@ -452,7 +448,7 @@ abstract class AbstractAccept implements HeaderInterface
|
||||
*/
|
||||
public function getPrioritized()
|
||||
{
|
||||
if (!$this->sorted) {
|
||||
if (! $this->sorted) {
|
||||
$this->sortFieldValueParts();
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -41,7 +39,7 @@ abstract class AbstractDate implements HeaderInterface
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
protected $date = null;
|
||||
protected $date;
|
||||
|
||||
/**
|
||||
* Date output format
|
||||
@@ -134,10 +132,11 @@ abstract class AbstractDate implements HeaderInterface
|
||||
*/
|
||||
public static function setDateFormat($format)
|
||||
{
|
||||
if (!isset(static::$dateFormats[$format])) {
|
||||
throw new Exception\InvalidArgumentException(
|
||||
"No constant defined for provided date format: {$format}"
|
||||
);
|
||||
if (! isset(static::$dateFormats[$format])) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'No constant defined for provided date format: %s',
|
||||
$format
|
||||
));
|
||||
}
|
||||
|
||||
static::$dateFormat = static::$dateFormats[$format];
|
||||
@@ -172,7 +171,7 @@ abstract class AbstractDate implements HeaderInterface
|
||||
$e
|
||||
);
|
||||
}
|
||||
} elseif (!($date instanceof DateTime)) {
|
||||
} elseif (! ($date instanceof DateTime)) {
|
||||
throw new Exception\InvalidArgumentException('Date must be an instance of \DateTime or a string');
|
||||
}
|
||||
|
||||
@@ -226,7 +225,7 @@ abstract class AbstractDate implements HeaderInterface
|
||||
$e
|
||||
);
|
||||
}
|
||||
} elseif (!($date instanceof DateTime)) {
|
||||
} elseif (! ($date instanceof DateTime)) {
|
||||
throw new Exception\InvalidArgumentException('Date must be an instance of \DateTime or a string');
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -31,7 +29,7 @@ abstract class AbstractLocation implements HeaderInterface
|
||||
*
|
||||
* @var UriInterface
|
||||
*/
|
||||
protected $uri = null;
|
||||
protected $uri;
|
||||
|
||||
/**
|
||||
* Create location-based header from string
|
||||
@@ -79,7 +77,7 @@ abstract class AbstractLocation implements HeaderInterface
|
||||
$e
|
||||
);
|
||||
}
|
||||
} elseif (!($uri instanceof UriInterface)) {
|
||||
} elseif (! ($uri instanceof UriInterface)) {
|
||||
throw new Exception\InvalidArgumentException('URI must be an instance of Zend\Uri\Http or a string');
|
||||
}
|
||||
$this->uri = $uri;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header\Accept\FieldValuePart;
|
||||
@@ -12,7 +10,6 @@ namespace Zend\Http\Header\Accept\FieldValuePart;
|
||||
/**
|
||||
* Field Value Part
|
||||
*
|
||||
*
|
||||
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
|
||||
*/
|
||||
abstract class AbstractFieldValuePart
|
||||
@@ -30,7 +27,6 @@ abstract class AbstractFieldValuePart
|
||||
protected $matchedAgainst;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param object $internalValues
|
||||
*/
|
||||
public function __construct($internalValues)
|
||||
@@ -61,7 +57,6 @@ abstract class AbstractFieldValuePart
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
protected function getInternalValues()
|
||||
@@ -102,8 +97,7 @@ abstract class AbstractFieldValuePart
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mixed
|
||||
* @param mixed $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header\Accept\FieldValuePart;
|
||||
@@ -12,7 +10,6 @@ namespace Zend\Http\Header\Accept\FieldValuePart;
|
||||
/**
|
||||
* Field Value Part
|
||||
*
|
||||
*
|
||||
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
|
||||
*/
|
||||
class AcceptFieldValuePart extends AbstractFieldValuePart
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header\Accept\FieldValuePart;
|
||||
@@ -12,13 +10,11 @@ namespace Zend\Http\Header\Accept\FieldValuePart;
|
||||
/**
|
||||
* Field Value Part
|
||||
*
|
||||
*
|
||||
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
|
||||
*/
|
||||
class CharsetFieldValuePart extends AbstractFieldValuePart
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCharset()
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header\Accept\FieldValuePart;
|
||||
@@ -12,13 +10,11 @@ namespace Zend\Http\Header\Accept\FieldValuePart;
|
||||
/**
|
||||
* Field Value Part
|
||||
*
|
||||
*
|
||||
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
|
||||
*/
|
||||
class EncodingFieldValuePart extends AbstractFieldValuePart
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding()
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header\Accept\FieldValuePart;
|
||||
@@ -12,7 +10,6 @@ namespace Zend\Http\Header\Accept\FieldValuePart;
|
||||
/**
|
||||
* Field Value Part
|
||||
*
|
||||
*
|
||||
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
|
||||
*/
|
||||
class LanguageFieldValuePart extends AbstractFieldValuePart
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -86,7 +84,7 @@ class AcceptLanguage extends AbstractAccept
|
||||
}
|
||||
|
||||
if (strpos($fieldValuePart, '-')) {
|
||||
$subtypeWhole = $format = $subtype = trim(substr($fieldValuePart, strpos($fieldValuePart, '-')+1));
|
||||
$subtypeWhole = $format = $subtype = trim(substr($fieldValuePart, strpos($fieldValuePart, '-') + 1));
|
||||
} else {
|
||||
$subtypeWhole = '';
|
||||
$format = '*';
|
||||
@@ -94,14 +92,14 @@ class AcceptLanguage extends AbstractAccept
|
||||
}
|
||||
|
||||
$aggregated = [
|
||||
'typeString' => trim($fieldValuePart),
|
||||
'type' => $type,
|
||||
'subtype' => $subtype,
|
||||
'subtypeRaw' => $subtypeWhole,
|
||||
'format' => $format,
|
||||
'priority' => isset($params['q']) ? $params['q'] : 1,
|
||||
'params' => $params,
|
||||
'raw' => trim($raw)
|
||||
'typeString' => trim($fieldValuePart),
|
||||
'type' => $type,
|
||||
'subtype' => $subtype,
|
||||
'subtypeRaw' => $subtypeWhole,
|
||||
'format' => $format,
|
||||
'priority' => isset($params['q']) ? $params['q'] : 1,
|
||||
'params' => $params,
|
||||
'raw' => trim($raw),
|
||||
];
|
||||
|
||||
return new FieldValuePart\LanguageFieldValuePart((object) $aggregated);
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -17,7 +15,7 @@ class AuthenticationInfo implements HeaderInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
public static function fromString($headerLine)
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -41,7 +39,7 @@ class CacheControl implements HeaderInterface
|
||||
// check to ensure proper header type for this factory
|
||||
if (strtolower($name) !== 'cache-control') {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Invalid header line for Cache-Control string: ""',
|
||||
'Invalid header line for Cache-Control string: "%s"',
|
||||
$name
|
||||
));
|
||||
}
|
||||
@@ -145,9 +143,9 @@ class CacheControl implements HeaderInterface
|
||||
$parts[] = $key;
|
||||
} else {
|
||||
if (preg_match('#[^a-zA-Z0-9._-]#', $value)) {
|
||||
$value = '"' . $value.'"';
|
||||
$value = '"' . $value . '"';
|
||||
}
|
||||
$parts[] = "$key=$value";
|
||||
$parts[] = $key . '=' . $value;
|
||||
}
|
||||
}
|
||||
return implode(', ', $parts);
|
||||
@@ -223,7 +221,6 @@ class CacheControl implements HeaderInterface
|
||||
|
||||
default:
|
||||
throw new Exception\InvalidArgumentException('expected SEPARATOR or END');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -27,7 +25,7 @@ class Connection implements HeaderInterface
|
||||
protected $value = self::CONNECTION_KEEP_ALIVE;
|
||||
|
||||
/**
|
||||
* @param $headerLine
|
||||
* @param string $headerLine
|
||||
* @return Connection
|
||||
* @throws Exception\InvalidArgumentException
|
||||
*/
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -17,7 +15,7 @@ class ContentDisposition implements HeaderInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
public static function fromString($headerLine)
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -73,6 +71,12 @@ class ContentSecurityPolicy implements HeaderInterface
|
||||
));
|
||||
}
|
||||
if (empty($sources)) {
|
||||
if ('report-uri' === $name) {
|
||||
if (isset($this->directives[$name])) {
|
||||
unset($this->directives[$name]);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
$this->directives[$name] = "'none'";
|
||||
return $this;
|
||||
}
|
||||
@@ -109,7 +113,7 @@ class ContentSecurityPolicy implements HeaderInterface
|
||||
$token = trim($token);
|
||||
if ($token) {
|
||||
list($directiveName, $directiveValue) = explode(' ', $token, 2);
|
||||
if (!isset($header->directives[$directiveName])) {
|
||||
if (! isset($header->directives[$directiveName])) {
|
||||
$header->setDirective($directiveName, [$directiveValue]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -50,15 +48,15 @@ class ContentType implements HeaderInterface
|
||||
));
|
||||
}
|
||||
|
||||
$parts = explode(';', $value);
|
||||
$mediaType = array_shift($parts);
|
||||
$header = new static($value, trim($mediaType));
|
||||
$parts = explode(';', $value);
|
||||
$mediaType = array_shift($parts);
|
||||
$header = new static($value, trim($mediaType));
|
||||
|
||||
if (count($parts) > 0) {
|
||||
$parameters = [];
|
||||
foreach ($parts as $parameter) {
|
||||
$parameter = trim($parameter);
|
||||
if (!preg_match('/^(?P<key>[^\s\=]+)\="?(?P<value>[^\s\"]*)"?$/', $parameter, $matches)) {
|
||||
if (! preg_match('/^(?P<key>[^\s\=]+)\="?(?P<value>[^\s\"]*)"?$/', $parameter, $matches)) {
|
||||
continue;
|
||||
}
|
||||
$parameters[$matches['key']] = $matches['value'];
|
||||
@@ -228,7 +226,7 @@ class ContentType implements HeaderInterface
|
||||
if (isset($this->parameters['charset'])) {
|
||||
return $this->parameters['charset'];
|
||||
}
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,7 +280,7 @@ class ContentType implements HeaderInterface
|
||||
*/
|
||||
protected function getMediaTypeObjectFromString($string)
|
||||
{
|
||||
if (!is_string($string)) {
|
||||
if (! is_string($string)) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Non-string mediatype "%s" provided',
|
||||
(is_object($string) ? get_class($string) : gettype($string))
|
||||
@@ -300,7 +298,7 @@ class ContentType implements HeaderInterface
|
||||
$type = array_shift($parts);
|
||||
$subtype = array_shift($parts);
|
||||
$format = $subtype;
|
||||
if (strstr($subtype, '+')) {
|
||||
if (false !== strpos($subtype, '+')) {
|
||||
$parts = explode('+', $subtype, 2);
|
||||
$subtype = array_shift($parts);
|
||||
$format = array_shift($parts);
|
||||
@@ -337,7 +335,7 @@ class ContentType implements HeaderInterface
|
||||
// Is the right side a partial wildcard?
|
||||
if ('*' == substr($right->subtype, -1)) {
|
||||
// validate partial-wildcard subtype
|
||||
if (!$this->validatePartialWildcard($right->subtype, $left->subtype)) {
|
||||
if (! $this->validatePartialWildcard($right->subtype, $left->subtype)) {
|
||||
return false;
|
||||
}
|
||||
// Finally, verify format is valid
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -97,13 +95,28 @@ class Cookie extends ArrayObject implements HeaderInterface
|
||||
{
|
||||
$nvPairs = [];
|
||||
|
||||
foreach ($this as $name => $value) {
|
||||
foreach ($this->flattenCookies($this) as $name => $value) {
|
||||
$nvPairs[] = $name . '=' . (($this->encodeValue) ? urlencode($value) : $value);
|
||||
}
|
||||
|
||||
return implode('; ', $nvPairs);
|
||||
}
|
||||
|
||||
protected function flattenCookies($data, $prefix = null)
|
||||
{
|
||||
$result = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$key = $prefix ? $prefix . '[' . $key . ']' : $key;
|
||||
if (is_array($value)) {
|
||||
$result = array_merge($result, $this->flattenCookies($value, $key));
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function toString()
|
||||
{
|
||||
return 'Cookie: ' . $this->getFieldValue();
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header\Exception;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header\Exception;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header\Exception;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header\Exception;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -25,4 +23,12 @@ class Expires extends AbstractDate
|
||||
{
|
||||
return 'Expires';
|
||||
}
|
||||
|
||||
public function setDate($date)
|
||||
{
|
||||
if ($date === '0' || $date === 0) {
|
||||
$date = date(DATE_W3C, 0); // Thu, 01 Jan 1970 00:00:00 GMT
|
||||
}
|
||||
return parent::setDate($date);
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,29 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
||||
/**
|
||||
* Content-Location Header
|
||||
*
|
||||
*/
|
||||
*/
|
||||
class GenericHeader implements HeaderInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldName = null;
|
||||
protected $fieldName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldValue = null;
|
||||
protected $fieldValue;
|
||||
|
||||
/**
|
||||
* Factory to generate a header object from a string
|
||||
@@ -88,7 +85,7 @@ class GenericHeader implements HeaderInterface
|
||||
*/
|
||||
public function setFieldName($fieldName)
|
||||
{
|
||||
if (!is_string($fieldName) || empty($fieldName)) {
|
||||
if (! is_string($fieldName) || empty($fieldName)) {
|
||||
throw new Exception\InvalidArgumentException('Header name must be a string');
|
||||
}
|
||||
|
||||
@@ -101,7 +98,7 @@ class GenericHeader implements HeaderInterface
|
||||
* tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." /
|
||||
* "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA
|
||||
*/
|
||||
if (!preg_match('/^[!#$%&\'*+\-\.\^_`|~0-9a-zA-Z]+$/', $fieldName)) {
|
||||
if (! preg_match('/^[!#$%&\'*+\-\.\^_`|~0-9a-zA-Z]+$/', $fieldName)) {
|
||||
throw new Exception\InvalidArgumentException(
|
||||
'Header name must be a valid RFC 7230 (section 3.2) field-name.'
|
||||
);
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -32,8 +30,10 @@ class GenericMultiHeader extends GenericHeader implements MultipleHeaderInterfac
|
||||
$name = $this->getFieldName();
|
||||
$values = [$this->getFieldValue()];
|
||||
foreach ($headers as $header) {
|
||||
if (!$header instanceof static) {
|
||||
throw new Exception\InvalidArgumentException('This method toStringMultipleHeaders was expecting an array of headers of the same type');
|
||||
if (! $header instanceof static) {
|
||||
throw new Exception\InvalidArgumentException(
|
||||
'This method toStringMultipleHeaders was expecting an array of headers of the same type'
|
||||
);
|
||||
}
|
||||
$values[] = $header->getFieldValue();
|
||||
}
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -17,7 +15,7 @@ class IfRange implements HeaderInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
public static function fromString($headerLine)
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -32,7 +30,7 @@ class Origin implements HeaderInterface
|
||||
}
|
||||
|
||||
$uri = UriFactory::factory($value);
|
||||
if (!$uri->isValid()) {
|
||||
if (! $uri->isValid()) {
|
||||
throw new Exception\InvalidArgumentException('Invalid header value for Origin key: "' . $name . '"');
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
@@ -65,7 +63,7 @@ class ProxyAuthenticate implements MultipleHeaderInterface
|
||||
{
|
||||
$strings = [$this->toString()];
|
||||
foreach ($headers as $header) {
|
||||
if (!$header instanceof ProxyAuthenticate) {
|
||||
if (! $header instanceof ProxyAuthenticate) {
|
||||
throw new Exception\RuntimeException(
|
||||
'The ProxyAuthenticate multiple header implementation can only accept'
|
||||
. ' an array of ProxyAuthenticate headers'
|
||||
|
@@ -1,10 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @see https://github.com/zendframework/zend-http for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Zend\Http\Header;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user