简体   繁体   English

金字塔:是否设置Content-Type以匹配匹配的header?

[英]Pyramid: Set Content-Type in response to match accept header?

We're using the pyramid web framework. 我们正在使用金字塔网络框架。 We use the accept predicate to match on the client's Accept header. 我们使用accept谓词来匹配客户端的Accept标头。 We use some custom headers for our json responses, like application/vnd.whatever+json . 我们为json响应使用一些自定义标头,例如application/vnd.whatever+json

What I would like is for the Content-Type of the response to be set equal to the accept predicate value. 我想要将响应的Content-Type设置为等于accept谓词值。

Currently pyramid always sends back application/json . 目前,金字塔总是发回application/json

How should I go about having the Content-Type of the response set to match the custom media type in the request Accept header that was negotiated? 我应该如何将响应的Content-Type设置为与协商的请求Accept标头中的自定义媒体类型相匹配?

To set response header use: 要设置响应头,请使用:

request.response.content_type = 'application/download'

This will set Content-Type for download, but you can set whatever you like. 这将设置要下载的Content-Type,但是您可以设置任何您喜欢的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM