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.
@@ -1,3 +1,6 @@
1
+ == 0.2.1 / 2009-12-30
2
+ * Requests default to 'GET / HTTP/1.0'
3
+
1
4
  == 0.2.0 / 2009-10-06
2
5
  * split off rbkb/http from rbkb core.
3
6
  * added MultiPartFormParams support and TextPlainFormParams
@@ -6,13 +6,56 @@ HTTP protocol addons for the Ruby BlackBag (rbkb-http)
6
6
 
7
7
  == DESCRIPTION
8
8
 
9
- This library various includes HTTP protocol tools and libraries based on and
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.0
1
+ 0.2.1
@@ -316,7 +316,7 @@ module Rbkb::Http
316
316
  _common_init(*args)
317
317
  @verb ||= "GET"
318
318
  @uri ||= URI.parse("/")
319
- @version ||= "HTTP/1.1"
319
+ @version ||= "HTTP/1.0"
320
320
  end
321
321
 
322
322
  def to_raw
@@ -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
- attr_accessor :action
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
- @action.parameters
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. The instance must have
47
- # an action element defined at the bare minimum.
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 = tmp_body.to_raw
61
- hdrs = (@headers).to_raw_array.unshift(first_entity.to_raw)
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
 
@@ -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.0"
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-11-12}
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.0
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-11-12 00:00:00 -06:00
12
+ date: 2009-12-30 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency