Skip to content

Conversation

@jobala
Copy link
Contributor

@jobala jobala commented Mar 5, 2020

Overview

Adds a middleware pipeline.
Enforces TLS 1.2

Notes

The middleware pipeline is a linkedlist with middlewares as nodes. The middlewares inherit from HTTPAdapter.

Creating a middleware

class ResponseMiddleware(HTTPAdapter):
    def __init__(self):
        super().__init__()
        self.next = None

    def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):
        if self.next is None:
            return super().send(request, stream, timeout, verify, cert, proxies)

        response = self._next.send(request, stream, timeout, verify, cert, proxies)
        # do something with the response
        return response

Creating requests with middlewares

middlewares = [
    ResponseMiddleware(),
]

requests = HTTPClientFactory.with_graph_middlewares(middlewares=middlewares)

closes #2

@jobala jobala changed the base branch from dev to feat/http-client-factory March 5, 2020 18:50
@jobala jobala marked this pull request as ready for review March 7, 2020 15:22
Copy link
Contributor

@MIchaelMainer MIchaelMainer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need more context on what the plans are for this client.

@jobala jobala changed the base branch from feat/http-client-factory to dev March 13, 2020 06:44
Copy link

@ddyett ddyett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never to early to start adding documentation such as the licensing agreements

return super().send(request, **kwargs)

def _middleware_present(self):
return self._middleware
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this? It seems longer than just saying if self._middleware but I know python standards also have a thing about being explicit. not sure this adds much though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this for readability. So that the if conditions reads if middleware_present ...

def test_middleware_pipeline(self):
url = 'https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/v1.0/me'
middlewares = [
_AuthMiddleware()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_AuthMiddleware() [](start = 12, length = 17)

would be good if this test had more than one middleware so you're testing the chaining of the middleware.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested that here

@jobala jobala merged commit 63f6772 into dev Mar 23, 2020
@samwelkanda samwelkanda deleted the feat/middleware-pipeline branch October 14, 2022 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use TLS 1.2

4 participants