Commit fefab474569f231676a4fd1579a70723d729f206

Authored by Dmitry Medvinsky
1 parent c0090a3f

Fix `/:username.keys` response content type

Currently this method responds with `text/html`. It is kind of unusable
if you open it in a browser. The browser thinks it is HTML and renders
it as HTML, meaning new lines are dropped. So it's very hard to
distinguish where the key starts and where it ends.

This commit changes the content type header to `text/plain`.
CHANGELOG
... ... @@ -29,6 +29,7 @@ v 6.7.0
29 29 - Better API responses for access_levels (sponsored by O'Reilly Media)
30 30 - Requires at least 2 unicorn workers
31 31 - Requires gitlab-shell v1.9+
  32 + - Fix `/:username.keys` response content type (Dmitry Medvinsky)
32 33  
33 34 v 6.6.5
34 35 - Added option to remove issue assignee on project issue page and issue edit page (Jason Blanchard)
... ...
app/controllers/profiles/keys_controller.rb
... ... @@ -41,7 +41,7 @@ class Profiles::KeysController < ApplicationController
41 41 begin
42 42 user = User.find_by_username(params[:username])
43 43 if user.present?
44   - render text: user.all_ssh_keys.join("\n")
  44 + render text: user.all_ssh_keys.join("\n"), content_type: "text/plain"
45 45 else
46 46 render_404 and return
47 47 end
... ...
spec/controllers/profile_keys_controller_spec.rb
... ... @@ -24,6 +24,11 @@ describe Profiles::KeysController do
24 24  
25 25 expect(response.body).to eq("")
26 26 end
  27 +
  28 + it "should respond with text/plain content type" do
  29 + get :get_keys, username: user.username
  30 + expect(response.content_type).to eq("text/plain")
  31 + end
27 32 end
28 33  
29 34 describe "user with keys" do
... ... @@ -44,6 +49,11 @@ describe Profiles::KeysController do
44 49 expect(response.body).not_to eq("")
45 50 expect(response.body).to eq(user.all_ssh_keys.join("\n"))
46 51 end
  52 +
  53 + it "should respond with text/plain content type" do
  54 + get :get_keys, username: user.username
  55 + expect(response.content_type).to eq("text/plain")
  56 + end
47 57 end
48 58 end
49 59 end
... ...