def fill_all_headers(self, req):
        """Set content-type, content-md5, date to the request."""
        url = urlsplit(req.url)

        content_type, __ = mimetypes.guess_type(url.path)
        if content_type is None:
            content_type = self.DEFAULT_TYPE
            logger.warn("can not determine mime-type for {0}".format(url.path))
        if self._expires is None:
            # sign with url, no content-type for url
            req.headers.setdefault("content-type", content_type)

        if (
            req.body is not None
            and req.headers.get("content-md5") is None
            and self._allow_empty_md5 is False
        ):
            logger.debug("calculating content-md5")
            content, content_md5 = utils.cal_content_md5(req.body)
            req.body = content
            req.headers["content-md5"] = content_md5
            logger.debug("new content-md5 is: {0}".format(content_md5))
        else:
            logger.debug("skip content-md5 calculation")

        if self._expires is None:
            req.headers.setdefault(
                "date",
                time.strftime(self.DATE_FMT, time.gmtime())
            )
        return req
def fill_all_headers ( self , req ) : url = urlsplit ( req . url ) content_type , __ = mimetypes . guess_type ( url . path ) if content_type is None : content_type = self . DEFAULT_TYPE logger . warn ( "can not determine mime-type for {0}" . format ( url . path ) ) if self . _expires is None : req . headers . setdefault ( "content-type" , content_type ) if ( req . body is not None and req . headers . get ( "content-md5" ) is None and self . _allow_empty_md5 is False ) : logger . debug ( "calculating content-md5" ) content , content_md5 = utils . cal_content_md5 ( req . body ) req . body = content req . headers [ "content-md5" ] = content_md5 logger . debug ( "new content-md5 is: {0}" . format ( content_md5 ) ) else : logger . debug ( "skip content-md5 calculation" ) if self . _expires is None : req . headers . setdefault ( "date" , time . strftime ( self . DATE_FMT , time . gmtime ( ) ) ) return req
Set content-type, content-md5, date to the request.