Created
October 17, 2016 20:16
-
-
Save bkwaku/595a02a11d814713d5e87aaf015ff0fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'date' | |
require 'logger' | |
require 'socket' | |
begin | |
require 'openssl' | |
BaseSSLError = OpenSSL::SSL::SSLError | |
raise | |
ssl = nil | |
class BaseSSLError < OpenSSL::SSL::SSLError | |
end | |
rescue | |
end | |
log = Logger.new('logs.log') | |
$port_by_scheme = { | |
http: 80, | |
https: 443 | |
} | |
setdate = '01-01-2014' | |
RECENT_DATE = Date::strptime(setdate, "%d-%m-%Y") | |
class DummyConnection | |
#Used to detect a failed ConnectionCls import. | |
end | |
class HTTPConnection < Net::HTTP | |
=begin Based on httplib.HTTPConnection but provides an extra constructor | |
backwards-compatibility layer between older and newer Pythons. | |
Additional keyword parameters are used to configure attributes of the connection. | |
Accepted parameters include: | |
- ``strict``: See the documentation on :class:`urllib3.connectionpool.HTTPConnectionPool` | |
- ``source_address``: Set the source address for the current connection. | |
.. note:: This is ignored for Python 2.6. It is only applied for 2.7 and 3.x | |
- ``socket_options``: Set specific options on the underlying socket. If not specified, then | |
defaults are loaded from ``HTTPConnection.default_socket_options`` which includes disabling | |
Nagle's algorithm (sets TCP_NODELAY to 1) unless the connection is behind a proxy. | |
For example, if you wish to enable TCP Keep Alive in addition to the defaults, | |
you might pass:: | |
HTTPConnection.default_socket_options + [ | |
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), | |
] | |
Or you may want to disable the defaults by passing an empty list (e.g., ``[]``). | |
=end | |
default = $port_by_scheme[:http] | |
#: Disable Nagle's algorithm by default. | |
#: ``[(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]`` | |
#default_socket_options = [(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)] | |
is_verified = false | |
def initialize(*args, **keyword_args) | |
end | |
def _new_conn() | |
=begin | |
Establish a socket connection and set nodelay on it. | |
:return: New connection | |
=end | |
extra_kw = Hash.new | |
if self.source_address | |
extra_kw[:source_address] = self.source_address | |
end | |
if self.socket_options | |
extra_kw[:socket_options] = self.socket_options | |
end | |
begin | |
conn = Net::HTTP.start() | |
rescue | |
return conn | |
end | |
end | |
def _prepare_conn(conn) | |
self.socket = conn | |
end | |
def connect() | |
conn = self._new_conn() | |
self._prepare_conn(conn) | |
end | |
def request_chunked(method, url, body=nil, headers=nil) | |
=begin | |
Alternative to the common request method, which sends the | |
body with chunked encoding and not as one block | |
=end | |
end | |
end | |
#puts RUBY_PLATFORM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment