Skip to content

Commit

Permalink
Replace mime-types with mini_mime for content type lookup
Browse files Browse the repository at this point in the history
`mini_mime` is a minimal mime type library that's more performant and
less memory hungry.
https://github.com/discourse/mini_mime

It has replaced `mime-types` in the `mail` gem: (which is a dependency
of `actionmailer`, and by extension, `rails`)
mikel/mail#1059

As well as `capybara`:
teamcapybara/capybara#1884

Which also means using it as a dependency of `httparty` would be able to
reuse the same dependency that should be already available in most Rails
apps, instead of pulling in an extra `mime-types` dependency.

The change in code is pretty straightforward, the same one made by the
capybara PR linked above.
  • Loading branch information
carlosantoniodasilva committed Nov 10, 2022
1 parent c27adec commit 366745b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## unreleased

* Fix request marshaling (https://github.com/jnunemaker/httparty/pull/767)
* [Replace `mime-types` with `mini_mime`](https://github.com/jnunemaker/httparty/pull/769)

## 0.20.0

Expand Down
2 changes: 1 addition & 1 deletion httparty.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.3.0'

s.add_dependency 'multi_xml', ">= 0.5.2"
s.add_dependency('mime-types', "~> 3.0")
s.add_dependency 'mini_mime', ">= 1.0.0"

# If this line is removed, all hard partying will cease.
s.post_install_message = "When you HTTParty, you must party hard!"
Expand Down
2 changes: 1 addition & 1 deletion lib/httparty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'uri'
require 'zlib'
require 'multi_xml'
require 'mime/types'
require 'mini_mime'
require 'json'
require 'csv'

Expand Down
4 changes: 2 additions & 2 deletions lib/httparty/request/body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def content_body(object)

def content_type(object)
return object.content_type if object.respond_to?(:content_type)
mime = MIME::Types.type_for(object.path)
mime.empty? ? 'application/octet-stream' : mime[0].content_type
mime = MiniMime.lookup_by_filename(object.path)
mime ? mime.content_type : 'application/octet-stream'
end

def file_name(object)
Expand Down

0 comments on commit 366745b

Please sign in to comment.