Module: EventMachine::Wssh::Connect::Http
- Defined in:
- lib/em/wssh/connect.rb
Instance Attribute Summary collapse
-
#dst ⇒ Object
Returns the value of attribute dst.
Instance Method Summary collapse
- #log(*msg) ⇒ Object
- #onbody ⇒ Object
- #onopen ⇒ Object
- #post_init ⇒ Object
- #receive_data(data) ⇒ Object
- #receive_line(line) ⇒ Object
- #unbind ⇒ Object
- #wssh(data) ⇒ Object
Instance Attribute Details
#dst ⇒ Object
Returns the value of attribute dst.
101 102 103 |
# File 'lib/em/wssh/connect.rb', line 101 def dst @dst end |
Instance Method Details
#log(*msg) ⇒ Object
103 104 105 |
# File 'lib/em/wssh/connect.rb', line 103 def log *msg dst.log *msg end |
#onbody ⇒ Object
153 154 155 156 157 |
# File 'lib/em/wssh/connect.rb', line 153 def onbody @body=[@hdrs] @hdrs='' send_data "HTTP/1.0 200 Ok\r\n\r\n" end |
#onopen ⇒ Object
159 160 161 162 |
# File 'lib/em/wssh/connect.rb', line 159 def onopen @body.each{|data| wssh data} @body=true end |
#post_init ⇒ Object
111 112 113 114 115 116 |
# File 'lib/em/wssh/connect.rb', line 111 def post_init self.dst = Dst.new self port, ip = Socket.unpack_sockaddr_in get_peername log "Client connected from", "#{ip}:#{port}" end |
#receive_data(data) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/em/wssh/connect.rb', line 118 def receive_data data if @body if Array===@body @body << data else wssh data end return end if @hdrs @hdrs << data else @hdrs = data end while m=/\r?\n/.match(@hdrs) @hdrs=m.post_match receive_line m.pre_match end end |
#receive_line(line) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/em/wssh/connect.rb', line 139 def receive_line line @nhdr||=0 if 1==(@nhdr+=1) m=/^connect\s+([-.\w]+):22(?:$|\s)/i.match line return @wssh = m[1] if m @hdrs='' log "Bad request" send_data "HTTP/1.0 500 Bad request\r\n\r\n" dst.bye else dst.connect! @wssh if 0==line.length end end |
#unbind ⇒ Object
164 165 166 167 |
# File 'lib/em/wssh/connect.rb', line 164 def unbind log "Client disconnected" dst.bye end |
#wssh(data) ⇒ Object
107 108 109 |
# File 'lib/em/wssh/connect.rb', line 107 def wssh data dst.send data end |