rbkb-http 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/README.rdoc +44 -1
- data/VERSION +1 -1
- data/lib/rbkb/http/headers.rb +1 -1
- data/lib/rbkb/http/request.rb +12 -8
- data/rbkb-http.gemspec +2 -2
- metadata +2 -2
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -6,13 +6,56 @@ HTTP protocol addons for the Ruby BlackBag (rbkb-http)
|
|
6
6
|
|
7
7
|
== DESCRIPTION
|
8
8
|
|
9
|
-
This library
|
9
|
+
This library includes HTTP protocol tools and libraries based on and
|
10
10
|
complementary to the Ruby BlackBag library.
|
11
11
|
|
12
|
+
At it's core rbkb-http is simply a set of serializable and desieralizable
|
13
|
+
objects for HTTP request and response messages.
|
14
|
+
|
12
15
|
== REQUIREMENTS
|
13
16
|
|
14
17
|
* ruby blackbag (rbkb) - http://emonti.github.com/rbkb
|
15
18
|
|
19
|
+
|
20
|
+
== SYNOPSIS
|
21
|
+
|
22
|
+
require 'rubygems'
|
23
|
+
require 'rbkb/http'
|
24
|
+
|
25
|
+
# we start with a raw HTTP request string
|
26
|
+
rawdat = "POST /foo HTTP/1.0
|
27
|
+
Content-Length: 10
|
28
|
+
|
29
|
+
a=12345678"
|
30
|
+
|
31
|
+
# ... which we parse into an abstract object
|
32
|
+
req = Rbkb::Http::Request.new()
|
33
|
+
req.capture(rawdat)
|
34
|
+
|
35
|
+
# Or you could just say this in one shot
|
36
|
+
#req = Rbkb::Http::Request.parse(rawdat)
|
37
|
+
|
38
|
+
# now we can mess with the request body
|
39
|
+
req.body << "extrastuff"
|
40
|
+
|
41
|
+
# .. and/or action line
|
42
|
+
req.action.version="HTTP/1.1"
|
43
|
+
|
44
|
+
# ... and/or headers
|
45
|
+
req.headers.set_header("Host", "somehost.com")
|
46
|
+
|
47
|
+
# and spit out a new request string (content-length is auto-calculated!)
|
48
|
+
puts req.to_raw
|
49
|
+
-/snip-
|
50
|
+
|
51
|
+
Which produces:
|
52
|
+
|
53
|
+
POST /foo HTTP/1.1
|
54
|
+
Content-Length: 20
|
55
|
+
Host: somehost.com
|
56
|
+
|
57
|
+
a=12345678extrastuff
|
58
|
+
|
16
59
|
== Copyright
|
17
60
|
|
18
61
|
Copyright (c) 2009 Eric Monti. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/rbkb/http/headers.rb
CHANGED
data/lib/rbkb/http/request.rb
CHANGED
@@ -3,13 +3,19 @@ module Rbkb::Http
|
|
3
3
|
# A Request encapsulates all the entities in a HTTP request message
|
4
4
|
# including the action header, general headers, and body.
|
5
5
|
class Request < Base
|
6
|
-
|
6
|
+
def action
|
7
|
+
@action ||= RequestAction.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def action=(a)
|
11
|
+
@action = a
|
12
|
+
end
|
7
13
|
|
8
14
|
alias first_entity action
|
9
15
|
alias first_entity= action=
|
10
16
|
|
11
17
|
def action_parameters
|
12
|
-
|
18
|
+
action.parameters
|
13
19
|
end
|
14
20
|
|
15
21
|
def body_parameters
|
@@ -43,10 +49,8 @@ module Rbkb::Http
|
|
43
49
|
Body.new(*args)
|
44
50
|
end
|
45
51
|
|
46
|
-
# Returns a raw HTTP request for this instance.
|
47
|
-
|
48
|
-
def to_raw(tmp_body=@body)
|
49
|
-
raise "this request has no action entity" unless first_entity()
|
52
|
+
# Returns a raw HTTP request for this instance.
|
53
|
+
def to_raw()
|
50
54
|
self.headers ||= default_headers_obj()
|
51
55
|
self.body ||= default_body_obj()
|
52
56
|
|
@@ -57,8 +61,8 @@ module Rbkb::Http
|
|
57
61
|
@headers.delete_header("Content-Length")
|
58
62
|
end
|
59
63
|
|
60
|
-
bstr =
|
61
|
-
hdrs =
|
64
|
+
bstr = @body.to_raw
|
65
|
+
hdrs = @headers.to_raw_array.unshift(first_entity.to_raw)
|
62
66
|
return "#{hdrs.join("\r\n")}\r\n\r\n#{bstr}"
|
63
67
|
end
|
64
68
|
|
data/rbkb-http.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rbkb-http}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Eric Monti"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-12-30}
|
13
13
|
s.description = %q{HTTP libraries and tools based on and complementary to Ruby BlackBag}
|
14
14
|
s.email = %q{emonti@matasano.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbkb-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Monti
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-30 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|