├── .editorconfig ├── .gitignore ├── LICENSE ├── Migration.md ├── README.md ├── composer.json ├── composer.lock ├── src └── ResponseHeader.php └── tests └── index.php /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = tab 7 | trim_trailing_whitespace = true 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | indent_style = space 13 | indent_size = 4 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ 2 | .idea/ 3 | 4 | # Composer 5 | vendor/ 6 | composer.phar 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) delight.im (https://www.delight.im/) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Migration.md: -------------------------------------------------------------------------------- 1 | # Migration 2 | 3 | ## General 4 | 5 | Update your version of this library using Composer and its `composer update` or `composer require` commands [[?]](https://github.com/delight-im/Knowledge/blob/master/Composer%20(PHP).md#how-do-i-update-libraries-or-modules-within-my-application). 6 | 7 | ## From `v1.x.x` to `v2.x.x` 8 | 9 | * The license has been changed from the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) to the [MIT License](https://opensource.org/licenses/MIT). 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP-HTTP 2 | 3 | Hypertext Transfer Protocol (HTTP) utilities for PHP 4 | 5 | ## Requirements 6 | 7 | * PHP 5.3.0+ 8 | 9 | ## Installation 10 | 11 | 1. Include the library via Composer [[?]](https://github.com/delight-im/Knowledge/blob/master/Composer%20(PHP).md): 12 | 13 | ``` 14 | $ composer require delight-im/http 15 | ``` 16 | 17 | 1. Include the Composer autoloader: 18 | 19 | ```php 20 | require __DIR__ . '/vendor/autoload.php'; 21 | ``` 22 | 23 | ## Usage 24 | 25 | ### Response headers 26 | 27 | * Retrieving a header (with optional value prefix) 28 | 29 | ```php 30 | $header = \Delight\Http\ResponseHeader::get('Content-Type'); 31 | // or 32 | $header = \Delight\Http\ResponseHeader::get('Content-Type', 'text/'); 33 | ``` 34 | 35 | * Setting a header (overwriting other headers with the same name) 36 | 37 | ```php 38 | \Delight\Http\ResponseHeader::set('X-Frame-Options', 'sameorigin'); 39 | ``` 40 | 41 | * Adding a header (preserving other headers with the same name) 42 | 43 | ```php 44 | \Delight\Http\ResponseHeader::add('Vary', 'User-Agent'); 45 | ``` 46 | 47 | * Removing a header (with optional value prefix) 48 | 49 | ```php 50 | $success = \Delight\Http\ResponseHeader::remove('X-Powered-By'); 51 | // or 52 | $success = \Delight\Http\ResponseHeader::remove('X-Powered-By', 'PHP'); 53 | ``` 54 | 55 | * Retrieving and removing a header at once (with optional value prefix) 56 | 57 | ```php 58 | $header = \Delight\Http\ResponseHeader::take('Set-Cookie'); 59 | // or 60 | $header = \Delight\Http\ResponseHeader::take('Set-Cookie', 'mysession='); 61 | ``` 62 | 63 | ## Contributing 64 | 65 | All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed. 66 | 67 | ## License 68 | 69 | This project is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT). 70 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "delight-im/http", 3 | "description": "Hypertext Transfer Protocol (HTTP) utilities for PHP", 4 | "require": { 5 | "php": ">=5.3.0" 6 | }, 7 | "type": "library", 8 | "keywords": [ "http", "https", "headers" ], 9 | "homepage": "https://github.com/delight-im/PHP-HTTP", 10 | "license": "MIT", 11 | "autoload": { 12 | "psr-4": { 13 | "Delight\\Http\\": "src/" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "33b28670c4a351b72361eb5eea147fac", 8 | "content-hash": "a875b5a43edd7d3ea439b781aca1606f", 9 | "packages": [], 10 | "packages-dev": [], 11 | "aliases": [], 12 | "minimum-stability": "stable", 13 | "stability-flags": [], 14 | "prefer-stable": false, 15 | "prefer-lowest": false, 16 | "platform": { 17 | "php": ">=5.3.0" 18 | }, 19 | "platform-dev": [] 20 | } 21 | -------------------------------------------------------------------------------- /src/ResponseHeader.php: -------------------------------------------------------------------------------- 1 |