chronos/apps/http/httpcommon

Search:
Group by:
Source   Edit  

Types

ContentEncodingFlags {.pure.} = enum
  Identity, Br, Compress, Deflate, Gzip
Source   Edit  
HttpAddressErrorType {.pure.} = enum
  InvalidUrlScheme = "Unsupported URL scheme",
  InvalidPortNumber = "Invalid port number",
  MissingHostname = "Hostname missing from URL",
  InvalidIpHostname = "Invalid IP", NameLookupFailed = "DNS lookup failed",
  NoAddressResolved = "Hostname has no addresses"
Source   Edit  
HttpCriticalError {....deprecated.} = object of HttpProtocolError
Deprecated
Source   Edit  
HttpError = object of AsyncError
Source   Edit  
HttpInterruptError = object of HttpError
Source   Edit  
HttpMessage = object
  code*: HttpCode
  contentType*: MediaType
  message*: string
Source   Edit  
HttpProtocolError = object of HttpError
  code*: HttpCode
Source   Edit  
HttpRecoverableError {....deprecated.} = object of HttpProtocolError
Deprecated
Source   Edit  
HttpResult[T] = Result[T, string]
Source   Edit  
HttpResultCode[T] = Result[T, HttpCode]
Source   Edit  
HttpResultMessage[T] = Result[T, HttpMessage]
Source   Edit  
HttpState {.pure.} = enum
  Alive, Closing, Closed
Source   Edit  
HttpTransportError = object of HttpError
Source   Edit  
KeyValueTuple = tuple[key: string, value: string]
Source   Edit  
QueryParamsFlag {.pure.} = enum
  CommaSeparatedArray        ## Enable usage of comma symbol as separator of array
                             ## items
Source   Edit  
TransferEncodingFlags {.pure.} = enum
  Identity, Chunked, Compress, Deflate, Gzip
Source   Edit  

Consts

AcceptHeaderName = "accept"
Source   Edit  
AuthorizationHeader = "authorization"
Source   Edit  
ConnectionHeader = "connection"
Source   Edit  
ContentDispositionHeader = "content-disposition"
Source   Edit  
ContentEncodingHeader = "content-encoding"
Source   Edit  
ContentLengthHeader = "content-length"
Source   Edit  
ContentTypeHeader = "content-type"
Source   Edit  
CriticalHttpAddressError = {HttpAddressErrorType.InvalidUrlScheme,
                            HttpAddressErrorType.InvalidPortNumber,
                            HttpAddressErrorType.MissingHostname,
                            HttpAddressErrorType.InvalidIpHostname}
Source   Edit  
DateHeader = "date"
Source   Edit  
ExpectHeader = "expect"
Source   Edit  
HeadersMark = [0x0D'u8, 0x0A'u8, 0x0D'u8, 0x0A'u8]
Source   Edit  
HostHeader = "host"
Source   Edit  
HttpServerRequestTrackerName = "httpserver.request"
Source   Edit  
HttpServerResponseTrackerName = "httpserver.response"
Source   Edit  
HttpServerSecureConnectionTrackerName = "httpserver.secure.connection"
Source   Edit  
HttpServerUnsecureConnectionTrackerName = "httpserver.unsecure.connection"
Source   Edit  
LocationHeader = "location"
Source   Edit  
MaximumBodySizeError = "Maximum size of request\'s body reached"
Source   Edit  
MultipartContentType = (media: "multipart", subtype: "form-data")
Source   Edit  
PostMethods = {MethodPost, MethodPatch, MethodPut, MethodDelete}
Source   Edit  
ProxyAuthorizationHeader = "proxy-authorization"
Source   Edit  
RecoverableHttpAddressError = {HttpAddressErrorType.NameLookupFailed,
                               HttpAddressErrorType.NoAddressResolved}
Source   Edit  
ServerHeader = "server"
Source   Edit  
TransferEncodingHeader = "transfer-encoding"
Source   Edit  
UrlEncodedContentType = (media: "application", subtype: "x-www-form-urlencoded")
Source   Edit  
UserAgentHeader = "user-agent"
Source   Edit  

Procs

func bytesToString(src: openArray[byte]): string {....raises: [], tags: [],
    forbids: [].}

Convert array of bytes to a string.

Note, that this procedure assume that sizeof(byte) == sizeof(char) == 1. If this equation is not correct this procedures MUST not be used.

Source   Edit  
proc bytesToString(src: openArray[byte]; dst: var openArray[char]) {....raises: [],
    tags: [], forbids: [].}

Convert array of bytes to array of characters.

