def build_headers(self, request=None):
        headers = dict()
        header_params = request.get_headers()
        headers[constant.X_CA_TIMESTAMP] = DateUtil.get_timestamp()
        headers[constant.X_CA_KEY] = self.__app_key

        body = request.get_body();

        headers[constant.X_CA_NONCE] = UUIDUtil.get_uuid()

        if request.get_content_type():
            headers[constant.HTTP_HEADER_CONTENT_TYPE] = request.get_content_type()
        else:
            headers[constant.HTTP_HEADER_CONTENT_TYPE] = constant.CONTENT_TYPE_JSON

        if constant.HTTP_HEADER_ACCEPT in header_params \
                and header_params[constant.HTTP_HEADER_ACCEPT]:
            headers[constant.HTTP_HEADER_ACCEPT] = header_params[constant.HTTP_HEADER_ACCEPT]
        else:
            headers[constant.HTTP_HEADER_ACCEPT] = constant.CONTENT_TYPE_JSON

        if constant.POST == request.get_method() and constant.CONTENT_TYPE_STREAM == request.get_content_type():
            headers[constant.HTTP_HEADER_CONTENT_MD5] = md5_tool.get_md5_base64_str(request.get_body())
            str_to_sign = signature_composer.build_sign_str(uri=request.get_url(), method=request.get_method(),
                                                            headers=headers)
        else:
            str_to_sign = signature_composer.build_sign_str(uri=request.get_url(), method=request.get_method(),
                                                            headers=headers, body=body)

        headers[constant.X_CA_SIGNATURE] = sha_hmac256.sign(str_to_sign, self.__app_secret)

        return headers
Exemple #2
0
    def build_headers(self, request=None):
        headers = dict()
        header_params = request.get_headers()
        headers[constant.X_CA_TIMESTAMP] = DateUtil.get_timestamp()
        headers[constant.X_CA_KEY] = self.__app_key

        body = request.get_body()

        headers[constant.X_CA_NONCE] = UUIDUtil.get_uuid()

        if request.get_content_type():
            headers[constant.
                    HTTP_HEADER_CONTENT_TYPE] = request.get_content_type()
        else:
            headers[
                constant.HTTP_HEADER_CONTENT_TYPE] = constant.CONTENT_TYPE_JSON

        if constant.HTTP_HEADER_ACCEPT in header_params \
                and header_params[constant.HTTP_HEADER_ACCEPT]:
            headers[constant.HTTP_HEADER_ACCEPT] = header_params[
                constant.HTTP_HEADER_ACCEPT]
        else:
            headers[constant.HTTP_HEADER_ACCEPT] = constant.CONTENT_TYPE_JSON

        if constant.POST == request.get_method():
            if constant.CONTENT_TYPE_STREAM == request.get_content_type():
                headers[constant.
                        HTTP_HEADER_CONTENT_MD5] = md5_tool.get_md5_base64_str(
                            request.get_body())

            elif constant.CONTENT_TYPE_JSON == request.get_content_type():
                headers[constant.
                        HTTP_HEADER_CONTENT_MD5] = md5_tool.get_md5_base64_str(
                            json.dumps(request.get_body()))

            str_to_sign = signature_composer.build_sign_str(
                uri=request.get_url(),
                method=request.get_method(),
                headers=headers)
        else:
            str_to_sign = signature_composer.build_sign_str(
                uri=request.get_url(),
                method=request.get_method(),
                headers=headers,
                body=body)

        headers[constant.X_CA_SIGNATURE] = sha_hmac256.sign(
            str_to_sign, self.__app_secret)

        return headers
Exemple #3
0
    def build_headers(self, request=None):
        headers = dict()
        header_params = request.get_headers()
        headers[constant.X_CA_TIMESTAMP] = DateUtil.get_timestamp()
        headers[constant.Authorization] = "APPCODE " + self.__appcode

        headers[constant.X_CA_NONCE] = UUIDUtil.get_uuid()

        if request.get_content_type():
            headers[constant.
                    HTTP_HEADER_CONTENT_TYPE] = request.get_content_type()
        else:
            headers[
                constant.HTTP_HEADER_CONTENT_TYPE] = constant.CONTENT_TYPE_JSON

        headers[constant.HTTP_HEADER_ACCEPT] = constant.CONTENT_TYPE_JSON

        return headers