kirk 0.2.0.beta.1-java → 0.2.0.beta.2-java
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +67 -0
- data/lib/kirk/server/handler.rb +1 -1
- data/lib/kirk/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -94,6 +94,73 @@ Use your OS features. For example, write an upstart script or use
|
|
94
94
|
|
95
95
|
Kirk just dumps logs to stdout, so just pipe Kirk to `logger`.
|
96
96
|
|
97
|
+
### Kirk::Client - For all your HTTP needs
|
98
|
+
|
99
|
+
Need to make one off HTTP requests?
|
100
|
+
|
101
|
+
resp = Kirk::Client.get 'http://www.google.com'
|
102
|
+
puts resp.body
|
103
|
+
|
104
|
+
That was cool, but I wouldn't recommending doing that in your Rails app.
|
105
|
+
Following is the more advanced API.
|
106
|
+
|
107
|
+
First, create an instance of Kirk::Client. This object is thread-safe (or at
|
108
|
+
least it should be) and will manage your connection pool. Any connection that
|
109
|
+
can be kept alive will be stored by Kirk::Client and reused on subsequent requests.
|
110
|
+
|
111
|
+
MY_CLIENT = Kirk::Client.new
|
112
|
+
|
113
|
+
Next, you'll want to implement a class to handle the responses. Just implement
|
114
|
+
any method that you want to use.
|
115
|
+
|
116
|
+
class MyHandler
|
117
|
+
# Handle exceptions
|
118
|
+
def on_exception(exception)
|
119
|
+
end
|
120
|
+
|
121
|
+
# The request to the server has finished, but the
|
122
|
+
# server has not responded yet.
|
123
|
+
def on_request_complete
|
124
|
+
end
|
125
|
+
|
126
|
+
# The server has finished sending the response header
|
127
|
+
def on_response_head(response)
|
128
|
+
puts "STATUS: #{response.status}"
|
129
|
+
response.headers.each do |name, val|
|
130
|
+
puts " #{name}: #{val}"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# The server is sending the response body. This method could
|
135
|
+
# be called multiple times depending on the number of chunks
|
136
|
+
# that are received.
|
137
|
+
#
|
138
|
+
# Also, if this method is implemented, the response body won't
|
139
|
+
# be buffered in the response object.
|
140
|
+
def on_response_body(response, chunk)
|
141
|
+
# response.body == nil
|
142
|
+
print chunk
|
143
|
+
end
|
144
|
+
|
145
|
+
def on_response_complete(response)
|
146
|
+
puts "The response has been received"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
Now, you can start making the requests.
|
151
|
+
|
152
|
+
MY_CLIENT.group do |g|
|
153
|
+
|
154
|
+
# All of these requests will happen in parallel.
|
155
|
+
g.get 'http://www.google.com', MyHandler.new
|
156
|
+
g.post 'http://www.twitter.com', MyHandler.new, "Some request body"
|
157
|
+
g.get 'http://www.amazon.com', nil, nil, 'X-Custom-Header' => 'Blah'
|
158
|
+
|
159
|
+
# The group will block until all of the requests are completed.
|
160
|
+
end
|
161
|
+
|
162
|
+
Hopefully that is enough to get started.
|
163
|
+
|
97
164
|
### Caveats
|
98
165
|
|
99
166
|
This is still a pretty new project and a lot of settings that should be
|
data/lib/kirk/server/handler.rb
CHANGED
@@ -73,7 +73,7 @@ module Kirk
|
|
73
73
|
REMOTE_HOST => request.get_remote_host || "",
|
74
74
|
REMOTE_ADDR => request.get_remote_addr || "",
|
75
75
|
REMOTE_USER => request.get_remote_user || "",
|
76
|
-
SERVER_PORT => request.
|
76
|
+
SERVER_PORT => request.get_local_port.to_s,
|
77
77
|
RACK_VERSION => ::Rack::VERSION)
|
78
78
|
|
79
79
|
# Process the content length
|
data/lib/kirk/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: kirk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 6
|
5
|
-
version: 0.2.0.beta.
|
5
|
+
version: 0.2.0.beta.2
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Carl Lerche
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-03-01 00:00:00 -08:00
|
14
14
|
default_executable: kirk
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -60,7 +60,7 @@ files:
|
|
60
60
|
- README.md
|
61
61
|
- LICENSE
|
62
62
|
has_rdoc: true
|
63
|
-
homepage: http://github.com/
|
63
|
+
homepage: http://github.com/strobecorp/kirk
|
64
64
|
licenses: []
|
65
65
|
|
66
66
|
post_install_message:
|