## GskHttpServer

GskHttpServer — The server end of an HTTP connection.

## Synopsis

    gboolean            (*GskHttpServerTrap)                (GskHttpServer *server,
                                                             gpointer data);
                        GskHttpServerClass;
                        GskHttpServer;
    #define             GSK_HTTP_SERVER_HOOK                (client)
    #define             gsk_http_server_trap                (server,func,shutdown,data,destroy)
    #define             gsk_http_server_untrap              (server)
    GskHttpServer *     gsk_http_server_new                 (void);
    gboolean            gsk_http_server_get_request         (GskHttpServer *server,
                                                             GskHttpRequest **request_out,
                                                             GskStream **post_data_out);
    void                gsk_http_server_respond             (GskHttpServer *server,
                                                             GskHttpRequest *request,
                                                             GskHttpResponse *response,
                                                             GskStream *content);

## Object Hierarchy

      GObject
       +----GskIO
             +----GskStream
                   +----GskHttpServer

## Description

This class manages incoming requests (including post-data), and outgoing responses (by passing a supplied GskStream as HTTP content).

## Details

### GskHttpServerTrap ()

    gboolean            (*GskHttpServerTrap)                (GskHttpServer *server,
                                                             gpointer data);

Function which will be called when the server has a request ready.

`server` : | the server which has the request available.
`data` : | as passed in to `gsk_http_server_trap()`.
Returns : | whether to keep the trap active.

### GskHttpServerClass

    typedef struct {
      GskStreamClass stream_class;
      void         (*set_poll_request) (GskHttpServer *server,
    				    gboolean       do_poll);
      void         (*shutdown_request) (GskHttpServer *server);
    } GskHttpServerClass;

Virtual functions which are implemented by an HTTP server.

GskStreamClass `stream_class`; | the base server class.
`set_poll_request` () | function to indicate whether to notify on the HTTP trap.
`shutdown_request` () | function to call to stop accepting requests.

### GskHttpServer

    typedef struct _GskHttpServer GskHttpServer;

Stream which is the server end of an HTTP connection.

This has a trap which is triggered when new requests are available. This HTTP server does not define any behavior-- the user is responsible for calling `gsk_http_server_respond()` to handle the request.

### GSK_HTTP_SERVER_HOOK()

    #define             GSK_HTTP_SERVER_HOOK(client)

Get the hook which is triggered on HTTP request availability.

`client` : | the client to get the hook from.

### gsk_http_server_trap()

    #define             gsk_http_server_trap(server,func,shutdown,data,destroy)

Register a function which will get called as long as a request is available. The request should be dequeued with `gsk_http_server_get_request()`.

`server` : | the server to watch.
`func` : | the function to call if a request is available.
`shutdown` : | the function to call if no further requests are going to be available.
`data` : | data to pass to `func` and `shutdown`.
`destroy` : | the function to call when the trap is removed or destroyed.

### gsk_http_server_untrap()

    #define             gsk_http_server_untrap(server)

Unregister the function which was to be called whenever a request was available.

This has the same effect as returning FALSE from the function registered with `gsk_http_server_trap()`.

`server` : | the server to stop watching.

### gsk_http_server_new ()

    GskHttpServer *     gsk_http_server_new                 (void);

Allocate a new HTTP server protocol processor. (Note that generally you will need to connect it to an accepted socket)

Returns : | the newly allocated server.

### gsk_http_server_get_request ()

    gboolean            gsk_http_server_get_request         (GskHttpServer *server,
                                                             GskHttpRequest **request_out,
                                                             GskStream **post_data_out);

Grab a client request if available. Use `gsk_http_server_trap()` to get notification when a request is available.

The corresponding POST data stream must be retrieved at the same time.

`server` : | the HTTP server to grab the request from.
`request_out` : | location to store a reference to the HTTP request.
`post_data_out` : | location to store a reference to the HTTP request's POST data, or NULL will be stored if this is not a POST-type request.
Returns : | whether a request was successfully dequeued.

### gsk_http_server_respond ()

    void                gsk_http_server_respond             (GskHttpServer *server,
                                                             GskHttpRequest *request,
                                                             GskHttpResponse *response,
                                                             GskStream *content);

Give a response to a client's request.

`server` : | the server to write the response to.
`request` : | the request obtained with `gsk_http_server_get_request()`.
`response` : | the response constructed to this request.
`content` : | content data if appropriate to this request.

## See Also

GskHttpClient