Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http resource: properly support HEAD request with remote worker #2340

Merged
merged 1 commit into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/resources/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,17 @@ def run_curl
end

def curl_command # rubocop:disable Metrics/AbcSize
cmd = ["curl -i -X #{http_method}"]
cmd = ['curl -i']

# Use curl's --head option when the method requested is HEAD. Otherwise,
# the user may experience a timeout when curl does not properly close
# the connection after the response is received.
if http_method.casecmp('HEAD') == 0
cmd << '--head'
else
cmd << "-X #{http_method}"
end

cmd << "--connect-timeout #{open_timeout}"
cmd << "--max-time #{open_timeout+read_timeout}"
cmd << "--user \'#{username}:#{password}\'" unless username.nil? || password.nil?
Expand Down
1 change: 1 addition & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def md.directory?
'f77ebcedaf6fbe8f02d2f9d4735a90c12311d2ca4b43ece9efa2f2e396491747' => cmd.call('http-remote-post'),
"curl -i -X GET --connect-timeout 60 --max-time 120 -H 'accept: application/json' -H 'foo: bar' 'http://www.example.com'" => cmd.call('http-remote-headers'),
"curl -i -X GET --connect-timeout 60 --max-time 120 'http://www.example.com?a=b&c=d'" => cmd.call('http-remote-params'),
"curl -i --head --connect-timeout 60 --max-time 120 'http://www.example.com'" => cmd.call('http-remote-head-request'),

# elasticsearch resource
"curl -H 'Content-Type: application/json' http://localhost:9200/_nodes" => cmd.call('elasticsearch-cluster-nodes-default'),
Expand Down
10 changes: 10 additions & 0 deletions test/unit/mock/cmd/http-remote-head-request
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Mon, 27 Nov 2017 16:46:15 GMT
Expires: Wed, 27 Dec 2017 16:46:15 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
9 changes: 9 additions & 0 deletions test/unit/resources/http_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,14 @@
_(worker.body).must_equal 'params ok'
end
end

describe 'a HEAD request' do
let(:http_method) { 'HEAD' }

it 'returns correct data' do
_(worker.status).must_equal 301
_(worker.response_headers['Location']).must_equal 'http://www.google.com/'
end
end
end
end