Class: Arpie::HTTPTestProtocol

Inherits:
Protocol
  • Object
show all
Defined in:
lib/arpie/xmlrpc.rb

Overview

This simulates a very basic HTTP XMLRPC client/server. It is not recommended to use this with production code.

Constant Summary collapse

CAN_SEPARATE_MESSAGES =
true

Constants included from Arpie

MTU

Instance Attribute Summary

Attributes inherited from Protocol

#metabuffer, #stowbuffer

Instance Method Summary collapse

Methods inherited from Protocol

#again!, #assemble, #assemble!, #to

Methods included from Arpie

#bogon!, #incomplete!

Instance Method Details

#from(binary) {|body| ... } ⇒ Object

Yields:

  • (body)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/arpie/xmlrpc.rb', line 72

def from binary
  # Simply strip all HTTP headers.
  binary && binary.size > 0 or incomplete!
  header, body_and_rest = binary.split(/\r\n\r\n/, 2)
  header && body_and_rest or incomplete!

  header =~ /^\s*content-length:\s+(\d+)$\s*/xi or stream_error! "No content-length was provided."
  content_length = $1.to_i

  content_length <= 0 
  body_and_rest.size >= content_length or incomplete!

  body = body_and_rest[0, content_length]

  yield body

  header.size + 4 + content_length
end