Skip to content

Commit

Permalink
do not send 502 on failed websocket, just send back ECONNRESET
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Jul 29, 2019
1 parent ae5def7 commit 26c701a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
15 changes: 2 additions & 13 deletions packages/server/lib/server.coffee
Expand Up @@ -644,22 +644,11 @@ class Server
socket.end = ->
socket.end = end

response = [
"HTTP/#{req.httpVersion} 502 #{statusCode.getText(502)}"
"X-Cypress-Proxy-Error-Message: #{err.message}"
"X-Cypress-Proxy-Error-Code: #{err.code}"
].join("\r\n") + "\r\n\r\n"

proxiedUrl = "#{protocol}//#{hostname}:#{port}"

debug(
"Got ERROR proxying websocket connection to url: '%s' received error: '%s' with code '%s'",
proxiedUrl,
err.toString()
err.code
"Got ERROR proxying websocket connection to url: received error %o", { err },
)

socket.end(response)
socket.end()

proxy.ws(req, socket, head, {
secure: false
Expand Down
10 changes: 4 additions & 6 deletions packages/server/test/integration/websockets_spec.coffee
Expand Up @@ -59,7 +59,7 @@ describe "Web Sockets", ->
expect(err.code).to.eq("ECONNRESET")
done()

it "sends back 502 Bad Gateway when error upgrading", (done) ->
it "sends back ECONNRESET when error upgrading", (done) ->
agent = new httpsAgent("http://localhost:#{cyPort}")

@server._onDomainSet("http://localhost:#{otherPort}")
Expand All @@ -68,11 +68,9 @@ describe "Web Sockets", ->
agent: agent
})

client.on "unexpected-response", (req, res) ->
expect(res.statusCode).to.eq(502)
expect(res.statusMessage).to.eq("Bad Gateway")
expect(res.headers).to.have.property("x-cypress-proxy-error-message")
expect(res.headers).to.have.property("x-cypress-proxy-error-code")
client.on "error", (err) ->
expect(err.code).to.eq('ECONNRESET')
expect(err.message).to.eq('socket hang up')

done()

Expand Down

0 comments on commit 26c701a

Please sign in to comment.