No commit activity in last 3 years
No release in over 3 years
This gem allows you to check the Content-Type of any HTTP-accessible asset.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

HttpContentType

Gem Version Build Status Dependency Status Code Climate Coverage Status

This gem allows you to check the Content-Type of any asset accessible via HTTP.

Compatible with Ruby >= 1.9, JRuby (1.9 mode) or Rubinius (1.9 mode).

Installation

Add this line to your application's Gemfile:

gem 'http_content_type'

And then execute:

$ bundle

Or install it yourself as:

$ gem install http_content_type

Usage

checker = HttpContentType::Checker.new('http://domain.com/video.mp4')

checker.error?                # => false (true if there was an error requesting
                              #    the asset)
checker.found?                # => true (the asset was found, i.e. request
                              #    returned an `Net::HTTPSuccess` response)
checker.expected_content_type # => 'video/mp4' (the expected content type is
                              #    based on file extension but can also be
                              #    hardcoded with the :expected_content_type option)
checker.content_type          # => 'video/mp4'
checker.valid_content_type?   # => true

Options

:timeout

checker = HttpContentType::Checker.new('http://domain.com/video.mp4', timeout: 10) # in seconds

:expected_content_type

checker = HttpContentType::Checker.new('http://domain.com/dynamic_asset.php', expected_content_type: 'video/mp4')
checker.expected_content_type # => 'video/mp4'
checker.content_type          # => 'video/mp4'
checker.valid_content_type?   # => true

Development

Pull requests are very welcome! Please try to follow these simple rules if applicable:

  • Please create a topic branch for every separate change you make.
  • Make sure your patches are well tested. All specs must pass on Travis CI.
  • Update the Yard documentation.
  • Update the README.
  • Update the CHANGELOG for noteworthy changes (don't forget to run bundle exec pimpmychangelog and watch the magic happen)!
  • Please do not change the version number.

Author

Contributors

https://github.com/jilion/http_content_type/graphs/contributors