PHPackages                             crysalead/net - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. crysalead/net

ActiveLibrary

crysalead/net
=============

Net - Network Message implementation

020.4k↓26.9%4PHP

Since Oct 22Pushed 1y ago2 watchersCompare

[ Source](https://github.com/crysalead/net)[ Packagist](https://packagist.org/packages/crysalead/net)[ RSS](/packages/crysalead-net/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (4)

Net - Network Message Library
=============================

[](#net---network-message-library)

[![Build Status](https://camo.githubusercontent.com/19e2865304026e8cd4fa67ecd1de992c1a28146c8f141d39366824f87c73ed24/68747470733a2f2f7472617669732d63692e636f6d2f63727973616c6561642f6e65742e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/crysalead/net)[![Code Coverage](https://camo.githubusercontent.com/f7aeb9fdb409e7e188d5472b9dc0eaa7ce955cba349d8a97140f3c94896f5c70/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f63727973616c6561642f6e65742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/crysalead/net/)

This library is a Network Message implementation in PHP. The library provides some PSR-7 compatible accessors and can be used with any PSR-7 compatible transport layer library.

Installation
------------

[](#installation)

```
composer require crysalead/net
```

API
---

[](#api)

### The HTTP Request class

[](#the-http-request-class)

```
use Lead\Net\Http\Request;

$request = new Request([
    'method'   => 'POST',
    'scheme'   => 'http',
    'version'  => '1.1',
    'host'     => 'www.domain.com',
    'port'     => 8080,
    'username' => 'username',
    'password' => 'password',
    'path'     => '/index.php',
    'query'    => ['foo' => 'bar'],
    'fragment' => '#quz',
    'type'     => 'application/json',
    'data'     => '['foo' => 'bar']'
]);

// Getters
$request->method();   // POST
$request->scheme();   // http
$request->version();  // 1.1
$request->protocol(); // HTTP/1.1
$request->host();     // www.domain.com:8080
$request->hostname(); // www.domain.com
$request->port();     // 80
$request->username(); // username
$request->password(); // password
$request->query();    // ['foo' => 'bar']
$request->fragment(); // '#quz'
$request->url();      // http://www.domain.com:8080/index.php
$request->type();     // application/json
$request->encoding(); //
$request->get();      // ['foo' => 'bar']
$request->body();     // '{"foo":"bar"}'
$request->stream();   // the plain body stream instance
$request->mode();     // origin
$request->line();     // POST /index.php HTTP/1.1
$request->data();     // exports the request as an array
$request->toString(); // exports the request as an string
(string) $request;    // exports the request as an string

// Setters
$request->method('PATCH');
$request->scheme('https');
$request->version('1.0');
$request->host('www.domain.com:8000');
$request->port('80');
$request->query(['foo' => 'baz']);
$request->fragment(#qaz);
$request->type('application/json');
$request->set(['foo' => 'baz']);
$request->body('{"foo":"baz"}');
$request->mode('absolute');

$request->username('username');
$request->password('password');

$request->auth(); // Generates a Basic auth header from credentials.

// Generates a Digest auth header from credentials
$request->auth([
    'realm' => 'app',
    'qop' => 'auth',
    'nonce' => '4bca0fbca7bd0',
    'opaque' => 'd3fb67a7aa4d887ec4bf83040a820a46'
]);

$request->auth(false); // Removes Authorization header from headers
```

Example of creating a request from an absolute URL:

```
use Lead\Net\Http\Request;

$request = Request::create('http://username:password@www.domain.com:8080/index.php', [
    /* additionnal options */
]);
```

### The HTTP Response class

[](#the-http-response-class)

```
use Lead\Net\Http\Response;

$response = new Response([
    'status'  => [200, 'OK'],
    'version' => '1.1',
    'type'    => 'text/html; charset=utf-8',
    'body'    => ''
]);

// Getters
$response->status();   // [200, 'OK']
$response->version();  // 1.1
$response->protocol(); // HTTP/1.1
$response->type();     // text/html
$response->encoding(); // utf-8
$response->digest();   // Looks at the WWW-Authenticate headers and returns an array of key/values.
$response->get();      // ''
$response->body();     // ''
$response->stream();   // a Stream instance of the plain body
$response->line();     // HTTP/1.1 200 OK
$response->data();     // exports the response as an array
$response->toString(); // exports the response as an string
(string) $response;    // exports the response as an string

// Setters
$response->status(404);
$response->status([404, 'Not Found']);
$response->version('1.0');
$response->type('text/plain');
$response->set('Not Found');
$response->body('Not Found');
$response->cache(false);      // Disable cache
$response->cache('+2 weeks'); // 2 weeks cache
//
```

Example of creating a response from a plain string body:

```
use Lead\Net\Http\Response;

$response = Response::parse(join("\r\n", [
    'HTTP/1.1 200 OK',
    'Connection: close',
    'Content-Type: text/plain;charset=UTF8',
    'Content-Length: 5',
    'Set-Cookie: doctor=who; Path=/tardis; HttpOnly',
    'Set-Cookie: test=foo%20bar; Expires=Fri, 25 Dec 2015 00:00:00 GMT; Secure',
    'Set-Cookie: test=foo%2Bbin; Path=/test; Domain=.domain.com',
    '',
    'Test!'
]));
```

### The HTTP Headers class

[](#the-http-headers-class)

You can access HTTP Headers from both requests and responses instance through the `headers` public member.

```
$request = new Request();
$request->headers['Content-Type'];
$request->headers['Vary'] = 'Accept-Encoding';
$request->headers['Vary'][] = 'Cookie';
$request->headers['Vary'][] = 'User-Agent';
$request->headers['Cookie'] = 'foo1=bar1; foo2=bar2; foo3=bar3';

// You can also access cookies through the `cookies` public member from headers.
$request->headers->cookies['foo4'] = 'bar4';
$request->headers->cookies['foo4'][] = 'bar44';

(string) $request->headers->cookies; // Cookie header representation
(string) $request->headers;          // Headers representation
```

Headers work the same way for responses:

```
$response = new Responses();
$response->headers['Cache-Control'] = 'no-store';
$response->headers['Cache-Control'][] = 'no-cache';
$response->headers['Cache-Control'][] = 'must-revalidatee';
$response->headers['Cache-Control'][] = 'max-age';
// You can also use `$response->cache('+2 weeks')` or `$response->cache(false)` to  control caches;

// You can set several Set-Cookie with the same name as long as the path and or domain differ.
$request->headers->cookies['foo'] = ['value' => 'quz', 'path' => '/foo'];
$request->headers->cookies['foo'] = ['value' => 'qaz', 'path' => '/foo/bar'];
```

Note: cookies in responses are in `Set-Cookie` headers.

### The CGI Request class

[](#the-cgi-request-class)

```
use Lead\Net\Http\Cgi\Request;

// Creates a server request build with CGI global vars (ie. $_SERVER, $_POST, $_GET, $_COOKIE, $_FILES)
$request = Request::ingoing();
```

### Acknowledgements

[](#acknowledgements)

- [Li3](https://github.com/UnionOfRAD/lithium)
- [zend-diactoros](https://github.com/zendframework/zend-diactoros)
- [Requests](https://github.com/rmccue/Requests)
- [Guzzle](https://github.com/guzzle/guzzle)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/67c78f317fdfb9f077b1f16c88193192f7562e999c536b25943b759c3b5099fb?d=identicon)[jails](/maintainers/jails)

---

Top Contributors

[![jails](https://avatars.githubusercontent.com/u/1306941?v=4)](https://github.com/jails "jails (99 commits)")

### Embed Badge

![Health badge](/badges/crysalead-net/health.svg)

```
[![Health](https://phpackages.com/badges/crysalead-net/health.svg)](https://phpackages.com/packages/crysalead-net)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
