-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCGIxml.rb
40 lines (33 loc) · 955 Bytes
/
SCGIxml.rb
1
2
3
4
5
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
#! /usr/bin/ruby
# Author: Dario Meloni <[email protected]>
require 'xmlrpc/client'
require 'xmlrpc/xmlrpcs'
require 'socket'
require 'scgi'
class SCGIXMLClient < XMLRPC::ClientS
def new_socket( info, async )
SCGIWrappedSocket.new(UNIXSocket.new(info.first),info.last)
end
end
class SCGIWrappedSocket
attr_accessor :sock, :uri, :method
def initialize( sock, uri, method="POST" )
@sock, @uri, @method = sock, uri, method
end
def write(x)
msg = SCGI::Wrapper.wrap(x,@uri,@method)
r = @sock.write(msg)
if r != msg.length then
raise IOException, "Not all the data has been sent (#{r}/#{msg.length})"
end
return x.length
end
def read()
data = @sock.read()
# receiving an html response (very dumb parsing)
# divided in 2
# 1 -> status + headers
# 2 -> data
return data.split("\r\n\r\n").last
end
end