-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic proxy support #19
base: master
Are you sure you want to change the base?
Conversation
Thanks for attention and contribution! Also, this functionality should be covered by tests. |
def send_message_through_proxy(self, url, payload, receiver, proxy): | ||
payload['chat_id'] = receiver | ||
self.logger.debug('Sending message to %s . Using proxy' % receiver) | ||
response = requests.post(url, data=payload, proxies=dict(http=proxy, https=proxy)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to refrain from the direct use of requests
. Sentry has internal, unified utils to interact with network.
Please, look for safe_urlopen() built-in function. It supports params
to pass additional options, like proxy-settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't use params
because this argument for query data https://github.com/requests/requests/blob/master/requests/sessions.py#L455
Is it worth to add PR to sentry for adding proxy functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, there is already one getsentry/sentry#6784
@@ -124,6 +138,12 @@ def send_message(self, url, payload, receiver): | |||
) | |||
self.logger.debug('Response code: %s, content: %s' % (response.status_code, response.content)) | |||
|
|||
def send_message_through_proxy(self, url, payload, receiver, proxy): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method looks like almost copy of send_message
method.
I propose to use one send_message
, and add proxies like this:
response = safe_urlopen(
method='POST',
url=url,
json=payload,
params=self.get_request_params(),
)
Where get_request_params()
will return proxies settings, if it required.
There are several questions left