From fec5e1a2dc0ad772976630c3d128bdae3a6977f3 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 19 Oct 2016 12:06:39 -0700 Subject: [PATCH] [elasticsearch/proxy] use different code path with erorr --- .../elasticsearch/lib/create_proxy.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core_plugins/elasticsearch/lib/create_proxy.js b/src/core_plugins/elasticsearch/lib/create_proxy.js index 44490ca5720d8..068712ca9c70f 100644 --- a/src/core_plugins/elasticsearch/lib/create_proxy.js +++ b/src/core_plugins/elasticsearch/lib/create_proxy.js @@ -20,14 +20,17 @@ function createProxy(server, method, route, config) { xforward: true, timeout: server.config().get('elasticsearch.requestTimeout'), onResponse: function (err, responseFromUpstream, request, reply) { - const upstreamLocation = responseFromUpstream.headers.location; - const response = reply(err, responseFromUpstream); + if (err) { + reply(err); + return; + } - // Workaround for #8705 until hapi has been updated to >= 15.0.0 - if (upstreamLocation) { - delete responseFromUpstream.headers.location; - response.location(encodeURI(upstreamLocation)); + if (responseFromUpstream.headers.location) { + // TODO: Workaround for #8705 until hapi has been updated to >= 15.0.0 + responseFromUpstream.headers.location = encodeURI(responseFromUpstream.headers.location); } + + reply(null, responseFromUpstream); } } },