fsilva/http-message

This package is abandoned and no longer maintained. The author suggests using the slick/http package instead.

PSR Http Message compliant package

v0.2.0 2015-11-02 18:39 UTC

This package is auto-updated.

Last update: 2024-09-20 14:29:08 UTC


README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

PSR Http Message compliant package. The goal is to have an HTTP message abstraction that can be used to implement a request/response strategy application.

This package is compliant with PSR-2 code standards and PSR-4 autoload standards. It also applies the semantic version 2.0.0 specification.

Installing via Composer

The recommended way to install Fsilva\HttpMessage package is through Composer.

# Install Composer
curl -sS https://getcomposer.org/installer | php

You can add Fsilva\HttpMessage package as a dependency using the composer.phar CLI:

$ composer require fsilva/http-message

Alternatively, you can Fsilva\HttpMessage package as a dependency in your project’s existing composer.json file:

{
    "require": {
        "fsilva/http-message": "*"
    }
}  

Basic usage

Creating a very basic HTTP message

use Fsilva/HttpMessage/Message;
use Fsilva/HttpMessage/Stream/Buffer;

$message = new Message();
$body = new Buffer();
$body->write(json_encode(['some' => 'value']));

$request = $message->withProtocolVersion(Message::HTTP_1_1)
    ->withHeader('X-Requested-With', 'XMLHttpRequest')
    ->withHeader('User-Agent', 'PHP Request call')
    ->withBody($body)
    ->withoutHeader('pragma')
    ->withAddedHeader('X-Forwarded-For', ['client1', 'proxy1', 'proxy2']);
    
$strMessage = "GET / HTTP/". $request->getProtocolVersion();

foreach($request->getHeaders() as $name => $values) {
    $strMessage .= "\n{$name}: ". implode(', ', $values);
}

// $strMessage is now a very simple HTTP message.
$strMessage .= "\n\n". $request->getBody()->getContents();

Testing

$ vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.