繁体   English   中英

如何为304 http响应代码设置Content-Type标头?

[英]How to set Content-Type header for 304 http response code?

因此,我使用了一些来自Django的装饰器来启用API上的缓存:

@require_GET
@cache_page(100)
@cache_control(max_age=100, s_maxage=100)
@csrf_exempt
def my_api(request):

问题是,text / html Content-Type标头返回了304 Not Modified响应。 我的API通常返回application / json Content-Type标头,我希望保持一致。 有没有办法告诉Django 304响应码返回哪种内容类型?

问题在这里https://github.com/django/django/blob/master/django/http/response.py#L411

编写装饰器以再次添加mimetype

def RestoreMime(fn):
  def Wrapper(*args, **kwds):
    response = fn(*args, **kwds)
    response['Content-type'] = your_mime_type
    return response
  return Wrapper

暂无
暂无

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

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