The previous "Content-Type" header parser was ported from Python and was
not very idiomatic Ruby. While fast and correct per the RFCs, it was
triggering bugs in Ruby MRI that we could probably work around. Ideally
someone would fix the bugs in Ruby MRI, but I haven't had time to track
them down.
Switch to using HTTP::Accept for parsing the media-type charset out of
the "Content-Type" header. Also relax the tests since HTTP::Accept is
somewhat stricter in the input it will accept. As a result, rest-client
will now ignore Content-Type headers with a trailing `;` character.
(This is invalid per the RFCs, so impact is likely to be small in
comparison to fixing the Ruby 2.4 memory leak.)
I also tried using https://github.com/httprb/content_type.rb but it is
significantly slower (caused 2x blowup in time on a simple benchmark)
and doesn't correctly handle content-types containing '.' characters.
Fixes: #523 (occasional MRI segfault)
Fixes: #611 (MRI 2.4.* memory leak)
* Unfortunately, HTTP::Accept does not support Ruby 2.0 due to its use
of named capture groups in StringScanner, which was added in Ruby 2.1.
Because rest-client still supports Ruby 2.0, fall back on the old
logic when running on Ruby 2.0. Even though Ruby 2.0 is unsupported,
it probably still sees wide use since it is the system Ruby even on
macOS Sierra.
* Don't bother running tests for .cgi_parse_header on Ruby 2.0. Still
keep the higher level tests that will exercise the deprecated code.
This conversion is done by Transpec 3.2.2 with the following command:
transpec
* 317 conversions
from: obj.should
to: expect(obj).to
* 160 conversions
from: obj.stub(:message)
to: allow(obj).to receive(:message)
* 100 conversions
from: obj.should_receive(:message)
to: expect(obj).to receive(:message)
* 30 conversions
from: lambda { }.should
to: expect { }.to
* 22 conversions
from: obj.should_not_receive(:message)
to: expect(obj).not_to receive(:message)
* 4 conversions
from: obj.should_not
to: expect(obj).not_to
* 2 conversions
from: == expected
to: eq(expected)
* 1 conversion
from: expect(collection).to have_at_least(n).items
to: expect(collection.size).to be >= n
* 1 conversion
from: obj.unstub(:message)
to: allow(obj).to receive(:message).and_call_original
For more details: https://github.com/yujinakayama/transpec#supported-conversions
Switch the generation of HTTP GET params over to the new, more
featureful method in Utils, which handles Rack/Rails style nested
parameters. Also add a variety of tests for this functionality.