mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
check total size of lines, rather than content-length
This commit is contained in:
parent
210a61112b
commit
82d5a7fafd
2 changed files with 13 additions and 3 deletions
|
@ -30,14 +30,21 @@ module.exports = HttpController =
|
||||||
version: version
|
version: version
|
||||||
ops: ops
|
ops: ops
|
||||||
|
|
||||||
|
_getTotalSizeOfLines: (lines) ->
|
||||||
|
size = 0
|
||||||
|
for line in lines
|
||||||
|
size += line.length
|
||||||
|
return size
|
||||||
|
|
||||||
setDoc: (req, res, next = (error) ->) ->
|
setDoc: (req, res, next = (error) ->) ->
|
||||||
doc_id = req.params.doc_id
|
doc_id = req.params.doc_id
|
||||||
project_id = req.params.project_id
|
project_id = req.params.project_id
|
||||||
lines = req.body.lines
|
lines = req.body.lines
|
||||||
source = req.body.source
|
source = req.body.source
|
||||||
user_id = req.body.user_id
|
user_id = req.body.user_id
|
||||||
if req.headers['content-length'] > TWO_MEGABYTES
|
lineSize = HttpController._getTotalSizeOfLines(lines)
|
||||||
logger.log {project_id, doc_id, source, user_id}, "document too large, returning 406 response"
|
if lineSize > TWO_MEGABYTES
|
||||||
|
logger.log {project_id, doc_id, source, lineSize, user_id}, "document too large, returning 406 response"
|
||||||
return res.send 406
|
return res.send 406
|
||||||
logger.log project_id: project_id, doc_id: doc_id, lines: lines, source: source, user_id: user_id, "setting doc via http"
|
logger.log project_id: project_id, doc_id: doc_id, lines: lines, source: source, user_id: user_id, "setting doc via http"
|
||||||
timer = new Metrics.Timer("http.setDoc")
|
timer = new Metrics.Timer("http.setDoc")
|
||||||
|
|
|
@ -69,7 +69,10 @@ describe "HttpController.setDoc", ->
|
||||||
|
|
||||||
describe "when the payload is too large", ->
|
describe "when the payload is too large", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@req.headers['content-length'] = 40 * 1024 * 1024
|
lines = []
|
||||||
|
for _ in [0..300000]
|
||||||
|
lines.push "test test test"
|
||||||
|
@req.body.lines = lines
|
||||||
@DocumentManager.setDocWithLock = sinon.stub().callsArgWith(5)
|
@DocumentManager.setDocWithLock = sinon.stub().callsArgWith(5)
|
||||||
@HttpController.setDoc(@req, @res, @next)
|
@HttpController.setDoc(@req, @res, @next)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue