Ruby and net / http request without content
I am trying to make a call to a Tika server using Net :: HTTP :: Put. The problem is the call always passes Content-Type
, which makes Tika fire detectors (which is what I need) and then throttles by default Content-Type
application/x-www-form-urlencoded
. The Tika docs suggest not to use this.
So, I have the following:
require 'net/http'
port = 9998
host = "localhost"
path = "/meta"
req = Net::HTTP::Put.new(path)
req.body_stream = File.open(file_name)
req['Transfer-Encoding'] = 'chunked'
req['Accept'] = 'application/json'
response = Net::HTTP.new(host, port).start { |http|
http.request(req)
}
I tried add req.delete('content-type')
and install in initheaders = {}
various ways, but by default Content-Type
keeps getting sent messages.
Any ideas would be greatly appreciated as I would rather avoid having to make multiple swirl calls ... is there a way to suppress sending this header by default?
source to share
If you install req['Content-Type'] = nil
then Net :: HTTP will set it as default for "application / x-www-form-urlencoded", but if you set it to an empty string, Net :: HTTP will leave it alone:
req['Content-Type'] = ''
Tika should see this as an invalid type and enable detectors.
source to share