Reputation: 55
I'd like to return json(string) for http HEAD method on sinatra.
But It seems that sinatra doesn't return any response body for HEAD requests.
I tried this code.
require 'sinatra' head "/" do "HEAD" end
And I did curl -X HEAD 'http://localhost:4567/'
.
But the command doesn't return for a while and finally throws a error below.
$ curl -X HEAD 'http://localhost:4567/' curl: (18) transfer closed with 5 bytes remaining to read
Upvotes: 0
Views: 1081
Reputation: 4986
That is a perfectly valid Sinatra head
route. The problem is with your curl statement.
curl -X HEAD 'http://localhost:4567/'
-X HEAD is not what you want; it will not print headers and will expect some specification of expected bytes transmission stated in Content-Length.
Instead you want the following.
curl -I http://localhost:4567/
Upvotes: 2