Skip to content

Could you add HTTPS support to the httplibrary? #7

Closed
@testipena

Description

@testipena

Hello!

Could you add an elegant way to use HTTPS with the httplibrary?

I modified the livetest.py and __ init__.py in the following way and got https requests to work.

livetest.py

def __init__(self, host, scheme='http', relative_to=None):
    self.host = host
    self.relative_to = relative_to
    self.conn = {}
    self._load_conn(scheme)
    self.scheme = scheme
    self.extra_environ = {}
    self.reset()

def _do_httplib_request(self, req):
    "Convert WebOb Request to httplib request."
    headers = dict((name, val) for name, val in req.headers.iteritems())
    if req.scheme not in self.conn:
        self._load_conn(self.scheme)

    conn = self.conn[self.scheme]
    conn.request(req.method, req.path_qs, req.body, headers)

    webresp = conn.getresponse()
    res = webtest.TestResponse()
    res.status = '%s %s' % (webresp.status, webresp.reason)
    res.body = webresp.read()
    response_headers = []
    for headername in dict(webresp.getheaders()).keys():
        for headervalue in webresp.msg.getheaders(headername):
            response_headers.append((headername, headervalue))
    res.headerlist = response_headers
    res.errors = ''
    return res

and __ init.py __

    def __init__(self, http, scheme,  host=None):
        # daddy
        self._http = http

        # the livetest app
        if host:
            self.app = livetest.TestApp(host, scheme)
        else:
            self.app = None

        # the last request
        self.response = None

        # requirements for the next request
        # None -> no requirements
        # True -> request should succeed
        # False -> request should not succeed
        # string -> response status code should startwith(string)
        self.next_request_should = None

        # setup new http context
        self.post_process_request(None)


# internal
def __init__(self, scheme):
    self._contexts = [HTTP.Context(self, scheme)]

def create_http_context(self, scheme, host=None):
    """
    Sets the HTTP host to use for future requests. You must call this
    before issuing any HTTP requests.
    `scheme` is used to determine if the connection is made using http or https 
    `host` is the name of the host, optionally with port (e.g. 'google.com' or 'localhost:5984')
    """
    if host == None:
        host = self.context.app.host
    logger.info("Host for next HTTP request set to '%s'" % host)
    logger.info("Scheme for the next HTTP request is '%s'" % scheme)
    self._contexts.append(HTTP.Context(self, scheme, host))

There seems to be some issue when the modified library is taken into use in the Robot Framework the library needs an argument to work correctly.

BR. testipena

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions