Sha256: 8b588eb071497d9efd0c8ba9deff90f183084cafe228f8236ad10fb8faeab34a

Contents?: true

Size: 683 Bytes

Versions: 11

Compression:

Stored size: 683 Bytes

Contents

class MockRequest

  attr_reader :headers, :body, :uri

  def initialize(request_string)
    lines = request_string.split("\r\n")

    # find blank line which seperates the headers from the body
    index_of_blank = nil
    lines.each_with_index{|e,i|
      index_of_blank = i if e == ""
    }

    @type, @uri = lines.first.split(/\s+/)
    if index_of_blank
      @headers = lines[1..index_of_blank]
      @body = lines[(index_of_blank + 1)..-1].first
    else
      @headers = lines[1..-1]
    end

    @headers = @headers.inject({}){|h,e|
      k,v = e.split(/:\s+/)
      h.merge k => v
    }
  end

  def get?
    @type == 'GET'
  end

  def post?
    @type == 'POST'
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
mikehale-rat-hole-0.1.0 test/mock_request.rb
mikehale-rat-hole-0.1.3 test/mock_request.rb
mikehale-rat-hole-0.1.4 test/mock_request.rb
mikehale-rat-hole-0.1.5 test/mock_request.rb
mikehale-rat-hole-0.1.6 test/mock_request.rb
mikehale-rat-hole-0.1.7 test/mock_request.rb
mikehale-rat-hole-0.1.8 test/mock_request.rb
mikehale-rat-hole-0.1.9 test/mock_request.rb
rat-hole-0.1.11 test/mock_request.rb
rat-hole-0.1.10 test/mock_request.rb
rat-hole-0.1.9 test/mock_request.rb