A platform for community discussion. Free, open, simple.
ensure we do not override charset for content type
Samadae963751ac
diff --git a/lib/hijack.rb b/lib/hijack.rbindex 51a4659591e..7e942c58ee1 100644--- a/lib/hijack.rb+++ b/lib/hijack.rb@@ -69,8 +69,8 @@ module HijackDiscourse::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.rbindex 7d3c0c3ad85..0a8b44eeee0 100644--- a/spec/components/hijack_spec.rb+++ b/spec/components/hijack_spec.rb@@ -157,7 +157,7 @@ describe Hijack doredirect_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\n<html><body>You are being <a href=\"http://awesome.com\">redirected</a>.</body></html>"+ 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\n<html><body>You are being <a href=\"http://awesome.com\">redirected</a>.</body></html>"expect(tester.io.string).to eq(result)end@@ -168,7 +168,7 @@ describe Hijack dorender body: nilend- 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 dorender 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 doProcess.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