🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

http_range

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http_range

1.2.0
Rubygems
Version published
Maintainers
1
Created
Source

HTTPRange

A library to parse an HTTP Range header for HTTP APIs with semantics described in SPEC.

Installation

Add this line to your application's Gemfile:

gem 'http_range'

And then execute:

$ bundle

Or install it yourself as:

$ gem install http_range

Usage

http_range = HTTPRange.parse('Range: id 29f99177-36e9-466c-baef-f855e1ab731e..29f99177-36e9-466c-baef-f855e1ab731e[; max=100')

http_range.attribute       # => "id"
http_range.first           # => "29f99177-36e9-466c-baef-f855e1ab731e"
http_range.last            # => "29f99177-36e9-466c-baef-f855e1ab731e"
http_range.max             # => "100"
http_range.order           # => nil
http_range.first_inclusive # => true
http_range.last_inclusive  # => false

Or, in a Rack app:

# Range: id a..z[; max=100
# found in env['HTTP_RANGE']
app = Rack::Builder.app do
  use HTTPRange::Middleware::AcceptRanges

  run lambda do |env|

    env['rack.range.attribute']       # => 'id'
    env['rack.range.first']           # => 'a'
    env['rack.range.last']            # => 'z'
    env['rack.range.first_inclusive'] # => true
    env['rack.range.last_inclusive']  # => false
    env['rack.range.order']           # => nil
    env['rack.range.max']             # => '100'

    [200, {}, "Body"]
  end
end

Inspiration

Inspired by Heroku's Interagent HTTP API Design as well as brandur's HTTPAccept library.

Contributing

  • Fork it ( https://github.com/h3h/http_range/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

FAQs

Package last updated on 23 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts