File: connect.rb

package info (click to toggle)
ruby-em-socksify 0.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 168 kB
  • sloc: ruby: 256; sh: 20; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 803 bytes parent folder | download | duplicates (3)
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
module EventMachine
  module Connectify
    module CONNECT
      def connect_send_handshake
        header =  "CONNECT #{@connect_target_host}:#{@connect_target_port} HTTP/1.0\r\n"
        if @connect_username || @connect_password
          encoded_credentials = Base64.strict_encode64([@connect_username, @connect_password].join(":"))
          header << "Proxy-Authorization: Basic #{encoded_credentials}\r\n"
        end

        header << "\r\n"
        send_data(header)
      end

      private

      def connect_parse_response
        unless @connect_data =~ %r{\AHTTP/1\.[01] 200 .*\r\n\r\n}m
          raise CONNECTError.new, "Unexpected response: #{@connect_data}"
        end

        connect_unhook
      rescue Exception => e
        @connect_deferrable.fail e
      end
    end
  end
end