Table Of Contents

Previous topic

ginsfsm.c_connex

Next topic

ginsfsm.protocols.wsgi

ginsfsm.protocols.http.server

Server http protocol.

An asynchronous http server, with well defined layers.

The wsgi/http server is inspired in Tornado and Waitress projects and using the best of both.

Classes involved:

../../_images/http-server.png

GObj GHttpServer

class ginsfsm.protocols.http.server.c_http_server.GHttpServer[source]

Asynchronous Http Server gobj.

In the startup, this class creates internally a server socket, gobj of ginsfsm.c_srv_sock.GServerSock gclass.

When a new client connects, a new ginsfsm.c_sock.GSock gobj is created, receiving the EV_CONNECTED event. Then it creates a ginsfsm.protocols.http.server.c_http_clisrv.GHttpCliSrv gobj that will process all the events of the GSock gobj.

The output events of ginsfsm.protocols.http.server.c_http_clisrv.GHttpCliSrv will be processed by subscriber gobj of this class.

Configurable Parameters:
Name Type Default value Description
url_scheme str http default http value
max_request_body_size int 1073741824
host str listening host
expose_tracebacks bool False expose tracebacks of uncaught exceptions
n_channels int 0 Server stats, number of channels opened
inactivity_timeout int 18000 Inactivity timeout in seconds.
port int 0 listening port
identity str ginsfsm server identity (sent in Server: header)
max_request_header_size int 262144
origins None None TODO:list of (host, port) tuples allowed to connect from
inbuf_overflow int 524288
subscriber None None subcriber of all output-events.Default is None, i.e., the parent
responseless_timeout int 18000 ‘Without response’ timeout in seconds.
maximum_simultaneous_requests int 0 maximum simultaneous requests. Default: 0, without limit.
Diagram:
Input-Events:
  • 'EV_CONNECTED': new clisrv, client socket.

    The internal child ginsfsm.c_srv_sock.GServerSock gobj has accepted a new socket connection, and it has created a new client gobj (clisrv) of ginsfsm.c_sock.GSock gclass.

    This event has been sended by the new ginsfsm.c_sock.GSock clisrv gobj.

    A new ginsfsm.protocols.http.server.c_http_clisrv.GHttpCliSrv gobj is created, to process all the events of the GSock gobj.

    This class will be subscred to the 'EV_HTTP_CHANNEL_CLOSED' event in order to destroy the GHttpCliSrv gobj.

    Event attributes:

    • peername: remote address to which the socket is connected.
    • sockname: the socket’s own address.
  • 'EV_HTTP_CHANNEL_CLOSED': http channel disconnected.

    The http server subcribes this event from clisrv gobj, in order to destroy it when became disconnected.

GObj GHttpCliSrv

Http Channel.

class ginsfsm.protocols.http.server.c_http_clisrv.GHttpCliSrv[source]

Http clisrv (client of server) class.

This gobj is create by GHttpServer when it receives an EV_CONNECTED event from a new gsock gobj.

This class will subscribe all the events of the partner ginsfsm.c_sock.GSock gobj, to implement the http protocol.

Configurable Parameters:
Name Type Default value Description
subscriber None None subcriber of all output-events.
gsock None None partner gsock.
inactivity_timeout int 18000 Inactivity timeout in seconds.
url_scheme str http default http value
responseless_timeout int 18000 ‘Without response’ timeout in seconds.
max_request_header_size int 262144
max_request_body_size int 1073741824
maximum_simultaneous_requests int 0 maximum simultaneous requests.
inbuf_overflow int 524288
Diagram:
Top Output-Events:
  • 'EV_HTTP_CHANNEL_OPENED': new http client.

    Event attributes:

    • channel: http channel.
  • 'EV_HTTP_CHANNEL_CLOSED': http client closed.

    Event attributes:

    • channel: http channel.
  • 'EV_HTTP_REQUEST': new http request.

    Event attributes:

    • channel: http channel.
    • request: http request.
Top Input-Events:
  • 'EV_HTTP_RESPONSE': response to the current request.

    Event attributes:

    • response: http response.
Bottom Input-Events:
  • 'EV_DISCONNECTED': socket disconnected.

    The clisrv gobj will be destroyed.

  • 'EV_TRANSMIT_READY': socket ready to transmit more data.

  • 'EV_RX_DATA': data received. Process http protocol.

Bottom Output-Events:

  • 'EV_SEND_DATA': transmit data socket.
  • 'EV_WRITE_OUTPUT_DATA': write data to socket output buffer.
  • 'EV_FLUSH_OUTPUT_DATA': flush data of socket output buffer.
finish(response=None)[source]

Finishes this response, flushing output buffer, and ending the HTTP request. To supply asynchronous access to high level.

flush(callback=None)[source]

Flush output buffer. To supply asynchronous access to high level.

go_out()[source]

Finish zone.

write(data)[source]

Write data to output buffer. To supply asynchronous access to high level.