lib/async/http/request.rb in async-http-0.24.3 vs lib/async/http/request.rb in async-http-0.25.0

- old
+ new

@@ -17,23 +17,52 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. require_relative 'body/buffered' +require_relative 'middleware' module Async module HTTP - class Request < Struct.new(:authority, :method, :path, :version, :headers, :body) + class Request prepend Body::Buffered::Reader + def initialize(authority = nil, method = nil, path = nil, version = nil, headers = [], body = nil) + @authority = authority + @method = method + @path = path + @version = version + @headers = headers + @body = body + end + + attr_accessor :authority + attr_accessor :method + attr_accessor :path + attr_accessor :version + attr_accessor :headers + attr_accessor :body + + def head? + self.method == HEAD + end + + def connect? + self.method == CONNECT + end + def self.[](method, path, headers, body) body = Body::Buffered.wrap(body) self.new(nil, method, path, nil, headers, body) end def idempotent? - method != 'POST' && (body.nil? || body.empty?) + method != POST && (body.nil? || body.empty?) + end + + def to_s + "#{@method} #{@path} #{@version}" end end end end