tmm1 (owner)

Revisions

  • fa3859 tmm1 Sat Apr 04 01:34:31 -0700 2009
gist: 90152 Download_button fork
public
Description:
first stab at an EM fastcgi client
Public Clone URL: git://gist.github.com/90152.git
Embed All Files: show embed
Ruby #
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
41
require 'rubygems'
require 'eventmachine'
 
EM.run{
  module FCGIHandler
    def post_init
      p [:connected]
    end
    def receive_data data
      p [:data, data]
      header = data.unpack('CCnnCC')
      p data.unpack(%[CCnnCCa#{header[3]}])
 
=begin
send_data %[\001\006\000\001\000d\004\000Status: 404 Not Found\r\nX-Powered-By: PHP/5.2.8\r\nContent-type: text/html\r\n\r\nNo input file specified.\n\000\000\000\000]
send_data %[\001\003\000\001\000\b\000\000\000\000\000\000\000s: ]
=end
 
      html = %[Status: 200 OK\r\nContent-type: text/plain\r\n\r\nhello world\n]
      padlen = 0#html.size%8
      send_data [1,6,1,html.size,padlen,0,html,%[\000]*padlen].pack('CCnnCCa*a*')
 
      send_data [1,6,1,0,0,0].pack('CCnnCC')
 
      endreq = [0,0,0,0,0].pack('NCC3')
      send_data [1,3,1,endreq.size,0,0,endreq].pack('CCnnCCa*')
 
      close_connection_after_writing
    end
    def send_data data
      p [:send, data]
      super
    end
    def unbind
      p [:disconnected]
    end
    
  end
 
  EM.start_server 'localhost', 12345, FCGIHandler
}