Skip to content

Commit

Permalink
revert request buffer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Dec 10, 2023
1 parent e755c5a commit ad5aac4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/scorper/http/streamserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ when defined(windows):
import winlean
const MethodNeedsBody = {HttpPost, HttpPut, HttpConnect, HttpPatch}

var buf {.global.}: array[HttpRequestBufferSize, char]

type
ImpRequest = ref object of typeof(Request()[])
transp: StreamTransport
buf: array[HttpRequestBufferSize, char]
contentLength: BiggestUInt # as RFC no limit
contentType: string
server: Scorper
Expand Down Expand Up @@ -586,7 +585,7 @@ proc form*(req: ImpRequest): Future[Form] {.async.} =
result = newForm()
case req.contentType:
of "application/x-www-form-urlencoded":
var parser = newUrlEncodedParser(req.transp, buf.addr, req.contentLength.int)
var parser = newUrlEncodedParser(req.transp, req.buf.addr, req.contentLength.int)
var parsed = await parser.parse()
for (key, value) in parsed:
let v = if value.len > 0: decodeUrlComponent(value) else: ""
Expand All @@ -603,7 +602,7 @@ proc form*(req: ImpRequest): Future[Form] {.async.} =
except BoundaryInvalidError as e:
await req.respError(Http400, e.msg)
return
var parser = newMultipartParser(parsed.boundary, req.transp, buf.addr, req.contentLength.int)
var parser = newMultipartParser(parsed.boundary, req.transp, req.buf.addr, req.contentLength.int)
try:
await parser.parse()
except BodyIncompleteError as e:
Expand Down Expand Up @@ -684,7 +683,7 @@ proc processRequest(
const HeaderSep = @[byte('\c'), byte('\L'), byte('\c'), byte('\L')]
var count: int
try:
count = await req.reader.readUntil(buf[0].addr, len(buf), sep = HeaderSep)
count = await req.reader.readUntil(req.buf[0].addr, len(req.buf), sep = HeaderSep)
except AsyncStreamIncompleteError:
return true
except AsyncStreamLimitError:
Expand All @@ -694,7 +693,7 @@ proc processRequest(
await req.respStatus(Http400, e.msg)
return false
# Headers
let headerEnd = scorper.httpParser.parseHeader(addr buf[0], buf.len)
let headerEnd = scorper.httpParser.parseHeader(addr req.buf[0], req.buf.len)
if headerEnd == -1:
await req.respError(Http400)
return true
Expand Down

0 comments on commit ad5aac4

Please sign in to comment.