<commit_before>A simple HTTP server for PHP
----------------------------

HttpServer is a simple HTTP server powerd [REACT](http://reactphp.org/).

[![Build Status](https://travis-ci.org/yosymfony/HttpServer.svg?branch=master)](https://travis-ci.org/yosymfony/HttpServer)

## Installation

Use [Composer](http://getcomposer.org/) to install Yosyfmony HttpServer package:

Add the following to your `composer.json` and run `composer update`.

    "require": {
        "yosymfony/httpserverl": "1.0.x-dev"
    }

More informations about the package on [Packagist](https://packagist.org/packages/yosymfony/httpserver).

## How to use?

It's simple. The RequestHandler need a function for managing each connection:

```
$requestHandler = new RequestHandler(function($request) {
    return 'Hi Yo! Symfony';
});

$server = new HttpServer($requestHandler);
$server->start();

// go to http://localhost:8080
```

## How to configure the RequestHandler?

**You can configure port and host for listening requests**:

```
$requestHandler = new RequestHandler( function($request) {
    return 'Hi Yo! Symfony';
});

$requestHandler->listen(8081, '127.0.0.1');
```

The defatult values:
* port: 8080
* host: 0.0.0.0

### The handler function

The handler function receives a unique parameter to describe the resquest. By default, this argument
is a object type [React\Http\Request](https://github.com/reactphp/http/blob/master/src/Request.php).
If you want to receive a [Symfony HttpFoundation Request](http://symfony.com/doc/current/components/http_foundation/introduction.html#request)
you need active this mode:

```
$requestHandler = new RequestHandler( function($request) {
    return 'Hi Yo! Symfony';
});

$requestHandler
    ->listen(8081, '127.0.0.1')
    ->enableHttpFoundationRequest(); // $requestHandler uses fluent interface
```

In case you want to use a HttpKernelInterface like Symfony, Silex oder Laravel, simple use the `HttpKernelRequestHandler` handler like this:
```
// Create our kernel.
$httpKernel = new ExampleHttpKernel();
$options = array(
    'host' => '127.0.0.1',
    'port' => 8081,
);

// Wrap it with the RequestHandler.
$handler = new \Yosymfony\HttpServer\HttpKernelRequestHandler($httpKernel, $options);

// Start the server using the RequestHandler.
$server = new \Yosymfony\HttpServer\HttpServer($handler);
$server->start();
```

## The response

The most simple use-case is return a string. By default the `Content-Type` value is `text/plain` at the response header:

```
$requestHandler = new RequestHandler( function($request) {<commit_msg>Fix typo (oder by or)<commit_after>A simple HTTP server for PHP
----------------------------

HttpServer is a simple HTTP server powerd [REACT](http://reactphp.org/).

[![Build Status](https://travis-ci.org/yosymfony/HttpServer.svg?branch=master)](https://travis-ci.org/yosymfony/HttpServer)

## Installation

Use [Composer](http://getcomposer.org/) to install Yosyfmony HttpServer package:

Add the following to your `composer.json` and run `composer update`.

    "require": {
        "yosymfony/httpserverl": "1.0.x-dev"
    }

More informations about the package on [Packagist](https://packagist.org/packages/yosymfony/httpserver).

## How to use?

It's simple. The RequestHandler need a function for managing each connection:

```
$requestHandler = new RequestHandler(function($request) {
    return 'Hi Yo! Symfony';
});

$server = new HttpServer($requestHandler);
$server->start();

// go to http://localhost:8080
```

## How to configure the RequestHandler?

**You can configure port and host for listening requests**:

```
$requestHandler = new RequestHandler( function($request) {
    return 'Hi Yo! Symfony';
});

$requestHandler->listen(8081, '127.0.0.1');
```

The defatult values:
* port: 8080
* host: 0.0.0.0

### The handler function

The handler function receives a unique parameter to describe the resquest. By default, this argument
is a object type [React\Http\Request](https://github.com/reactphp/http/blob/master/src/Request.php).
If you want to receive a [Symfony HttpFoundation Request](http://symfony.com/doc/current/components/http_foundation/introduction.html#request)
you need active this mode:

```
$requestHandler = new RequestHandler( function($request) {
    return 'Hi Yo! Symfony';
});

$requestHandler
    ->listen(8081, '127.0.0.1')
    ->enableHttpFoundationRequest(); // $requestHandler uses fluent interface
```

In case you want to use a HttpKernelInterface like Symfony, Silex or Laravel, simple use the `HttpKernelRequestHandler` handler like this:
```
// Create our kernel.
$httpKernel = new ExampleHttpKernel();
$options = array(
    'host' => '127.0.0.1',
    'port' => 8081,
);

// Wrap it with the RequestHandler.
$handler = new \Yosymfony\HttpServer\HttpKernelRequestHandler($httpKernel, $options);

// Start the server using the RequestHandler.
$server = new \Yosymfony\HttpServer\HttpServer($handler);
$server->start();
```

## The response

The most simple use-case is return a string. By default the `Content-Type` value is `text/plain` at the response header:

```
$requestHandler = new RequestHandler( function($request) {
{'fraction_non_alphanumeric': 0.14535561601243685, 'fraction_numerical': 0.017100660707345512, 'mean_word_length': 4.40083945435467, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1806017', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1552, 'n_words': 468}