重写响应头
更新时间: 2019-03-14 10:05
下载对象时,可以重写部分HTTP/HTTPS响应头信息。可重写的响应头信息见下表:
参数 | 作用 |
---|---|
GetObjectInput.ResponseContentType | 重写HTTP/HTTPS响应中的Content-Type |
GetObjectInput.ResponseContentLanguage | 重写HTTP/HTTPS响应中的Content-Language |
GetObjectInput.ResponseExpires | 重写HTTP/HTTPS响应中的Expires |
GetObjectInput.ResponseCacheControl | 重写HTTP/HTTPS响应中的Cache-Control |
GetObjectInput.ResponseContentDisposition | 重写HTTP/HTTPS响应中的Content-Disposition |
GetObjectInput.ResponseContentEncoding | 重写HTTP/HTTPS响应中的Content-Encoding |
以下代码展示了如何重写响应头:
- // 引入依赖包
- import (
- "fmt"
- "obs"
- )
- var ak = "*** Provide your Access Key ***"
- var sk = "*** Provide your Secret Key ***"
- var endpoint = "https://your-endpoint"
- // 创建ObsClient结构体
- var obsClient, _ = obs.New(ak, sk, endpoint)
- func main() {
- input := &obs.GetObjectInput{}
- input.Bucket = "bucketname"
- input.Key = "objectkey"
- input.ResponseContentType = "image/jpeg"
- output, err := obsClient.GetObject(input)
- if err == nil {
- defer output.Body.Close()
- // 获取重写的响应头
- fmt.Printf("ContentType:%s\n", output.ContentType)
- } else if obsError, ok := err.(obs.ObsError); ok {
- fmt.Printf("Code:%s\n", obsError.Code)
- fmt.Printf("Message:%s\n", obsError.Message)
- }
- }
父主题:下载对象