Using buffers to get request body
This commit is contained in:
1 parent
75a3c91bc4
commit
e5d1a97375
1 file changed
+17
-3
+17
-3
@@ -124,15 +124,29 @@ else
|
|||||||
response.end('405 Method Not Allowed')
|
response.end('405 Method Not Allowed')
|
||||||
return
|
return
|
||||||
|
|
||||||
request.content = ''
|
chunks = []
|
||||||
|
bytes = 0
|
||||||
cookies = {}
|
cookies = {}
|
||||||
|
|
||||||
request.addListener 'data', (chunk) ->
|
request.addListener 'data', (chunk) ->
|
||||||
request.content += chunk
|
chunks.push(chunk)
|
||||||
|
bytes += chunk.length
|
||||||
|
|
||||||
|
request.getBody = (encoding) ->
|
||||||
|
# Write all chunks into a Buffer
|
||||||
|
body = new Buffer(bytes)
|
||||||
|
offset = 0
|
||||||
|
chunks.forEach((chunk) ->
|
||||||
|
chunk.copy(body, offset, 0, chunk.length)
|
||||||
|
offset += chunk.length
|
||||||
|
)
|
||||||
|
|
||||||
|
#Return encoded (default to UTF8) string
|
||||||
|
return body.toString(encoding || 'utf8', 0, body.byteLength)
|
||||||
|
|
||||||
request.addListener 'end', () ->
|
request.addListener 'end', () ->
|
||||||
resParams = {}
|
resParams = {}
|
||||||
reqParams = tr069.request(request.headers, request.content)
|
reqParams = tr069.request(request.headers, request.getBody())
|
||||||
|
|
||||||
if reqParams.inform
|
if reqParams.inform
|
||||||
resParams.inform = true
|
resParams.inform = true
|
||||||
|
|||||||
Reference in new issue
Block a user