netkit/http/writer

This module provides an abstraction of write operations related to HTTP.

Overview

A server writes a response to a client, and a client writes a request to a server.

HttpWriter is a base object for write operations, ServerResponse and ClientRequest inherit from it. ServerResponse represents a response from a server, and ClientRequest represents a request from a client.

Types

HttpWriter = ref object of RootObj
  conn: HttpConnection
  lock: AsyncLock
  onEnd: proc () {...}{.gcsafe, closure.}
  writable: bool
An abstraction of write operations related to HTTP.   Source Edit
ServerResponse = ref object of HttpWriter
Represents a response from a server.   Source Edit
ClientRequest = ref object of HttpWriter
Represents a request from a client.   Source Edit

Procs

proc newServerResponse(conn: HttpConnection; onEnd: proc () {...}{.gcsafe, closure.}): ServerResponse {...}{.
    raises: [], tags: [].}
Creates a new ServerResponse.   Source Edit
proc newClientRequest(conn: HttpConnection; onEnd: proc () {...}{.gcsafe, closure.}): ClientRequest {...}{.
    raises: [], tags: [].}
Creates a new ClientRequest.   Source Edit
proc ended(writer: HttpWriter): bool {...}{.inline, raises: [], tags: [].}
Returns true if the underlying connection has been closed or writer has been shut down.   Source Edit
proc write(writer: HttpWriter; buf: pointer; size: Natural): Future[void] {...}{.
    raises: [Exception, FutureError], tags: [RootEffect].}

Writes size bytes from buf to the writer.

If a system error occurs during writing, an OsError will be raised. If the connection is disconnected before successful writing or the writer has been shut down, a WriteAbortedError will be raised.

  Source Edit
proc write(writer: HttpWriter; data: string): Future[void] {...}{.
    raises: [Exception, FutureError], tags: [RootEffect].}

Writes a string to the writer.

If a system error occurs during writing, an OsError will be raised. If the connection is disconnected before successful writing or the writer has been shut down, a WriteAbortedError will be raised.

  Source Edit
proc write(writer: HttpWriter; statusCode: HttpCode;
          fields: openArray[tuple[name: string, value: string]]): Future[void] {...}{.
    raises: [Exception, FutureError, KeyError], tags: [RootEffect].}

Writes a message header to the writer.

If a system error occurs during writing, an OsError will be raised. If the connection is disconnected before successful writing or the writer has been shut down, a WriteAbortedError will be raised.

  Source Edit
proc write(writer: HttpWriter; statusCode: HttpCode;
          fields: openArray[tuple[name: string, value: seq[string]]]): Future[void] {...}{.
    raises: [Exception, FutureError, KeyError], tags: [RootEffect].}

Writes a message header to the writer.

If a system error occurs during writing, an OsError will be raised. If the connection is disconnected before successful writing or the writer has been shut down, a WriteAbortedError will be raised.

  Source Edit
proc writeEnd(writer: HttpWriter) {...}{.raises: [Exception], tags: [RootEffect].}
Shuts down writer. Data is no longer allowed to be written, otherwise an WriteAbortedError will be raised.   Source Edit