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

Lazy load some gems #760

Merged
merged 1 commit into from
Mar 20, 2024
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
2 changes: 2 additions & 0 deletions features/steps/mongrel_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def process(request, response)
reply_with(response, 406, 'No deflate accept encoding found in request')
else
response.start do |head, body|
require 'zlib'
head['Content-Encoding'] = 'deflate'
body.write Zlib::Deflate.deflate(response_body)
end
Expand All @@ -53,6 +54,7 @@ def process(request, response)
protected

def gzip(string)
require 'zlib'
sio = StringIO.new('', 'r+')
gz = Zlib::GzipWriter.new sio
gz.write string
Expand Down
5 changes: 0 additions & 5 deletions lib/httparty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
require 'pathname'
require 'net/http'
require 'uri'
require 'zlib'
require 'multi_xml'
require 'mini_mime'
require 'json'
require 'csv'

require 'httparty/module_inheritable_attributes'
require 'httparty/cookie_hash'
Expand Down
1 change: 1 addition & 0 deletions lib/httparty/logger/logstash_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def format(request, response)
attr_reader :request, :response

def logstash_message
require 'json'
{
'@timestamp' => current_time,
'@version' => 1,
Expand Down
3 changes: 3 additions & 0 deletions lib/httparty/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,19 @@ def parse
protected

def xml
require 'multi_xml'
MultiXml.parse(body)
end

UTF8_BOM = "\xEF\xBB\xBF"

def json
require 'json'
JSON.parse(body, :quirks_mode => true, :allow_nan => true)
end

def csv
require 'csv'
CSV.parse(body)
end

Expand Down
1 change: 1 addition & 0 deletions lib/httparty/request/body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def content_body(object)

def content_type(object)
return object.content_type if object.respond_to?(:content_type)
require 'mini_mime'
mime = MiniMime.lookup_by_filename(object.path)
mime ? mime.content_type : 'application/octet-stream'
end
Expand Down
1 change: 1 addition & 0 deletions spec/httparty/logger/logstash_formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'json'
require 'spec_helper'

RSpec.describe HTTParty::Logger::LogstashFormatter do
Expand Down
2 changes: 2 additions & 0 deletions spec/httparty/parser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'multi_xml'

RSpec.describe HTTParty::Parser do
describe ".SupportedFormats" do
Expand Down Expand Up @@ -183,6 +184,7 @@ def self.name
end

it "parses csv with CSV" do
require 'csv'
expect(CSV).to receive(:parse).with('body')
subject.send(:csv)
end
Expand Down