国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

Django4.0 中間件-處理流式響應

2022-03-16 17:46 更新

與 ?HttpResponse ?不同,?StreamingHttpResponse? 沒有 ?content ?屬性。因此,中間件不能再假設(shè)所有響應有 ?content ?屬性。如果它們需要訪問 ?content?,它們必須為流式響應進行測試,并且調(diào)整其行為:

if response.streaming:
    response.streaming_content = wrap_streaming_content(response.streaming_content)
else:
    response.content = alter_content(response.content)

注解:?streaming_content ?被假設(shè)為體積太大而無法在內(nèi)存中保存。響應中間件可以將其包裝在一個新的生成器里,但不能使用它。包裝通常如下實現(xiàn):

def wrap_streaming_content(content):
    for chunk in content:
        yield alter_content(chunk)


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號