rack-x_served_by 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +93 -0
- data/lib/rack/x_served_by/version.rb +5 -0
- data/lib/rack/x_served_by.rb +28 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a2a5a4eff17481c2de2bea096ad3f80d2cd2dac
|
4
|
+
data.tar.gz: 21e19ffa631ca4a2d70f5fb5c08138fe2a9906fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0bd46c56457f3754a18e97cf684b78c6a5a9f278d741b732be890ddf3724a4eff37c40cf714b150e4a4586c31d4d274588cac48e22891a18c080f6787aacac3b
|
7
|
+
data.tar.gz: 84a50c5aaa9e21a3f1398d73b058e9572ccfa45d30a957fdc3fdf70deb768f4b4cf610ff868fbc0271ece0cbfa1a4a023411e7bb67c824da1017ab84e98715f3
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Rack::XServedBy [](https://codeclimate.com/github/3scale/rack-x_served_by)
|
2
|
+
|
3
|
+
|
4
|
+
Rack::XServedBy is a Rack middleware, that adds `X-Served-By` HTTP header to your responses.
|
5
|
+
|
6
|
+
That is useful if load balance between many servers and want to know which one served the request.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'rack-x_served_by'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install rack-x_served_by
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
In config.ru
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
use Rack::XServedBy
|
32
|
+
|
33
|
+
run YourApp
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
Or in Rails `config/application.rb`
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
|
41
|
+
module YourApp
|
42
|
+
class Application < Rails::Application
|
43
|
+
config.middleware.use Rack::XServedBy
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
You can configure custom hostname as:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
use Rack::XServedBy, 'custom-hostname'
|
52
|
+
```
|
53
|
+
|
54
|
+
|
55
|
+
With example `config.ru`:
|
56
|
+
|
57
|
+
```
|
58
|
+
$ curl -v localhost:9292
|
59
|
+
|
60
|
+
* Rebuilt URL to: localhost:9292/
|
61
|
+
* Hostname was NOT found in DNS cache
|
62
|
+
* Trying 127.0.0.1...
|
63
|
+
* Connected to localhost (127.0.0.1) port 9292 (#0)
|
64
|
+
> GET / HTTP/1.1
|
65
|
+
> User-Agent: curl/7.37.1
|
66
|
+
> Host: localhost:9292
|
67
|
+
> Accept: */*
|
68
|
+
>
|
69
|
+
< HTTP/1.1 200 OK
|
70
|
+
< X-Served-By: Michals-MacBook-Pro.local
|
71
|
+
< Transfer-Encoding: chunked
|
72
|
+
* Server WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13) is not blacklisted
|
73
|
+
< Server: WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13)
|
74
|
+
< Date: Fri, 22 May 2015 13:37:22 GMT
|
75
|
+
< Connection: Keep-Alive
|
76
|
+
<
|
77
|
+
* Connection #0 to host localhost left intact
|
78
|
+
Hello, world%
|
79
|
+
```
|
80
|
+
|
81
|
+
## Development
|
82
|
+
|
83
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
84
|
+
|
85
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
1. Fork it ( https://github.com/3scale/rack-x_served_by/fork )
|
90
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
91
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
92
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
93
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rack/x_served_by/version'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class XServedBy
|
5
|
+
attr_accessor :hostname
|
6
|
+
|
7
|
+
HEADER_NAME = 'X-Served-By'.freeze
|
8
|
+
|
9
|
+
def initialize(app, hostname = self.class.hostname)
|
10
|
+
@app = app
|
11
|
+
@hostname = hostname
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.hostname
|
15
|
+
Socket.gethostname
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
_status, headers, _body = @app.call(env)
|
20
|
+
|
21
|
+
unless headers.key?(HEADER_NAME)
|
22
|
+
headers[HEADER_NAME] = hostname
|
23
|
+
end
|
24
|
+
|
25
|
+
[_status, headers, _body]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-x_served_by
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michal Cichra
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
description: Allows you to know from which server the response originated from.
|
56
|
+
email:
|
57
|
+
- michal@3scale.net
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- README.md
|
63
|
+
- lib/rack/x_served_by.rb
|
64
|
+
- lib/rack/x_served_by/version.rb
|
65
|
+
homepage: https://github.com/3scale/rack-x_served_by
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.4.6
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Adds X-Served-By header to responses with server's hostname
|
89
|
+
test_files: []
|
90
|
+
has_rdoc:
|