Example #1
0
    def callRemote(self, method, *args):

        body = xmlrpc.payloadTemplate % (
            method,
            xmlrpclib.dumps(args, allow_none=self.xmlrpclib_allow_none),
        )
        body_p = web.StringBodyProducer(body)
        headers = Headers({
            b'content-type': ['text/xml'],
            b'content-length': [str(len(body))],
        })
        logger.debug("call request to %r, args %r", self.url, args)
        resp = yield self.agent.request('POST',
                                        self.url,
                                        headers=headers,
                                        bodyProducer=body_p)
        logger.debug("response code %r", resp.code)

        resp_ct = resp.headers.getRawHeaders(b'content-type', [None])[-1]
        resp_body = yield client.readBody(resp)

        if resp.code != 200:
            raise HttpRPCError(resp.code, resp_body, resp_ct)

        # TODO: read body & parse errors
        if not resp_body:
            raise HttpRPCError(resp.code,
                               None,
                               resp_body,
                               response_content_type=resp_ct)

        response = xmlrpclib.loads(resp_body,
                                   use_datetime=self.xmlrpclib_use_datetime)
        defer.returnValue(response[0][0])
Example #2
0
    def callRemote(self, method, *args):

        logger.debug("remote call to %r, method %r with args %r", self.url,
                     method, args)

        body = json.dumps(args).encode('utf-8')
        uri = self.url + "?method=" + method

        body_p = web.StringBodyProducer(body)
        headers = Headers({b'content-type': [b'application/json']})

        resp = yield self.agent.request('POST',
                                        uri,
                                        headers=headers,
                                        bodyProducer=body_p)
        logger.debug("response code %r from %r", resp.code, uri)

        resp_ct = resp.headers.getRawHeaders(b'content-type', [None])[-1]
        resp_body = yield client.readBody(resp)

        if resp.code != 200:
            raise HttpRPCError(resp.code, resp_body, resp_ct)

        # TODO: read body & parse errors
        if not resp_body:
            raise HttpRPCError(resp.code,
                               resp_body,
                               response_content_type=resp_ct)

        response = json.loads(resp_body)
        defer.returnValue(response)
Example #3
0
 def test_too_old_request(self):
     agent = authhmac.AuthHMACAgent(self.agent, "key", "secret")
     headers = Headers({'date': [datetimeToString(time.time() - 1500)]})
     bodyp = web.StringBodyProducer("some content")
     resp = yield agent.request('POST', self.request_url(""), headers,
                                bodyp)
     yield self.check_fail(resp)
Example #4
0
 def test_wrong_md5(self):
     agent = authhmac.AuthHMACAgent(self.agent, "key", "secret")
     headers = Headers({'content-md5': ["xxx"]})
     bodyp = web.StringBodyProducer("some content")
     resp = yield agent.request('POST', self.request_url(""), headers,
                                bodyp)
     yield self.check_fail(resp)
Example #5
0
 def test_ok_post_with_ct(self):
     agent = authhmac.AuthHMACAgent(self.agent, "key", "secret")
     bodyp = web.StringBodyProducer("some content")
     headers = Headers({'content-type': ['unknown-content-type']})
     resp = yield agent.request('POST', self.request_url(""), headers,
                                bodyp)
     yield self.check_ok(resp)
Example #6
0
 def test_ok_post(self):
     agent = authhmac.AuthHMACAgent(self.agent, "key", "secret")
     bodyp = web.StringBodyProducer("some content")
     resp = yield agent.request('POST', self.request_url(""), None, bodyp)
     yield self.check_ok(resp)