Option -> Opt (#307)

This commit is contained in:
Jacek Sieka 2022-09-05 13:08:52 +02:00 committed by GitHub
parent 3e4b47e60a
commit 746832384a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 20 deletions

View File

@ -6,13 +6,13 @@
# Licensed under either of # Licensed under either of
# Apache License, version 2.0, (LICENSE-APACHEv2) # Apache License, version 2.0, (LICENSE-APACHEv2)
# MIT license (LICENSE-MIT) # MIT license (LICENSE-MIT)
import std/[tables, options, uri, strutils] import std/[tables, uri, strutils]
import stew/[results, base10], httputils import stew/[results, base10], httputils
import ../../asyncloop, ../../asyncsync import ../../asyncloop, ../../asyncsync
import ../../streams/[asyncstream, boundstream, chunkstream] import ../../streams/[asyncstream, boundstream, chunkstream]
import httptable, httpcommon, multipart import httptable, httpcommon, multipart
export asyncloop, asyncsync, httptable, httpcommon, httputils, multipart, export asyncloop, asyncsync, httptable, httpcommon, httputils, multipart,
asyncstream, boundstream, chunkstream, uri, tables, options, results asyncstream, boundstream, chunkstream, uri, tables, results
type type
HttpServerFlags* {.pure.} = enum HttpServerFlags* {.pure.} = enum
@ -88,7 +88,7 @@ type
state*: HttpState state*: HttpState
headers*: HttpTable headers*: HttpTable
query*: HttpTable query*: HttpTable
postTable: Option[HttpTable] postTable: Opt[HttpTable]
rawPath*: string rawPath*: string
uri*: Uri uri*: Uri
scheme*: string scheme*: string
@ -98,9 +98,9 @@ type
transferEncoding*: set[TransferEncodingFlags] transferEncoding*: set[TransferEncodingFlags]
requestFlags*: set[HttpRequestFlags] requestFlags*: set[HttpRequestFlags]
contentLength: int contentLength: int
contentTypeData*: Option[ContentTypeData] contentTypeData*: Opt[ContentTypeData]
connection*: HttpConnectionRef connection*: HttpConnectionRef
response*: Option[HttpResponseRef] response*: Opt[HttpResponseRef]
HttpRequestRef* = ref HttpRequest HttpRequestRef* = ref HttpRequest
@ -211,7 +211,7 @@ proc getResponse*(req: HttpRequestRef): HttpResponseRef {.raises: [Defect].} =
else: else:
{} {}
) )
req.response = some(resp) req.response = Opt.some(resp)
resp resp
else: else:
req.response.get() req.response.get()
@ -351,7 +351,7 @@ proc prepareRequest(conn: HttpConnectionRef,
request.requestFlags.incl(HttpRequestFlags.UrlencodedForm) request.requestFlags.incl(HttpRequestFlags.UrlencodedForm)
elif contentType == MultipartContentType: elif contentType == MultipartContentType:
request.requestFlags.incl(HttpRequestFlags.MultipartForm) request.requestFlags.incl(HttpRequestFlags.MultipartForm)
request.contentTypeData = some(contentType) request.contentTypeData = Opt.some(contentType)
if ExpectHeader in request.headers: if ExpectHeader in request.headers:
let expectHeader = request.headers.getString(ExpectHeader) let expectHeader = request.headers.getString(ExpectHeader)
@ -755,18 +755,18 @@ proc processLoop(server: HttpServerRef, transp: StreamTransport,
break break
breakLoop = false breakLoop = false
var lastErrorCode: Option[HttpCode] var lastErrorCode: Opt[HttpCode]
try: try:
resp = await conn.server.processCallback(arg) resp = await conn.server.processCallback(arg)
except CancelledError: except CancelledError:
breakLoop = true breakLoop = true
except HttpCriticalError as exc: except HttpCriticalError as exc:
lastErrorCode = some(exc.code) lastErrorCode = Opt.some(exc.code)
except HttpRecoverableError as exc: except HttpRecoverableError as exc:
lastErrorCode = some(exc.code) lastErrorCode = Opt.some(exc.code)
except CatchableError: except CatchableError:
lastErrorCode = some(Http503) lastErrorCode = Opt.some(Http503)
if breakLoop: if breakLoop:
break break
@ -983,7 +983,7 @@ proc post*(req: HttpRequestRef): Future[HttpTable] {.async.} =
copyMem(addr strbody[0], addr body[0], len(body)) copyMem(addr strbody[0], addr body[0], len(body))
for key, value in queryParams(strbody, queryFlags): for key, value in queryParams(strbody, queryFlags):
table.add(key, value) table.add(key, value)
req.postTable = some(table) req.postTable = Opt.some(table)
return table return table
elif MultipartForm in req.requestFlags: elif MultipartForm in req.requestFlags:
var table = HttpTable.init() var table = HttpTable.init()
@ -1029,7 +1029,7 @@ proc post*(req: HttpRequestRef): Future[HttpTable] {.async.} =
await mpreader.closeWait() await mpreader.closeWait()
raise exc raise exc
await mpreader.closeWait() await mpreader.closeWait()
req.postTable = some(table) req.postTable = Opt.some(table)
return table return table
else: else:
if HttpRequestFlags.BoundBody in req.requestFlags: if HttpRequestFlags.BoundBody in req.requestFlags:

View File

@ -8,7 +8,7 @@
# Apache License, version 2.0, (LICENSE-APACHEv2) # Apache License, version 2.0, (LICENSE-APACHEv2)
# MIT license (LICENSE-MIT) # MIT license (LICENSE-MIT)
import std/[os, tables, strutils, heapqueue, options, deques, sequtils] import std/[os, tables, strutils, heapqueue, deques, sequtils]
import stew/base10 import stew/base10
import ./srcloc import ./srcloc
export srcloc export srcloc

View File

@ -13,7 +13,7 @@ when (NimMajor, NimMinor) < (1, 4):
else: else:
{.push raises: [].} {.push raises: [].}
import std/[os, tables, strutils, heapqueue, lists, options, nativesockets, net, import std/[os, tables, strutils, heapqueue, lists, nativesockets, net,
deques] deques]
import ./timer import ./timer

View File

@ -14,7 +14,7 @@
## ##
## For stream writing it means that you should write exactly bounded size ## For stream writing it means that you should write exactly bounded size
## of bytes. ## of bytes.
import std/options import stew/results
import ../asyncloop, ../timer import ../asyncloop, ../timer
import asyncstream, ../transports/stream, ../transports/common import asyncstream, ../transports/stream, ../transports/common
export asyncloop, asyncstream, stream, timer, common export asyncloop, asyncstream, stream, timer, common
@ -24,7 +24,7 @@ type
Equal, LessOrEqual Equal, LessOrEqual
BoundedStreamReader* = ref object of AsyncStreamReader BoundedStreamReader* = ref object of AsyncStreamReader
boundSize: Option[uint64] boundSize: Opt[uint64]
boundary: seq[byte] boundary: seq[byte]
offset: uint64 offset: uint64
cmpop: BoundCmp cmpop: BoundCmp
@ -288,7 +288,7 @@ proc init*[T](child: BoundedStreamReader, rsource: AsyncStreamReader,
comparison = BoundCmp.Equal, comparison = BoundCmp.Equal,
bufferSize = BoundedBufferSize, udata: ref T) = bufferSize = BoundedBufferSize, udata: ref T) =
doAssert(len(boundary) > 0, BoundarySizeDefectMessage) doAssert(len(boundary) > 0, BoundarySizeDefectMessage)
child.boundSize = some(boundSize) child.boundSize = Opt.some(boundSize)
child.boundary = @boundary child.boundary = @boundary
child.cmpop = comparison child.cmpop = comparison
init(AsyncStreamReader(child), rsource, boundedReadLoop, bufferSize, init(AsyncStreamReader(child), rsource, boundedReadLoop, bufferSize,
@ -297,7 +297,7 @@ proc init*[T](child: BoundedStreamReader, rsource: AsyncStreamReader,
proc init*(child: BoundedStreamReader, rsource: AsyncStreamReader, proc init*(child: BoundedStreamReader, rsource: AsyncStreamReader,
boundSize: uint64, comparison = BoundCmp.Equal, boundSize: uint64, comparison = BoundCmp.Equal,
bufferSize = BoundedBufferSize) = bufferSize = BoundedBufferSize) =
child.boundSize = some(boundSize) child.boundSize = Opt.some(boundSize)
child.cmpop = comparison child.cmpop = comparison
init(AsyncStreamReader(child), rsource, boundedReadLoop, bufferSize) init(AsyncStreamReader(child), rsource, boundedReadLoop, bufferSize)
@ -313,7 +313,7 @@ proc init*(child: BoundedStreamReader, rsource: AsyncStreamReader,
boundSize: uint64, boundary: openArray[byte], boundSize: uint64, boundary: openArray[byte],
comparison = BoundCmp.Equal, bufferSize = BoundedBufferSize) = comparison = BoundCmp.Equal, bufferSize = BoundedBufferSize) =
doAssert(len(boundary) > 0, BoundarySizeDefectMessage) doAssert(len(boundary) > 0, BoundarySizeDefectMessage)
child.boundSize = some(boundSize) child.boundSize = Opt.some(boundSize)
child.boundary = @boundary child.boundary = @boundary
child.cmpop = comparison child.cmpop = comparison
init(AsyncStreamReader(child), rsource, boundedReadLoop, bufferSize) init(AsyncStreamReader(child), rsource, boundedReadLoop, bufferSize)