http-mel 0.10.0

Mélodium HTTP library
use root/server::HttpServer
use root/server::@HttpRequest
use root/server::incoming
use root/server::outgoing
use root/method::HttpMethod
use root/status::HttpStatus
use std/data/string_map::StringMap

/**
Connection on HTTP server.

For every valid incoming HTTP request to `http_server`, a new track with all the outputs is created.

In order to start sending response to the requester, `status` and `headers` inputs must be filled.
`status` can be any valid HTTP code, for more informations please see the [MDN Documentation](https://developer.mozilla.org/docs/Web/HTTP/Status).

Outputs:
    - `headers`: headers send in request.
    - `data`: the raw body data received in the request.
    - `failed`: emitted if a failure occurs during the processing of request.
    - `error`: error message emitted if a failure occurs during the processing of request.

Inputs:
    - `status`: HTTP status response.
    - `headers`: headers to send in response.
    - `data`: data to send in response, corresponding to the HTTP body.
*/
treatment connection[http_server: HttpServer](const method: HttpMethod, const route: string)
  require @HttpRequest
  input status: Block<HttpStatus>
  input headers: Block<StringMap>
  input data: Stream<byte>
  output started: Block<void>
  output headers: Block<StringMap>
  output data: Stream<byte>
  output failed: Block<void>
  output error: Block<string>
{
    incoming[http_server=http_server](method=method, route=route)
    outgoing[http_server=http_server](id=@HttpRequest[id])

    incoming.started -> Self.started
    incoming.headers -> Self.headers
    incoming.data ----> Self.data
    incoming.error ---> Self.error
    incoming.failed --> Self.failed

    Self.status --> outgoing.status
    Self.headers -> outgoing.headers
    Self.data ----> outgoing.data
}