ensure we do not override charset for content type

This commit is contained in:
Sam 2018-01-25 18:43:32 +11:00
parent afaf9fd54c
commit adae963751
2 changed files with 5 additions and 5 deletions

View File

@ -69,8 +69,8 @@ module Hijack
Discourse::Cors.apply_headers(cors_origins, env, headers) Discourse::Cors.apply_headers(cors_origins, env, headers)
end end
headers['Content-Type'] ||= response.content_type || "text/plain"
headers['Content-Length'] = body.bytesize headers['Content-Length'] = body.bytesize
headers['Content-Type'] = response.content_type || "text/plain"
headers['Connection'] = "close" headers['Connection'] = "close"
status_string = Rack::Utils::HTTP_STATUS_CODES[response.status.to_i] || "Unknown" status_string = Rack::Utils::HTTP_STATUS_CODES[response.status.to_i] || "Unknown"

View File

@ -157,7 +157,7 @@ describe Hijack do
redirect_to 'http://awesome.com' redirect_to 'http://awesome.com'
end 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) expect(tester.io.string).to eq(result)
end end
@ -168,7 +168,7 @@ describe Hijack do
render body: nil render body: nil
end 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) expect(tester.io.string).to eq(result)
end end
@ -179,7 +179,7 @@ describe Hijack do
render plain: "hello world" render plain: "hello world"
end 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) expect(tester.io.string).to eq(result)
end end
@ -187,7 +187,7 @@ describe Hijack do
Process.stubs(:clock_gettime).returns(1.0) Process.stubs(:clock_gettime).returns(1.0)
tester.hijack_test 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) expect(tester.io.string).to eq(expected)
end end