Class: HTTPalooza::Players::LynxPlayer
- Defined in:
- lib/httpalooza/players/lynx.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
execute!, #initialize, introducing!, #name
Constructor Details
This class inherits a constructor from HTTPalooza::Players::Base
Instance Method Details
#response ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/httpalooza/players/lynx.rb', line 6 def response output = nil if request.head? output = `lynx -head -dump '#{request.url}'` elsif request.get? output = `lynx -dump '#{request.url}'` elsif request.post? if request.params.empty? raise "This client cannot POST without parameters." end form_data = URI.encode_www_form(request.params.each_pair.to_a) output = `echo '#{form_data}' | lynx -dump -post_data '#{request.url}'` else raise "Unsupported HTTP method for this client!" end if $? == 0 code = 200 # probably, right? # Lynx prints headers when you issue -head if request.head? output = '' end Response.new(code, output) else code = case output when /Not Found/ 404 when /Internal Server Error/ 500 else 400 # sure, why not end Response.new(code, output) end end |