Example #1
0
    def push(self, url, vumi_message):
        config = self.get_static_config()
        data = vumi_message.to_json().encode('utf-8')
        try:
            auth, url = extract_auth_from_url(url.encode('utf-8'))
            headers = {
                'Content-Type': 'application/json; charset=utf-8',
            }
            if auth is not None:
                username, password = auth

                if username is None:
                    username = ''

                if password is None:
                    password = ''

                headers.update({
                    'Authorization': 'Basic %s' % (
                        base64.b64encode('%s:%s' % (username, password)),)
                })
            resp = yield http_request_full(
                url, data=data, headers=headers, timeout=config.timeout)
            if not (200 <= resp.code < 300):
                # We didn't get a 2xx response.
                log.warning('Got unexpected response code %s from %s' % (
                    resp.code, url))
        except SchemeNotSupported:
            log.warning('Unsupported scheme for URL: %s' % (url,))
        except HttpTimeoutError:
            log.warning("Timeout pushing message to %s" % (url,))
        except DNSLookupError:
            log.warning("DNS lookup error pushing message to %s" % (url,))
        except ConnectionRefusedError:
            log.warning("Connection refused pushing message to %s" % (url,))
Example #2
0
def cross_domain_xhr(request):
    auth, url = extract_auth_from_url(request.POST.get('url', None))
    response = requests.get(url, auth=auth)

    return HttpResponse(
        response.content,
        status=response.status_code)
Example #3
0
    def push(self, url, vumi_message):
        config = self.get_static_config()
        data = vumi_message.to_json().encode('utf-8')
        try:
            auth, url = extract_auth_from_url(url.encode('utf-8'))
            headers = {
                'Content-Type': 'application/json; charset=utf-8',
            }
            if auth is not None:
                username, password = auth

                if username is None:
                    username = ''

                if password is None:
                    password = ''

                headers.update({
                    'Authorization':
                    'Basic %s' % (base64.b64encode('%s:%s' %
                                                   (username, password)), )
                })
            resp = yield http_request_full(url,
                                           data=data,
                                           headers=headers,
                                           timeout=config.timeout)
            if not (200 <= resp.code < 300):
                # We didn't get a 2xx response.
                log.warning('Got unexpected response code %s from %s' %
                            (resp.code, url))
        except SchemeNotSupported:
            log.warning('Unsupported scheme for URL: %s' % (url, ))
        except HttpTimeoutError:
            log.warning("Timeout pushing message to %s" % (url, ))
        except DNSLookupError:
            log.warning("DNS lookup error pushing message to %s" % (url, ))
        except ConnectionRefusedError:
            log.warning("Connection refused pushing message to %s" % (url, ))
Example #4
0
 def test_extract_auth_from_url_with_username(self):
     auth, url = extract_auth_from_url('http://[email protected]')
     self.assertEqual(auth, ('u', None))
     self.assertEqual(url, 'http://go.vumi.org')
Example #5
0
 def test_extract_auth_from_url_with_auth(self):
     auth, url = extract_auth_from_url('http://*****:*****@go.vumi.org')
     self.assertEqual(auth, ('u', 'p'))
     self.assertEqual(url, 'http://go.vumi.org')
Example #6
0
 def test_extract_auth_from_url_no_auth(self):
     auth, url = extract_auth_from_url('http://go.vumi.org')
     self.assertEqual(auth, None)
     self.assertEqual(url, 'http://go.vumi.org')
Example #7
0
def cross_domain_xhr(request):
    auth, url = extract_auth_from_url(request.POST.get('url', None))
    response = requests.get(url, auth=auth)

    return HttpResponse(response.content, status=response.status_code)