루비로 작성된 HTTP 인터셉트 프록시의 시작이 있습니다Ruby에서 HTTP 차단 프록시 사용에 대한 도움이 필요하십니까?
require 'socket' # Get sockets from stdlib
server = TCPServer.open(8080) # Socket to listen on port 8080
loop { # Servers run forever
Thread.start(server.accept) do |client|
puts "** Got connection!"
@output = ""
@host = ""
@port = 80
while line = client.gets
line.chomp!
if (line =~ /^(GET|CONNECT) .*(\.com|\.net):(.*) (HTTP\/1.1|HTTP\/1.0)$/)
@port = $3
elsif (line =~ /^Host: (.*)$/ && @host == "")
@host = $1
end
print line + "\n"
@output += line + "\n"
# This *may* cause problems with not getting full requests,
# but without this, the loop never returns.
break if line == ""
end
if (@host != "")
puts "** Got host! (#{@host}:#{@port})"
out = TCPSocket.open(@host, @port)
puts "** Got destination!"
out.print(@output)
while line = out.gets
line.chomp!
if (line =~ /^<proxyinfo>.*<\/proxyinfo>$/)
# Logic is done here.
end
print line + "\n"
client.print(line + "\n")
end
out.close
end
client.close
end
}
내가 HTTP 요청 중 대상은 다음 HTTP 응답을 읽고 특별한 HTML 태그를 기반으로 논리를 수행 구문 분석 만든이 간단한 프록시 . 프록시는 대부분 작동하지만 바이너리 데이터 및 HTTPS 연결을 처리하는 데 문제가있는 것 같습니다.
어떻게 이러한 문제를 해결할 수 있습니까?