项目作者: alphagov

项目描述 :
Canonicalise URLs
高级语言: Ruby
项目地址: git://github.com/alphagov/optic14n.git
创建时间: 2013-07-25T15:52:33Z
项目社区:https://github.com/alphagov/optic14n

开源协议:MIT License

下载


Optic14n

Canonicalises URLs.

Installation

Add this line to your application’s Gemfile:

  1. gem 'optic14n'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install optic14n

Usage

Parse a BLURI like this:

  1. bluri = BLURI('http://somewhere.com/?a=1&b=2&c=3')

Canonicalize it according to the Previously-Established Rules thusly:

  1. bluri.canonicalize!

You can also do site-specific stuff if you know some of the querystring will be valuable

  1. bluri.canonicalize!(allow_query: :all)
  1. bluri.canonicalize!(allow_query: [:a, :c])
  2. # or
  3. bluri.canonicalize!(allow_query: ['a', 'c'])

The previously-established rules

This is a gem for canonicalising HTTP URIs such that we can boil our input set of URIs down to something that is much
smaller than it would otherwise be. We do this aggressively by:

  • lowercasing URIs
  • removing query strings (unless told otherwise)
  • removing fragments
  • escaping and unescaping various characters and escape sequences according to RFC3986

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Licence

MIT License