Note, that this procedure assume that sizeof(byte) == sizeof(char) == 1. If this equation is not correct this procedures MUST not be used.

Source   Edit  
func encodeBasicAuth(username, password: string): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func getContentEncoding(ch: openArray[string]): HttpResult[
    set[ContentEncodingFlags]] {....deprecated: "getContentEncodings", raises: [],
                                 tags: [], forbids: [].}
Deprecated: getContentEncodings
Parse value of multiple HTTP headers Content-Encoding and return the last entry, ie the first encoding that must be decoded. Source   Edit  
func getContentEncodings(ch: openArray[string]): HttpResult[
    seq[ContentEncodingFlags]] {....raises: [], tags: [], forbids: [].}

Parse value of multiple Content-Encoding headers and return the list of ContentEncodingFlags.

If no encodings are given, returns an empty seq.

identity is a no-op encoding that is accepted and ignored for backwards compatibility.

See also:

Source   Edit  
func getContentType(ch: openArray[string]): HttpResult[ContentTypeData] {.
    ...raises: [], tags: [], forbids: [].}
Check and prepare value of Content-Type header. Source   Edit  
func getTransferEncoding(ch: openArray[string]): HttpResult[
    set[TransferEncodingFlags]] {....deprecated: "getTransferEncodings",
                                  raises: [], tags: [], forbids: [].}
Deprecated: getTransferEncodings
Parse value of multiple HTTP headers Transfer-Encoding and return the last entry, ie the first encoding that must be decoded. Source   Edit  
func getTransferEncodings(ch: openArray[string]): HttpResult[
    seq[TransferEncodingFlags]] {....raises: [], tags: [], forbids: [].}

Parse value of multiple Transfer-Encoding headers and return the list.

identity is a no-op encoding that is accepted and ignored for backwards compatibility.

See also:

Source   Edit  
func init(t: typedesc[HttpMessage]; code: HttpCode): HttpMessage {....raises: [].}
Source   Edit  
func init(t: typedesc[HttpMessage]; code: HttpCode; message: string): HttpMessage {.
    ...raises: [].}
Source   Edit  
func init(t: typedesc[HttpMessage]; code: HttpCode; message: string;
          contentType: MediaType): HttpMessage {....raises: [].}
Source   Edit  
func init(t: typedesc[HttpMessage]; code: HttpCode; message: string;
          contentType: string): HttpMessage {....raises: [].}
Source   Edit  
func isCriticalError(error: HttpAddressErrorType): bool {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func isPersistent(version: HttpVersion; headers: HttpTable): bool {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
func isRecoverableError(error: HttpAddressErrorType): bool {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc newHttpInterruptError(): ref HttpInterruptError {.noinline, ...raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc newHttpReadError(message: string): ref HttpReadError {.noinline,
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc newHttpUseClosedError(): ref HttpUseClosedError {.noinline, ...raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc newHttpWriteError(message: string): ref HttpWriteError {.noinline,
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc raiseHttpAddressError(msg: string) {.noinline, noreturn,
    ...raises: [HttpAddressError], raises: [], tags: [], forbids: [].}
Source   Edit  
proc raiseHttpConnectionError(msg: string) {.noinline, noreturn,
    ...raises: [HttpConnectionError], raises: [], tags: [], forbids: [].}
Source   Edit  
proc raiseHttpCriticalError(msg: string; code = Http400) {.noinline, noreturn,
    ...raises: [HttpCriticalError], deprecated, raises: [], tags: [], forbids: [].}
Deprecated
Source   Edit  
proc raiseHttpDisconnectError() {.noinline, noreturn,
                                  ...raises: [HttpDisconnectError], raises: [],
                                  tags: [], forbids: [].}
Source   Edit  
proc raiseHttpInterruptError() {.noinline, noreturn,
                                 ...raises: [HttpInterruptError], raises: [],
                                 tags: [], forbids: [].}
Source   Edit  
proc raiseHttpProtocolError(code: HttpCode; msg: string) {.noinline, noreturn,
    ...raises: [HttpProtocolError], raises: [], tags: [], forbids: [].}
Source   Edit  
proc raiseHttpProtocolError(msg: HttpMessage) {.noinline, noreturn,
    ...raises: [HttpProtocolError], raises: [], tags: [], forbids: [].}
Source   Edit  
proc raiseHttpProtocolError(msg: string) {.noinline, noreturn,
    ...raises: [HttpProtocolError], raises: [], tags: [], forbids: [].}
Source   Edit  
proc raiseHttpReadError(msg: string) {.noinline, noreturn,
                                       ...raises: [HttpReadError], raises: [],
                                       tags: [], forbids: [].}
Source   Edit  
proc raiseHttpRedirectError(msg: string) {.noinline, noreturn,
    ...raises: [HttpRedirectError], raises: [], tags: [], forbids: [].}
Source   Edit  
proc raiseHttpRequestBodyTooLargeError() {.noinline, noreturn,
    ...raises: [HttpRequestBodyTooLargeError], raises: [], tags: [], forbids: [].}
Source   Edit  
proc raiseHttpWriteError(msg: string) {.noinline, noreturn,
                                        ...raises: [HttpWriteError], raises: [],
                                        tags: [], forbids: [].}
Source   Edit  
func stringToBytes(src: openArray[char]): seq[byte] {....raises: [], tags: [],
    forbids: [].}

Convert string to sequence of bytes.

Note, that this procedure assume that sizeof(byte) == sizeof(char) == 1. If this equation is not correct this procedures MUST not be used.

Source   Edit  
proc stringToBytes(src: openArray[char]; dst: var openArray[byte]) {....raises: [],
    tags: [], forbids: [].}

Convert array of characters to array of bytes.

Note, that this procedure assume that sizeof(byte) == sizeof(char) == 1. If this equation is not correct this procedures MUST not be used.

Source   Edit  
func toString(error: HttpAddressErrorType): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  

Iterators

iterator queryParams(query: string; flags: set[QueryParamsFlag] = {}): KeyValueTuple {.
    ...raises: [], tags: [], forbids: [].}
Iterate over url-encoded query string. Source   Edit  

Exports

NestedPoll, closeSocket, ENOSR, EHOSTUNREACH, EHOSTDOWN, ECONNRESET, EDQUOT, fail, ECANCELED, EMLINK, milliseconds, asyncTimer, +=, $, Second, internalRaiseIfError, getSrcLocation, FutureError, fromNow, weeks, ESPIPE, withTimeout, LocationKind, id, <=, FutureBase, FutureCompletedError, ENOEXEC, ESHUTDOWN, fail, EREMOTEIO, Day, waitFor, complete, internalInitFutureBase, EPROTONOSUPPORT, cancelAndWait, addTimer, Moment, ECOMM, EPROTOTYPE, AsyncExceptionError, FuturePendingError, milliseconds, ENOENT, millis, removeTimer, or, FutureFlag, ENOTCONN, EBUSY, init, ENOTUNIQ, <=, days, +=, race, ==, cancelSoon, AsyncTimeoutError, setThreadDispatcher, EEXIST, ENOLINK, newInternalRaisesFuture, idleAsync, internalRaiseIfError, SomeIntegerI64, ENOMEM, ENOKEY, +, removeWriter2, ENOMSG, EKEYEXPIRED, Week, cancelSoon, awaitne, EAFNOSUPPORT, EWOULDBLOCK, [], EREMOTE, finished, AsyncCallback, EHWPOISON, epochSeconds, newDispatcher, EPERM, microseconds, internalFail, weeks, Finished, ENOTSOCK, cancelCallback=, ETOOMANYREFS, $, EISCONN, callSoon, ESOCKTNOSUPPORT, setGlobalDispatcher, EXDEV, EBADF, EKEYREVOKED, allFinished, TrackerBase, hours, InternalAsyncCallback, EBFONT, ENETDOWN, EACCES, ELOOP, InfiniteDuration, ETIMEDOUT, EINVAL, value, EBADFD, Future, completed, PDispatcher, ESRCH, EL2NSYNC, Finished, low, await, ESTRPIPE, -=, EALREADY, getAsyncTimestamp, EXFULL, Hour, EIDRM, removeReader2, secs, getThreadDispatcher, futureContinue, isZero, ENOANO, EADV, CallbackFunc, contains, cancelAndWait, $, ENFILE, waitFor, high, Microsecond, ENOPKG, ELIBBAD, EOWNERDEAD, handle, ERANGE, done, ENONET, completed, callSoon, toString, cancelSoon, EMSGSIZE, EBADMSG, EILSEQ, ENOPROTOOPT, EDESTADDRREQ, allFutures, -, complete, FutureState, EBADR, nanos, location, FutureDefect, EDOTDOT, one, EKEYREJECTED, <, race, error, one, CancelledError, nanoseconds, EISDIR, sleepAsync, Nanosecond, EOVERFLOW, FutureSeq, cancelAndWait, micros, -, ESRMNT, ENOTEMPTY, EPROTO, TimerCallback, microseconds, error, epochNanoSeconds, ENOTRECOVERABLE, wait, EDOM, value, hours, AsyncError, EBADRQC, ENODEV, FutureStr, addTimer, ENOBUFS, ECHRNG, ENOTDIR, EUNATCH, cancelAndSchedule, failed, nanoseconds, ERESTART, *, ETXTBSY, newFutureStr, EMFILE, LocFinishIndex, withTimeout, addTimer, race, EUSERS, ENOTBLK, Minute, DispatcherHandle, EISNAM, ELIBACC, ENAVAIL, init, race, EUCLEAN, ENOTTY, +, cancelSoon, completed, minutes, cancel, FutureFlags, getGlobalDispatcher, ELIBEXEC, stepsAsync, micros, wait, cancelAndWait, EINPROGRESS, EPFNOSUPPORT, E2BIG, -=, ENOMEDIUM, secs, read, waitFor, EL3HLT, unregisterAndCloseFd, EBADSLT, InternalRaisesFuture, -, <, ENETRESET, fastEpochTime, ENXIO, join, EPIPE, ThreadCallbackFunc, allFutures, race, wait, now, read, asyncSpawn, removeCallback, EAGAIN, raiseOsDefect, EADDRNOTAVAIL, read, removeCallback, TrackerCounter, async, addCallback, init, async, ZeroDuration, EREMCHG, EFAULT, addCallback, seconds, noCancel, low, AsyncFD, ECHILD, Raising, init, ECONNABORTED, state, wait, removeTimer, LocCreateIndex, addReader2, ETIME, ENOLCK, EBADE, EDEADLK, asyncCheck, Duration, ELNRNG, ENOCSI, millis, EMEDIUMTYPE, readError, sleepAsync, isInfinite, callback=, ENETUNREACH, InternalFutureBase, ENOSPC, ENOSYS, ELIBSCN, EIO, EROFS, seconds, ELIBMAX, SrcLoc, ==, ==, div, init, EL2HLT, EOPNOTSUPP, tryCancel, poll, flags, clearTimer, register2, LocCompleteIndex, days, ENOSTR, EADDRINUSE, one, ENAMETOOLONG, EMULTIHOP, ESTALE, await, ENODATA, EFBIG, +, minutes, ERFKILL, cancelled, toException, or, EDEADLOCK, allFutures, MaxEventsCount, wait, read, raiseAsDefect, Millisecond, setTimer, unregister2, failed, waitFor, newFutureSeq, callback=, orImpl, ECONNREFUSED, high, ENOTNAM, nanos, addWriter2, removeTimer, EINTR, join, closeHandle, EL3RST, readError, *, newFuture, []=, EDQUOT, internalRaiseIfError, closeSocket, EHOSTUNREACH, EHOSTDOWN, closeWait, ECONNRESET, fail, ECANCELED, EMLINK, milliseconds, InternalRaisesFuture, CallbackFunc, +=, $, Second, NestedPoll, getSrcLocation, FutureError, fromNow, close, weeks, ESPIPE, withTimeout, LocationKind, id, isSet, <=, FutureCompletedError, ENOEXEC, SomeIntegerI64, fail, EREMOTEIO, or, ENOTTY, waitFor, addTimer, internalInitFutureBase, EPROTONOSUPPORT, nanoseconds, ==, cancelAndWait, contains, ENOPKG, Moment, ECOMM, addFirst, register, EPROTOTYPE, AsyncExceptionError, AsyncSemaphore, ENOCSI, milliseconds, ENOENT, millis, [], removeTimer, ENOSR, ==, EADDRNOTAVAIL, ENOTCONN, EBUSY, init, waitFor, asyncTimer, days, +=, race, EAFNOSUPPORT, ZeroDuration, cancelSoon, AsyncTimeoutError, []=, setThreadDispatcher, EEXIST, isInfinite, ENOLINK, newInternalRaisesFuture, idleAsync, internalRaiseIfError, ESHUTDOWN, ENOMEM, ==, ENOKEY, +, removeWriter2, ENOMSG, EKEYEXPIRED, Week, cancelSoon, awaitne, EWOULDBLOCK, EREMOTE, unregister, EPERM, tryAcquire, finished, AsyncCallback, EHWPOISON, epochSeconds, newDispatcher, microseconds, AsyncEvent, internalFail, sleepAsync, addCallback, weeks, Finished, cancelCallback=, ETOOMANYREFS, mitems, EISCONN, callSoon, ESOCKTNOSUPPORT, newAsyncQueue, setGlobalDispatcher, AsyncQueue, release, EXDEV, EBADF, cancelSoon, allFinished, microseconds, hours, wait, ENETDOWN, EACCES, AsyncEventQueue, ELOOP, InfiniteDuration, ETIMEDOUT, clear, EINVAL, value, EBADFD, Future, addCallback, len, completed, PDispatcher, ESRCH, EL2NSYNC, Finished, low, await, ESTRPIPE, -=, ENOLCK, [], getAsyncTimestamp, div, Hour, EIDRM, removeReader2, EventQueueReader, secs, getThreadDispatcher, EventQueueKey, futureContinue, popFirstNoWait, isZero, ENOANO, readError, <=, cancelAndWait, $, tryCancel, addLastNoWait, FutureBase, waitFor, high, Microsecond, complete, $, pairs, ELIBBAD, EOWNERDEAD, handle, ERANGE, done, clearTimer, popLastNoWait, contains, or, ENONET, completed, callSoon, cancelSoon, EMSGSIZE, EALREADY, EBADMSG, EILSEQ, ENOPROTOOPT, race, allFutures, empty, -, addTimer, FutureState, addFirstNoWait, EBADR, nanos, location, FutureDefect, EDOTDOT, ENOBUFS, put, EKEYREJECTED, <, Minute, error, one, CancelledError, EISDIR, release, EKEYREVOKED, FutureSeq, cancelAndWait, micros, -, ESRMNT, ENOTEMPTY, EPROTO, TimerCallback, TrackerBase, ENOTRECOVERABLE, EBFONT, cancelAndWait, hours, AsyncError, EBADRQC, ENODEV, ENFILE, complete, callback=, one, ECHRNG, wait, EUNATCH, cancelAndSchedule, acquire, failed, nanoseconds, ERESTART, *, ETXTBSY, availableSlots, newFutureStr, full, getNoWait, EMFILE, LocFinishIndex, orImpl, withTimeout, addTimer, race, EUSERS, ENOTBLK, race, DispatcherHandle, EISNAM, ELIBACC, init, EXFULL, EUCLEAN, race, +, EOVERFLOW, minutes, cancel, FutureFlags, getGlobalDispatcher, popFirst, ELIBEXEC, stepsAsync, error, micros, wait, clear, EINPROGRESS, completed, E2BIG, -=, ENOMEDIUM, secs, AsyncQueueEmptyError, value, read, waitFor, EINTR, newAsyncSemaphore, unregisterAndCloseFd, EBADSLT, [], -, <, ENETRESET, fastEpochTime, waitEvents, seconds, EDOM, FuturePendingError, EPIPE, AsyncLockError, InternalFutureBase, ThreadCallbackFunc, allFutures, len, EDESTADDRREQ, ENAVAIL, await, EPFNOSUPPORT, wait, EMULTIHOP, read, asyncSpawn, removeCallback, EAGAIN, raiseOsDefect, FutureFlag, read, removeCallback, TrackerCounter, async, AsyncLock, init, popLast, async, ENOSPC, EREMCHG, EFAULT, fire, ENXIO, seconds, noCancel, low, AsyncFD, ECHILD, init, ECONNABORTED, state, ENOTDIR, removeTimer, LocCreateIndex, setTimer, ETIME, EBADE, EDEADLK, items, asyncCheck, epochNanoSeconds, unregister2, Duration, ELNRNG, locked, join, millis, EMEDIUMTYPE, readError, sleepAsync, newFutureSeq, newAsyncEventQueue, InternalAsyncCallback, ENETUNREACH, get, ENOSYS, acquire, ELIBSCN, EIO, EROFS, AsyncEventQueueFullError, ELIBMAX, SrcLoc, EFBIG, EL2HLT, AsyncQueueFullError, EOPNOTSUPP, emit, FutureStr, poll, readerOverflow, flags, register2, LocCompleteIndex, newAsyncLock, days, ENOSTR, EADDRINUSE, one, AsyncSemaphoreError, size, newFuture, now, putNoWait, Nanosecond, wait, newAsyncEvent, ESTALE, Raising, Day, ENODATA, init, +, minutes, ERFKILL, cancelled, $, toException, EDEADLOCK, allFutures, MaxEventsCount, wait, read, raiseAsDefect, Millisecond, addLast, addReader2, failed, ENOTUNIQ, callback=, ENOTSOCK, ECONNREFUSED, high, ENOTNAM, nanos, addWriter2, toString, removeTimer, EL3HLT, join, closeHandle, EL3RST, EADV, *, ENAMETOOLONG