hatetepe 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -68,6 +68,14 @@ module Hatetepe
68
68
  end
69
69
 
70
70
  def response(code, version = "1.1")
71
+ if Array === code
72
+ response(code[0])
73
+ code[1].each_pair {|name, value| header(name, value) }
74
+ code[2].each {|chunk| body(chunk) }
75
+ complete
76
+ return
77
+ end
78
+
71
79
  complete unless ready?
72
80
  unless status = STATUS_CODES[code]
73
81
  error "Unknown status code: #{code}"
@@ -103,6 +111,7 @@ module Hatetepe
103
111
  elsif writing_trailing_headers?
104
112
  error "Cannot write body after trailing headers"
105
113
  elsif writing_headers?
114
+ header "Transfer-Encoding", "chunked" if chunked?
106
115
  write "\r\n"
107
116
  @state = :writing_body
108
117
  end
@@ -35,7 +35,8 @@ module Hatetepe
35
35
  attr_reader :bytes_read
36
36
 
37
37
  def initialize(&block)
38
- @on_request, @on_response, @on_header = [], [], []
38
+ @on_request, @on_response = [], []
39
+ @on_header, @on_headers_complete = [], []
39
40
  @on_body_chunk, @on_complete, @on_error = [], [], []
40
41
  @parser = HTTP::Parser.new
41
42
 
@@ -53,6 +54,8 @@ module Hatetepe
53
54
  @parser.headers.each do |header|
54
55
  on_header.each {|h| h.call(*header) }
55
56
  end
57
+
58
+ on_headers_complete.each {|hc| hc.call }
56
59
  end
57
60
 
58
61
  @parser.on_body = proc do |chunk|
@@ -75,7 +78,8 @@ module Hatetepe
75
78
  @bytes_read = 0
76
79
  end
77
80
 
78
- [:request, :response, :header, :body_chunk, :complete, :error].each do |hook|
81
+ [:request, :response, :header, :headers_complete,
82
+ :body_chunk, :complete, :error].each do |hook|
79
83
  define_method :"on_#{hook}" do |&block|
80
84
  store = instance_variable_get(:"@on_#{hook}")
81
85
  return store unless block
@@ -1,3 +1,3 @@
1
1
  module Hatetepe
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hatetepe
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Lars Gierth
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-03 00:00:00 Z
13
+ date: 2011-06-06 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http_parser.rb
@@ -70,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
- hash: 678111023
73
+ hash: -899733391
74
74
  segments:
75
75
  - 0
76
76
  version: "0"
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- hash: 678111023
82
+ hash: -899733391
83
83
  segments:
84
84
  - 0
85
85
  version: "0"