hi 1.0.0 → 1.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +26 -7
- data/lib/hi/request.rb +35 -0
- data/lib/hi/server.rb +2 -21
- data/lib/hi/version.rb +1 -1
- data/lib/hi.rb +1 -0
- data/spec/hi/request_spec.rb +28 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8bbd54fb327c3e7b130df186485b8ca1df580cc
|
4
|
+
data.tar.gz: d8184e3e8465aed9ae58bd516a02c0c65e16f995
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f0065cbc2ea2f70a279d13c1affbbae432793a72970732bb69b7659ca9d616a2d139c5b9f8456050b26e4e72fb711fec57059c2bfdd9a625d142fd9ae76c63c
|
7
|
+
data.tar.gz: ead378f1dcf608e175646f5c74a44e641a97dea9dfd2a302e89b10194853f4e4cf36a4c1a33e2da8cb62a5bb81180540711a4d7a35ced7e4253da0572439080e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -41,7 +41,7 @@ Now start debugging those requests:
|
|
41
41
|
```bash
|
42
42
|
$ curl localhost:3000/foo/bar\?message=hello
|
43
43
|
|
44
|
-
GET http://localhost:3000/foo/bar?message=hello (2013-12-27
|
44
|
+
"GET http://localhost:3000/foo/bar?message=hello (2013-12-27 14:18:16 -0800)"
|
45
45
|
{
|
46
46
|
:host => "localhost",
|
47
47
|
:ip => "127.0.0.1",
|
@@ -55,7 +55,13 @@ GET http://localhost:3000/foo/bar?message=hello (2013-12-27 11:32:47 -0800)
|
|
55
55
|
:media_type => nil,
|
56
56
|
:referer => nil,
|
57
57
|
:user_agent => "curl/7.30.0",
|
58
|
-
:xhr => false
|
58
|
+
:xhr => false,
|
59
|
+
:headers => {
|
60
|
+
"HTTP_VERSION" => "HTTP/1.1",
|
61
|
+
"HTTP_USER_AGENT" => "curl/7.30.0",
|
62
|
+
"HTTP_HOST" => "localhost:3000",
|
63
|
+
"HTTP_ACCEPT" => "*/*"
|
64
|
+
}
|
59
65
|
}
|
60
66
|
```
|
61
67
|
|
@@ -64,7 +70,7 @@ GET http://localhost:3000/foo/bar?message=hello (2013-12-27 11:32:47 -0800)
|
|
64
70
|
```bash
|
65
71
|
$ curl -d 'message=hello' localhost:3000
|
66
72
|
|
67
|
-
POST http://localhost:3000/ (2013-12-27
|
73
|
+
"POST http://localhost:3000/ (2013-12-27 14:18:59 -0800)"
|
68
74
|
{
|
69
75
|
:host => "localhost",
|
70
76
|
:ip => "127.0.0.1",
|
@@ -74,11 +80,17 @@ POST http://localhost:3000/ (2013-12-27 10:24:07 -0800)
|
|
74
80
|
:url => "http://localhost:3000/",
|
75
81
|
:query_string => "",
|
76
82
|
:body => "message=hello",
|
77
|
-
:content_length => "
|
83
|
+
:content_length => "13",
|
78
84
|
:media_type => "application/x-www-form-urlencoded",
|
79
85
|
:referer => nil,
|
80
86
|
:user_agent => "curl/7.30.0",
|
81
|
-
:xhr => false
|
87
|
+
:xhr => false,
|
88
|
+
:headers => {
|
89
|
+
"HTTP_VERSION" => "HTTP/1.1",
|
90
|
+
"HTTP_USER_AGENT" => "curl/7.30.0",
|
91
|
+
"HTTP_HOST" => "localhost:3000",
|
92
|
+
"HTTP_ACCEPT" => "*/*"
|
93
|
+
}
|
82
94
|
}
|
83
95
|
```
|
84
96
|
|
@@ -87,7 +99,7 @@ Or an xhr request:
|
|
87
99
|
```bash
|
88
100
|
$ curl -H 'X-Requested-With: XMLHttpRequest' -d "message=hello" localhost:3000
|
89
101
|
|
90
|
-
POST http://localhost:3000/ (2013-12-27
|
102
|
+
"POST http://localhost:3000/ (2013-12-27 14:19:24 -0800)"
|
91
103
|
{
|
92
104
|
:host => "localhost",
|
93
105
|
:ip => "127.0.0.1",
|
@@ -101,7 +113,14 @@ POST http://localhost:3000/ (2013-12-27 10:28:56 -0800)
|
|
101
113
|
:media_type => "application/x-www-form-urlencoded",
|
102
114
|
:referer => nil,
|
103
115
|
:user_agent => "curl/7.30.0",
|
104
|
-
:xhr => true
|
116
|
+
:xhr => true,
|
117
|
+
:headers => {
|
118
|
+
"HTTP_VERSION" => "HTTP/1.1",
|
119
|
+
"HTTP_USER_AGENT" => "curl/7.30.0",
|
120
|
+
"HTTP_HOST" => "localhost:3000",
|
121
|
+
"HTTP_ACCEPT" => "*/*",
|
122
|
+
"HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"
|
123
|
+
}
|
105
124
|
}
|
106
125
|
```
|
107
126
|
|
data/lib/hi/request.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rack/request'
|
2
|
+
|
3
|
+
module Hi
|
4
|
+
class Request
|
5
|
+
attr_reader :env, :request
|
6
|
+
|
7
|
+
def initialize(env)
|
8
|
+
@env = env
|
9
|
+
@request = Rack::Request.new(env)
|
10
|
+
end
|
11
|
+
|
12
|
+
def headers
|
13
|
+
env.select { |key| key.start_with? 'HTTP_' }
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_h
|
17
|
+
{
|
18
|
+
host: request.host,
|
19
|
+
ip: request.ip,
|
20
|
+
port: request.port,
|
21
|
+
request_method: request.request_method,
|
22
|
+
scheme: request.scheme,
|
23
|
+
url: request.url,
|
24
|
+
query_string: request.query_string,
|
25
|
+
body: (request.body.string if request.body),
|
26
|
+
content_length: request.content_length,
|
27
|
+
media_type: request.media_type,
|
28
|
+
referer: request.referer,
|
29
|
+
user_agent: request.user_agent,
|
30
|
+
xhr: request.xhr?,
|
31
|
+
headers: headers,
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/hi/server.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'awesome_print'
|
2
|
+
require 'hi/request'
|
2
3
|
|
3
4
|
module Hi
|
4
5
|
class Server
|
@@ -9,7 +10,7 @@ module Hi
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def call(env)
|
12
|
-
log
|
13
|
+
log Hi::Request.new(env).to_h
|
13
14
|
|
14
15
|
[ 200, { 'Content-Type' => 'text/plain' }, ['hi'] ]
|
15
16
|
end
|
@@ -22,25 +23,5 @@ module Hi
|
|
22
23
|
ap request
|
23
24
|
end
|
24
25
|
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
26
|
end
|
46
27
|
end
|
data/lib/hi/version.rb
CHANGED
data/lib/hi.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'hi/request'
|
3
|
+
|
4
|
+
describe Hi::Request do
|
5
|
+
describe '#to_h' do
|
6
|
+
it 'includes all the important bits' do
|
7
|
+
hash = described_class.new({}).to_h
|
8
|
+
|
9
|
+
expect(hash).to include :headers
|
10
|
+
expect(hash).to include :body
|
11
|
+
expect(hash).to include :url
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#headers' do
|
16
|
+
it 'returns all headers from the environment' do
|
17
|
+
headers = {
|
18
|
+
'HTTP_MY_HEADER' => 'is present',
|
19
|
+
'HTTP_MY_OTHER_HEADER' => 'is also present',
|
20
|
+
}
|
21
|
+
|
22
|
+
request = described_class.new \
|
23
|
+
headers.merge('NOT_A_HEADER' => 'is not present')
|
24
|
+
|
25
|
+
expect(request.headers).to eq headers
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hunt
|
@@ -113,9 +113,11 @@ files:
|
|
113
113
|
- bin/hi
|
114
114
|
- hi.gemspec
|
115
115
|
- lib/hi.rb
|
116
|
+
- lib/hi/request.rb
|
116
117
|
- lib/hi/server.rb
|
117
118
|
- lib/hi/version.rb
|
118
119
|
- screenshot.png
|
120
|
+
- spec/hi/request_spec.rb
|
119
121
|
- spec/hi/server_spec.rb
|
120
122
|
- spec/spec_helper.rb
|
121
123
|
homepage: https://github.com/chrishunt/hi
|
@@ -143,6 +145,7 @@ signing_key:
|
|
143
145
|
specification_version: 4
|
144
146
|
summary: hi, I'm here to debug your HTTP
|
145
147
|
test_files:
|
148
|
+
- spec/hi/request_spec.rb
|
146
149
|
- spec/hi/server_spec.rb
|
147
150
|
- spec/spec_helper.rb
|
148
151
|
has_rdoc:
|