Chrome ERR_INVALID_RESPONSE on unauthorized Git archive download
Zendesk: https://gitlab.zendesk.com/agent/tickets/15148
Previous issue: https://gitlab.com/gitlab-org/gitlab-workhorse/issues/23
When trying to visit a link to an archive download in Chrome for a project that the I have no access to I see an unfriendly Chrome error page.
My best guess why this happens is because of an incorrect Content-Type header on the response.
% curl -v 'http://localhost:3000/root/grrr/repository/archive.zip?ref=master'
* Trying ::1...
* connect to ::1 port 3000 failed: Connection refused
* Trying fe80::1...
* connect to fe80::1 port 3000 failed: Connection refused
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET /root/grrr/repository/archive.zip?ref=master HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< Cache-Control: no-cache
< Content-Type: application/zip; charset=utf-8
< Date: Tue, 02 Feb 2016 10:20:09 GMT
< Status: 401 Unauthorized
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-Request-Id: f90f8c27-bada-4621-ba8b-533ba315562a
< X-Runtime: 0.074683
< X-Xss-Protection: 1; mode=block
< Content-Length: 49
<
* Connection #0 to host localhost left intact
You need to sign in or sign up before continuing.%
Note that the content-type is 'application/zip' but the response body is plain text.
It seems that the 401 response is generated by Devise. I have tried using http://stackoverflow.com/a/18792108 to modify the content-type but my special after_action in SessionsController never got called.
Devise has an interesting test case that might explain what is happening: https://github.com/plataformatec/devise/blob/dd5de829c944dd955e4b35074c60798c3ad4b947/test/integration/http_authenticatable_test.rb#L41
test 'uses the request format as response content type' do
sign_in_as_new_user_with_http("unknown")
assert_equal 401, status
assert_equal "application/xml; charset=utf-8", headers["Content-Type"]
assert_match "<error>Invalid email or password.</error>", response.body
end
I think the actual behavior is happening in https://github.com/plataformatec/devise/blob/v3.5.4/lib/devise/failure_app.rb (the Devise 'failure app').
At the moment it is unclear to me how to override the self.content_type = request.format.to_s
behavior of Devise.
cc @patricio