Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/namusyaka/rack-refresh
Rack Middleware for adding Refresh field to response headers
https://github.com/namusyaka/rack-refresh
Last synced: about 1 month ago
JSON representation
Rack Middleware for adding Refresh field to response headers
- Host: GitHub
- URL: https://github.com/namusyaka/rack-refresh
- Owner: namusyaka
- License: mit
- Created: 2014-07-30T15:18:03.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-31T07:34:11.000Z (over 10 years ago)
- Last Synced: 2024-10-02T22:04:49.921Z (about 1 month ago)
- Language: Ruby
- Size: 129 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Rack::Refresh
[![Build Status](https://travis-ci.org/namusyaka/rack-refresh.svg?branch=master)](https://travis-ci.org/namusyaka/rack-refresh)
[![Gem Version](https://badge.fury.io/rb/rack-refresh.svg)](http://badge.fury.io/rb/rack-refresh)
[![Code Climate](https://codeclimate.com/github/namusyaka/rack-refresh/badges/gpa.svg)](https://codeclimate.com/github/namusyaka/rack-refresh)Rack Middleware for adding `Refresh` field to response headers.
**`Refresh` is supported by modern browsers, but it isn't official HTTP standard.
So please be careful when using this.**## Installation
Add this line to your application's Gemfile:
gem 'rack-refresh'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rack-refresh
## Usage
`Rack::Refresh` is easy to use.
I would explain how to use it in three sections.```ruby
use Rack::Refresh do
refresh "/", interval: 5, url: "http://www.google.com/"
refresh do |env|
env["PATH_INFO"] == "/path" && env["REQUEST_METHOD"].to_s.upcase == "GET"
end
refresh %r{/hello.+?} do |env|
env["PATH_INFO"].start_with?("/hello")
end
end
```### with Path
The path can be set string and regex.
The refresh field will be added to response headers if the path matches with `ENV["PATH_INFO"]````ruby
use Rack::Refresh do
# String
refresh "/", url: "http://www.google.com/"
# Regex
refresh %r{/foo}, url: "http://www.google.com/"
end
```### with Block
The refresh field will be added to response headers if the return value of block is `true`.
```ruby
use Rack::Refresh do
refresh do |env|
env["PATH_INFO"].start_with?("/hello")
end
end
```### Configuration
`:url` and `:interval` can be set in `refresh` and `use` methods.
If options are set in both methods, `refresh`'s option will be priority.```ruby
use Rack::Refresh, url: "http://www.google.com/", interval: 5 do
refresh "/" #=> Refresh: 5; url=http://www.google.com/
refresh "/foo", url: "http://namusyaka.info/", interval: 0 #=> Refresh: 0; url=http://namusyaka.info/
end
```## Contributing
1. Fork it ( https://github.com/namusyaka/rack-refresh/fork )
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 a new Pull Request