From adae963751ac9c7cc193bc7b65be0ce241cdb0c2 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 25 Jan 2018 18:43:32 +1100 Subject: [PATCH] ensure we do not override charset for content type --- lib/hijack.rb | 2 +- spec/components/hijack_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/hijack.rb b/lib/hijack.rb index 51a4659591e..7e942c58ee1 100644 --- a/lib/hijack.rb +++ b/lib/hijack.rb @@ -69,8 +69,8 @@ module Hijack Discourse::Cors.apply_headers(cors_origins, env, headers) end + headers['Content-Type'] ||= response.content_type || "text/plain" headers['Content-Length'] = body.bytesize - headers['Content-Type'] = response.content_type || "text/plain" headers['Connection'] = "close" status_string = Rack::Utils::HTTP_STATUS_CODES[response.status.to_i] || "Unknown" diff --git a/spec/components/hijack_spec.rb b/spec/components/hijack_spec.rb index 7d3c0c3ad85..0a8b44eeee0 100644 --- a/spec/components/hijack_spec.rb +++ b/spec/components/hijack_spec.rb @@ -157,7 +157,7 @@ describe Hijack do redirect_to 'http://awesome.com' end - result = "HTTP/1.1 302 Found\r\nLocation: http://awesome.com\r\nContent-Type: text/html\r\nContent-Length: 84\r\nConnection: close\r\nX-Runtime: 1.000000\r\n\r\nYou are being redirected." + result = "HTTP/1.1 302 Found\r\nLocation: http://awesome.com\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: 84\r\nConnection: close\r\nX-Runtime: 1.000000\r\n\r\nYou are being redirected." expect(tester.io.string).to eq(result) end @@ -168,7 +168,7 @@ describe Hijack do render body: nil end - result = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 0\r\nConnection: close\r\nX-Runtime: 1.000000\r\n\r\n" + result = "HTTP/1.1 200 OK\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: 0\r\nConnection: close\r\nX-Runtime: 1.000000\r\n\r\n" expect(tester.io.string).to eq(result) end @@ -179,7 +179,7 @@ describe Hijack do render plain: "hello world" end - result = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 11\r\nConnection: close\r\nX-Runtime: 1.000000\r\n\r\nhello world" + result = "HTTP/1.1 200 OK\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: 11\r\nConnection: close\r\nX-Runtime: 1.000000\r\n\r\nhello world" expect(tester.io.string).to eq(result) end @@ -187,7 +187,7 @@ describe Hijack do Process.stubs(:clock_gettime).returns(1.0) tester.hijack_test - expected = "HTTP/1.1 500 Internal Server Error\r\nContent-Type: text/html\r\nContent-Length: 0\r\nConnection: close\r\nX-Runtime: 0.000000\r\n\r\n" + expected = "HTTP/1.1 500 Internal Server Error\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: 0\r\nConnection: close\r\nX-Runtime: 0.000000\r\n\r\n" expect(tester.io.string).to eq(expected) end