Add missing parts of defaults buffer size increase. (#513)

This commit is contained in:
Eugene Kabanov 2024-03-06 01:56:40 +02:00 committed by GitHub
parent 4ed0cd6be7
commit f6c7ecfa0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 30 additions and 19 deletions

View File

@ -11,7 +11,7 @@
import std/[tables, uri, strutils] import std/[tables, uri, strutils]
import stew/[base10], httputils, results import stew/[base10], httputils, results
import ../../[asyncloop, asyncsync] import ../../[asyncloop, asyncsync, config]
import ../../streams/[asyncstream, boundstream, chunkstream] import ../../streams/[asyncstream, boundstream, chunkstream]
import "."/[httptable, httpcommon, multipart] import "."/[httptable, httpcommon, multipart]
from ../../transports/common import TransportAddress, ServerFlags, `$`, `==` from ../../transports/common import TransportAddress, ServerFlags, `$`, `==`
@ -244,7 +244,7 @@ proc new*(
serverUri = Uri(), serverUri = Uri(),
serverIdent = "", serverIdent = "",
maxConnections: int = -1, maxConnections: int = -1,
bufferSize: int = 4096, bufferSize: int = chronosTransportDefaultBufferSize,
backlogSize: int = DefaultBacklogSize, backlogSize: int = DefaultBacklogSize,
httpHeadersTimeout = 10.seconds, httpHeadersTimeout = 10.seconds,
maxHeadersSize: int = 8192, maxHeadersSize: int = 8192,
@ -304,7 +304,7 @@ proc new*(
serverUri = Uri(), serverUri = Uri(),
serverIdent = "", serverIdent = "",
maxConnections: int = -1, maxConnections: int = -1,
bufferSize: int = 4096, bufferSize: int = chronosTransportDefaultBufferSize,
backlogSize: int = DefaultBacklogSize, backlogSize: int = DefaultBacklogSize,
httpHeadersTimeout = 10.seconds, httpHeadersTimeout = 10.seconds,
maxHeadersSize: int = 8192, maxHeadersSize: int = 8192,

View File

@ -20,6 +20,7 @@ export asyncloop, httptable, httpcommon, httpbodyrw, asyncstream, httputils
const const
UnableToReadMultipartBody = "Unable to read multipart message body, reason: " UnableToReadMultipartBody = "Unable to read multipart message body, reason: "
UnableToSendMultipartMessage = "Unable to send multipart message, reason: " UnableToSendMultipartMessage = "Unable to send multipart message, reason: "
MaxMultipartHeaderSize = 4096
type type
MultiPartSource* {.pure.} = enum MultiPartSource* {.pure.} = enum
@ -142,10 +143,11 @@ proc init*[A: BChar, B: BChar](mpt: typedesc[MultiPartReader],
MultiPartReader(kind: MultiPartSource.Buffer, MultiPartReader(kind: MultiPartSource.Buffer,
buffer: buf, offset: 0, boundary: fboundary) buffer: buf, offset: 0, boundary: fboundary)
proc new*[B: BChar](mpt: typedesc[MultiPartReaderRef], proc new*[B: BChar](
stream: HttpBodyReader, mpt: typedesc[MultiPartReaderRef],
boundary: openArray[B], stream: HttpBodyReader,
partHeadersMaxSize = 4096): MultiPartReaderRef = boundary: openArray[B],
partHeadersMaxSize = MaxMultipartHeaderSize): MultiPartReaderRef =
## Create new MultiPartReader instance with `stream` interface. ## Create new MultiPartReader instance with `stream` interface.
## ##
## ``stream`` is stream used to read data. ## ``stream`` is stream used to read data.

View File

@ -10,7 +10,7 @@
{.push raises: [].} {.push raises: [].}
import httpserver import httpserver
import ../../asyncloop, ../../asyncsync import ../../[asyncloop, asyncsync, config]
import ../../streams/[asyncstream, tlsstream] import ../../streams/[asyncstream, tlsstream]
export asyncloop, asyncsync, httpserver, asyncstream, tlsstream export asyncloop, asyncsync, httpserver, asyncstream, tlsstream
@ -91,7 +91,7 @@ proc new*(htype: typedesc[SecureHttpServerRef],
serverIdent = "", serverIdent = "",
secureFlags: set[TLSFlags] = {}, secureFlags: set[TLSFlags] = {},
maxConnections: int = -1, maxConnections: int = -1,
bufferSize: int = 4096, bufferSize: int = chronosTransportDefaultBufferSize,
backlogSize: int = DefaultBacklogSize, backlogSize: int = DefaultBacklogSize,
httpHeadersTimeout = 10.seconds, httpHeadersTimeout = 10.seconds,
maxHeadersSize: int = 8192, maxHeadersSize: int = 8192,
@ -157,7 +157,7 @@ proc new*(htype: typedesc[SecureHttpServerRef],
serverIdent = "", serverIdent = "",
secureFlags: set[TLSFlags] = {}, secureFlags: set[TLSFlags] = {},
maxConnections: int = -1, maxConnections: int = -1,
bufferSize: int = 4096, bufferSize: int = chronosTransportDefaultBufferSize,
backlogSize: int = DefaultBacklogSize, backlogSize: int = DefaultBacklogSize,
httpHeadersTimeout = 10.seconds, httpHeadersTimeout = 10.seconds,
maxHeadersSize: int = 8192, maxHeadersSize: int = 8192,

View File

@ -97,6 +97,9 @@ const
chronosStreamDefaultBufferSize* {.intdefine.} = 16384 chronosStreamDefaultBufferSize* {.intdefine.} = 16384
## Default size of chronos async stream internal buffer. ## Default size of chronos async stream internal buffer.
chronosTLSSessionCacheBufferSize* {.intdefine.} = 4096
## Default size of chronos TLS Session cache's internal buffer.
when defined(chronosStrictException): when defined(chronosStrictException):
{.warning: "-d:chronosStrictException has been deprecated in favor of handleException".} {.warning: "-d:chronosStrictException has been deprecated in favor of handleException".}
# In chronos v3, this setting was used as the opposite of # In chronos v3, this setting was used as the opposite of
@ -123,6 +126,8 @@ when defined(debug) or defined(chronosConfig):
chronosTransportDefaultBufferSize) chronosTransportDefaultBufferSize)
printOption("chronosStreamDefaultBufferSize", printOption("chronosStreamDefaultBufferSize",
chronosStreamDefaultBufferSize) chronosStreamDefaultBufferSize)
printOption("chronosTLSSessionCacheBufferSize",
chronosTLSSessionCacheBufferSize)
# In nim 1.6, `sink` + local variable + `move` generates the best code for # In nim 1.6, `sink` + local variable + `move` generates the best code for
# moving a proc parameter into a closure - this only works for closure # moving a proc parameter into a closure - this only works for closure

View File

@ -18,8 +18,8 @@
{.push raises: [].} {.push raises: [].}
import results import results
import ../asyncloop, ../timer import ../[asyncloop, timer, config]
import asyncstream, ../transports/stream, ../transports/common import asyncstream, ../transports/[stream, common]
export asyncloop, asyncstream, stream, timer, common export asyncloop, asyncstream, stream, timer, common
type type
@ -44,7 +44,7 @@ type
BoundedStreamRW* = BoundedStreamReader | BoundedStreamWriter BoundedStreamRW* = BoundedStreamReader | BoundedStreamWriter
const const
BoundedBufferSize* = 4096 BoundedBufferSize* = chronosStreamDefaultBufferSize
BoundarySizeDefectMessage = "Boundary must not be empty array" BoundarySizeDefectMessage = "Boundary must not be empty array"
template newBoundedStreamIncompleteError(): ref BoundedStreamError = template newBoundedStreamIncompleteError(): ref BoundedStreamError =

View File

@ -11,13 +11,13 @@
{.push raises: [].} {.push raises: [].}
import ../asyncloop, ../timer import ../[asyncloop, timer, config]
import asyncstream, ../transports/stream, ../transports/common import asyncstream, ../transports/[stream, common]
import results import results
export asyncloop, asyncstream, stream, timer, common, results export asyncloop, asyncstream, stream, timer, common, results
const const
ChunkBufferSize = 4096 ChunkBufferSize = chronosStreamDefaultBufferSize
MaxChunkHeaderSize = 1024 MaxChunkHeaderSize = 1024
ChunkHeaderValueSize = 8 ChunkHeaderValueSize = 8
# This is limit for chunk size to 8 hexadecimal digits, so maximum # This is limit for chunk size to 8 hexadecimal digits, so maximum

View File

@ -16,9 +16,12 @@ import
bearssl/[brssl, ec, errors, pem, rsa, ssl, x509], bearssl/[brssl, ec, errors, pem, rsa, ssl, x509],
bearssl/certs/cacert bearssl/certs/cacert
import ".."/[asyncloop, asyncsync, config, timer] import ".."/[asyncloop, asyncsync, config, timer]
import asyncstream, ../transports/stream, ../transports/common import asyncstream, ../transports/[stream, common]
export asyncloop, asyncsync, timer, asyncstream export asyncloop, asyncsync, timer, asyncstream
const
TLSSessionCacheBufferSize* = chronosTLSSessionCacheBufferSize
type type
TLSStreamKind {.pure.} = enum TLSStreamKind {.pure.} = enum
Client, Server Client, Server
@ -777,11 +780,12 @@ proc init*(tt: typedesc[TLSCertificate],
raiseTLSStreamProtocolError("Could not find any certificates") raiseTLSStreamProtocolError("Could not find any certificates")
res res
proc init*(tt: typedesc[TLSSessionCache], size: int = 4096): TLSSessionCache = proc init*(tt: typedesc[TLSSessionCache],
size: int = TLSSessionCacheBufferSize): TLSSessionCache =
## Create new TLS session cache with size ``size``. ## Create new TLS session cache with size ``size``.
## ##
## One cached item is near 100 bytes size. ## One cached item is near 100 bytes size.
var rsize = min(size, 4096) let rsize = min(size, 4096)
var res = TLSSessionCache(storage: newSeq[byte](rsize)) var res = TLSSessionCache(storage: newSeq[byte](rsize))
sslSessionCacheLruInit(addr res.context, addr res.storage[0], rsize) sslSessionCacheLruInit(addr res.context, addr res.storage[0], rsize)
res res