Python startswith() 函数 判断字符串开头

在阿里云oss API 身份验证构建CanonicalizedOSSHeaders的方法时,要将 x-oss- 为前缀的HTTP Header提取出来作为CanonicalizedOSSHeaders,python 中提供了startwith()方法实现该功能:
实现代码如下:

def getCanonicalizedOSSHeaders(headers){
  canon_headers = []
  for key,value in headers.items():
      lover_key = k.lower()    
      if lower_key.startswith('x-oss-'):
          canon_headers.append((lower_key, v))
      canon_headers.sort(key=lambda x: x[0])
      if canon_headers:
          return '\n'.join(k + ':' + v for k, v in canon_headers) + '\n'
      else:
          return ''
}    

你可能感兴趣的:(Python startswith() 函数 判断字符串开头)