hi 1.0.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/.gitignore +17 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +124 -0
- data/Rakefile +8 -0
- data/bin/hi +7 -0
- data/hi.gemspec +28 -0
- data/lib/hi.rb +2 -0
- data/lib/hi/server.rb +46 -0
- data/lib/hi/version.rb +3 -0
- data/screenshot.png +0 -0
- data/spec/hi/server_spec.rb +44 -0
- data/spec/spec_helper.rb +2 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8f247763227d7434b2ed46f46900cee4f7d1f6a3
|
4
|
+
data.tar.gz: 97718c860991c2f4945be7c70fb012a657249d48
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9056d458b63ea7a5a4102ddca6e0e6a639f72c1ae1efe65c1464d62214ae3833dffac2a3ff957f04c8cad24afdbc90f95f648bea7b475efea95942618bf1c71
|
7
|
+
data.tar.gz: f6c052e3263328c6b5eed1e699deff94a86216e342fdebe9fcb96e1eb5f36a915e9f66b76df5057dafd7116adada26847ac06fc94db9b20ec20d87e1b6b4d944
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
Want to contribute? Awesome! Thank you so much.
|
4
|
+
|
5
|
+
## How?
|
6
|
+
|
7
|
+
1. [Fork it](https://help.github.com/articles/fork-a-repo)
|
8
|
+
2. Create a feature branch (`git checkout -b my-new-feature`)
|
9
|
+
3. Commit changes, **with tests** (`git commit -am 'Add some feature'`)
|
10
|
+
4. Run the tests (`bundle exec rake`)
|
11
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
12
|
+
6. Create new [Pull
|
13
|
+
Request](https://help.github.com/articles/using-pull-requests)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chris Hunt
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
[](https://travis-ci.org/chrishunt/hi)
|
2
|
+
[](https://coveralls.io/r/chrishunt/hi)
|
3
|
+
[](https://codeclimate.com/github/chrishunt/hi)
|
4
|
+
|
5
|
+

|
6
|
+
|
7
|
+
### hi, I'm here to debug your HTTP
|
8
|
+
|
9
|
+
## Description
|
10
|
+
|
11
|
+
`hi` is a simple HTTP server that will accept any request you throw at it and
|
12
|
+
reply with 'hi'. Since all requests are dumped to the console, it's probably
|
13
|
+
most useful for debugging.
|
14
|
+
|
15
|
+
Get started by installing the gem:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
$ gem install hi
|
19
|
+
```
|
20
|
+
|
21
|
+
Then start up the server:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
$ hi
|
25
|
+
>> Thin web server (v1.5.1 codename Straight Razor)
|
26
|
+
>> Maximum connections set to 1024
|
27
|
+
>> Listening on 0.0.0.0:3000, CTRL+C to stop
|
28
|
+
```
|
29
|
+
|
30
|
+
The default port is `3000`. You can start on another port if you like:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
$ hi 1234
|
34
|
+
>> Thin web server (v1.5.1 codename Straight Razor)
|
35
|
+
>> Maximum connections set to 1024
|
36
|
+
>> Listening on 0.0.0.0:1234, CTRL+C to stop
|
37
|
+
```
|
38
|
+
|
39
|
+
Now start debugging those requests:
|
40
|
+
|
41
|
+
```bash
|
42
|
+
$ curl localhost:3000/foo/bar\?message=hello
|
43
|
+
|
44
|
+
GET http://localhost:3000/foo/bar?message=hello (2013-12-27 11:32:47 -0800)
|
45
|
+
{
|
46
|
+
:host => "localhost",
|
47
|
+
:ip => "127.0.0.1",
|
48
|
+
:port => 3000,
|
49
|
+
:request_method => "GET",
|
50
|
+
:scheme => "http",
|
51
|
+
:url => "http://localhost:3000/foo/bar?message=hello",
|
52
|
+
:query_string => "message=hello",
|
53
|
+
:body => "",
|
54
|
+
:content_length => nil,
|
55
|
+
:media_type => nil,
|
56
|
+
:referer => nil,
|
57
|
+
:user_agent => "curl/7.30.0",
|
58
|
+
:xhr => false
|
59
|
+
}
|
60
|
+
```
|
61
|
+
|
62
|
+
`hi` accepts anything. Try a `POST` instead:
|
63
|
+
|
64
|
+
```bash
|
65
|
+
$ curl -d 'message=hello' localhost:3000
|
66
|
+
|
67
|
+
POST http://localhost:3000/ (2013-12-27 10:24:07 -0800)
|
68
|
+
{
|
69
|
+
:host => "localhost",
|
70
|
+
:ip => "127.0.0.1",
|
71
|
+
:port => 3000,
|
72
|
+
:request_method => "POST",
|
73
|
+
:scheme => "http",
|
74
|
+
:url => "http://localhost:3000/",
|
75
|
+
:query_string => "",
|
76
|
+
:body => "message=hello",
|
77
|
+
:content_length => "19",
|
78
|
+
:media_type => "application/x-www-form-urlencoded",
|
79
|
+
:referer => nil,
|
80
|
+
:user_agent => "curl/7.30.0",
|
81
|
+
:xhr => false
|
82
|
+
}
|
83
|
+
```
|
84
|
+
|
85
|
+
Or an xhr request:
|
86
|
+
|
87
|
+
```bash
|
88
|
+
$ curl -H 'X-Requested-With: XMLHttpRequest' -d "message=hello" localhost:3000
|
89
|
+
|
90
|
+
POST http://localhost:3000/ (2013-12-27 10:28:56 -0800)
|
91
|
+
{
|
92
|
+
:host => "localhost",
|
93
|
+
:ip => "127.0.0.1",
|
94
|
+
:port => 3000,
|
95
|
+
:request_method => "POST",
|
96
|
+
:scheme => "http",
|
97
|
+
:url => "http://localhost:3000/",
|
98
|
+
:query_string => "",
|
99
|
+
:body => "message=hello",
|
100
|
+
:content_length => "13",
|
101
|
+
:media_type => "application/x-www-form-urlencoded",
|
102
|
+
:referer => nil,
|
103
|
+
:user_agent => "curl/7.30.0",
|
104
|
+
:xhr => true
|
105
|
+
}
|
106
|
+
```
|
107
|
+
|
108
|
+
## Installation
|
109
|
+
|
110
|
+
```bash
|
111
|
+
$ gem install hi
|
112
|
+
```
|
113
|
+
|
114
|
+
## Contributing
|
115
|
+
Please see the [Contributing
|
116
|
+
Document](https://github.com/chrishunt/hi/blob/master/CONTRIBUTING.md)
|
117
|
+
|
118
|
+
## Changelog
|
119
|
+
Please see the [Changelog
|
120
|
+
Document](https://github.com/chrishunt/hi/blob/master/CHANGELOG.md)
|
121
|
+
|
122
|
+
## License
|
123
|
+
Copyright (C) 2013 Chris Hunt, [MIT
|
124
|
+
License](https://github.com/chrishunt/hi/blob/master/LICENSE.txt)
|
data/Rakefile
ADDED
data/bin/hi
ADDED
data/hi.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hi"
|
8
|
+
spec.version = Hi::VERSION
|
9
|
+
spec.authors = ["Chris Hunt"]
|
10
|
+
spec.email = ["c@chrishunt.co"]
|
11
|
+
spec.summary = %q{hi, I'm here to debug your HTTP}
|
12
|
+
spec.description = %q{hi, I'm here to debug your HTTP}
|
13
|
+
spec.homepage = "https://github.com/chrishunt/hi"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'awesome_print', '~> 1.2.0'
|
22
|
+
spec.add_dependency 'thin', '~> 1.5.1'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'coveralls', '~> 0.7.0'
|
25
|
+
spec.add_development_dependency 'rack-test', '~> 0.6.2'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.1.1'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 2.14.1'
|
28
|
+
end
|
data/lib/hi.rb
ADDED
data/lib/hi/server.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'awesome_print'
|
2
|
+
|
3
|
+
module Hi
|
4
|
+
class Server
|
5
|
+
attr_reader :port
|
6
|
+
|
7
|
+
def initialize(port = nil)
|
8
|
+
@port = (port = port.to_i) > 0 ? port : 3000
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
log parse_request(env)
|
13
|
+
|
14
|
+
[ 200, { 'Content-Type' => 'text/plain' }, ['hi'] ]
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def log(request)
|
20
|
+
unless ENV['RACK_ENV'] == 'test'
|
21
|
+
ap "#{request[:request_method]} #{request[:url]} (#{Time.now})"
|
22
|
+
ap request
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_request(env)
|
27
|
+
request = Rack::Request.new(env)
|
28
|
+
|
29
|
+
{
|
30
|
+
host: request.host,
|
31
|
+
ip: request.ip,
|
32
|
+
port: request.port,
|
33
|
+
request_method: request.request_method,
|
34
|
+
scheme: request.scheme,
|
35
|
+
url: request.url,
|
36
|
+
query_string: request.query_string,
|
37
|
+
body: request.body.string,
|
38
|
+
content_length: request.content_length,
|
39
|
+
media_type: request.media_type,
|
40
|
+
referer: request.referer,
|
41
|
+
user_agent: request.user_agent,
|
42
|
+
xhr: request.xhr?,
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/hi/version.rb
ADDED
data/screenshot.png
ADDED
Binary file
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'hi/server'
|
3
|
+
require 'rack/test'
|
4
|
+
|
5
|
+
ENV['RACK_ENV'] = 'test'
|
6
|
+
|
7
|
+
describe Hi::Server do
|
8
|
+
include Rack::Test::Methods
|
9
|
+
|
10
|
+
def app
|
11
|
+
described_class.new
|
12
|
+
end
|
13
|
+
|
14
|
+
[:get, :put, :post].each do |method|
|
15
|
+
it "responds to #{method.to_s.upcase}" do
|
16
|
+
send(method, '/')
|
17
|
+
|
18
|
+
expect(last_response).to be_ok
|
19
|
+
expect(last_response.body).to eq('hi')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'responds to any route' do
|
24
|
+
get '/some/random/route'
|
25
|
+
|
26
|
+
expect(last_response).to be_ok
|
27
|
+
expect(last_response.body).to eq('hi')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'defaults to port 3000' do
|
31
|
+
expect(app.port).to eq(3000)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'allows a customized port' do
|
35
|
+
expect(described_class.new(1234).port).to eq(1234)
|
36
|
+
expect(described_class.new('1234').port).to eq(1234)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'uses default port when customized port is invalid' do
|
40
|
+
expect(described_class.new(nil).port).to eq(3000)
|
41
|
+
expect(described_class.new('nope').port).to eq(3000)
|
42
|
+
expect(described_class.new(-100).port).to eq(3000)
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Hunt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: awesome_print
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thin
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.5.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.5.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coveralls
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.7.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.7.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.6.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 10.1.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 10.1.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.14.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.14.1
|
97
|
+
description: hi, I'm here to debug your HTTP
|
98
|
+
email:
|
99
|
+
- c@chrishunt.co
|
100
|
+
executables:
|
101
|
+
- hi
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- .travis.yml
|
107
|
+
- CHANGELOG.md
|
108
|
+
- CONTRIBUTING.md
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/hi
|
114
|
+
- hi.gemspec
|
115
|
+
- lib/hi.rb
|
116
|
+
- lib/hi/server.rb
|
117
|
+
- lib/hi/version.rb
|
118
|
+
- screenshot.png
|
119
|
+
- spec/hi/server_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
homepage: https://github.com/chrishunt/hi
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.0.3
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: hi, I'm here to debug your HTTP
|
145
|
+
test_files:
|
146
|
+
- spec/hi/server_spec.rb
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
has_rdoc:
|