include a timeout on WebApiManager requests

This commit is contained in:
Brian Gough 2016-04-13 16:30:20 +01:00
parent a55b72871f
commit 6e5eadfa86
2 changed files with 7 additions and 3 deletions

View file

@ -2,6 +2,9 @@ request = require "request"
logger = require "logger-sharelatex"
Settings = require "settings-sharelatex"
# Don't let HTTP calls hang for a long time
MAX_HTTP_REQUEST_LENGTH = 15000 # 15 seconds
# DEPRECATED! This method of getting user details via track-changes is deprecated
# in the way we lay out our services.
# Instead, web should be responsible for collecting the raw data (user_ids) and
@ -11,6 +14,7 @@ module.exports = WebApiManager =
sendRequest: (url, callback = (error, body) ->) ->
request.get {
url: "#{Settings.apis.web.url}#{url}"
timeout: MAX_HTTP_REQUEST_LENGTH
auth:
user: Settings.apis.web.user
pass: Settings.apis.web.pass

View file

@ -37,7 +37,7 @@ describe "WebApiManager", ->
it 'should get the user from the web api', ->
@request.get
.calledWith({
.calledWithMatch({
url: "#{@settings.apis.web.url}/user/#{@user_id}/personal_info"
auth:
user: @settings.apis.web.user
@ -92,7 +92,7 @@ describe "WebApiManager", ->
it 'should get the project from the web api', ->
@request.get
.calledWith({
.calledWithMatch({
url: "#{@settings.apis.web.url}/project/#{@project_id}/details"
auth:
user: @settings.apis.web.user
@ -120,4 +120,4 @@ describe "WebApiManager", ->
it "should return the callback with an error", ->
@callback
.calledWith(new Error("web returned failure status code: 500"))
.should.equal true
.should.equal true