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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f247763227d7434b2ed46f46900cee4f7d1f6a3
4
- data.tar.gz: 97718c860991c2f4945be7c70fb012a657249d48
3
+ metadata.gz: b8bbd54fb327c3e7b130df186485b8ca1df580cc
4
+ data.tar.gz: d8184e3e8465aed9ae58bd516a02c0c65e16f995
5
5
  SHA512:
6
- metadata.gz: d9056d458b63ea7a5a4102ddca6e0e6a639f72c1ae1efe65c1464d62214ae3833dffac2a3ff957f04c8cad24afdbc90f95f648bea7b475efea95942618bf1c71
7
- data.tar.gz: f6c052e3263328c6b5eed1e699deff94a86216e342fdebe9fcb96e1eb5f36a915e9f66b76df5057dafd7116adada26847ac06fc94db9b20ec20d87e1b6b4d944
6
+ metadata.gz: 2f0065cbc2ea2f70a279d13c1affbbae432793a72970732bb69b7659ca9d616a2d139c5b9f8456050b26e4e72fb711fec57059c2bfdd9a625d142fd9ae76c63c
7
+ data.tar.gz: ead378f1dcf608e175646f5c74a44e641a97dea9dfd2a302e89b10194853f4e4cf36a4c1a33e2da8cb62a5bb81180540711a4d7a35ced7e4253da0572439080e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ##v1.1.0
4
+ *2013-12-27*
5
+
6
+ - #1 Show request headers
7
+
3
8
  ##v1.0.0
4
9
  *2013-12-27*
5
10
 
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 11:32:47 -0800)
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 10:24:07 -0800)
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 => "19",
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 10:28:56 -0800)
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 parse_request(env)
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
@@ -1,3 +1,3 @@
1
1
  module Hi
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/hi.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'hi/version'
2
+ require 'hi/request'
2
3
  require 'hi/server'
@@ -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.0.0
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: