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

View File

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

View File

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

View File

@ -97,6 +97,9 @@ const
chronosStreamDefaultBufferSize* {.intdefine.} = 16384
## Default size of chronos async stream internal buffer.
chronosTLSSessionCacheBufferSize* {.intdefine.} = 4096
## Default size of chronos TLS Session cache's internal buffer.
when defined(chronosStrictException):
{.warning: "-d:chronosStrictException has been deprecated in favor of handleException".}
# In chronos v3, this setting was used as the opposite of
@ -123,6 +126,8 @@ when defined(debug) or defined(chronosConfig):
chronosTransportDefaultBufferSize)
printOption("chronosStreamDefaultBufferSize",
chronosStreamDefaultBufferSize)
printOption("chronosTLSSessionCacheBufferSize",
chronosTLSSessionCacheBufferSize)
# 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

View File

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

View File

@ -11,13 +11,13 @@
{.push raises: [].}
import ../asyncloop, ../timer
import asyncstream, ../transports/stream, ../transports/common
import ../[asyncloop, timer, config]
import asyncstream, ../transports/[stream, common]
import results
export asyncloop, asyncstream, stream, timer, common, results
const
ChunkBufferSize = 4096
ChunkBufferSize = chronosStreamDefaultBufferSize
MaxChunkHeaderSize = 1024
ChunkHeaderValueSize = 8
# 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/certs/cacert
import ".."/[asyncloop, asyncsync, config, timer]
import asyncstream, ../transports/stream, ../transports/common
import asyncstream, ../transports/[stream, common]
export asyncloop, asyncsync, timer, asyncstream
const
TLSSessionCacheBufferSize* = chronosTLSSessionCacheBufferSize
type
TLSStreamKind {.pure.} = enum
Client, Server
@ -777,11 +780,12 @@ proc init*(tt: typedesc[TLSCertificate],
raiseTLSStreamProtocolError("Could not find any certificates")
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``.
##
## 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))
sslSessionCacheLruInit(addr res.context, addr res.storage[0], rsize)
res