1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00
Commit graph

7 commits

Author SHA1 Message Date
Andy Brody
4fb434e351 Add dependency on http-accept for Content-Type.
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.
2017-07-05 00:42:43 -04:00
Andy Brody
4971d1a6e1 Convert specs to RSpec 2.99.2 syntax with Transpec
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
2016-06-05 19:52:16 -04:00
Andy Brody
bad70fb1d8 Add more tests for Utils.encode_query_string.
These tests, which follow the yard-doc examples, exercise the
new ParamsArray behavior.
2016-01-26 23:02:07 -05:00
Andy Brody
2dd4b3739d Enable new GET param generation, add tests.
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.
2015-11-12 00:11:33 -08:00
Andy Brody
5ce0c6ebde Fix up tests for encoding changes.
Add a `.to_hash => {}` for the Net HTTP response mocks.
2015-03-13 18:00:51 -07:00
Andy Brody
6d7818f517 Per RFC 7231, don't default to ISO-8859-1. 2015-03-13 16:33:46 -07:00
Andy Brody
29b56a33f3 Add functions for parsing content-type headers. 2015-01-28 02:45:02 -08:00