openresty 反向代理没有立即响应客户端headers

41 views
Skip to first unread message

kitestar

unread,
Aug 8, 2024, 5:46:28 AM8/8/24
to openresty
上游接口输出headers后没有立即输出body
func testHandler(w http.ResponseWriter, r *http.Request) {
// Set the Content-Length header
fmt.Println("\n\n=======================")
w.Header().Set("Content-Length", "12240")
// Set other headers if necessary
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(200)
fmt.Println("header has been set")
// Flush the headers
if flusher, ok := w.(http.Flusher); ok {

flusher.Flush()
fmt.Println("header has been flushed")
}
w.Write([]byte("1"))
fmt.Println("body has been written")
// Wait for 20 seconds
time.Sleep(30 * time.Second)
// Write the body
w.Write([]byte("1"))
fmt.Println("body has been written")
}

openresty在header_filter阶段处理完header后,没有立即输出转发上游的headers,而是等到body接受超时才转发headers 
0E7A010D-1997-4E76-B3A7-A5ECCF053EC3.png
ngx.send_headers也没法在这个阶段调用 ,请教各位如下设置可以时openresty立即处理转发上游headers 






Reply all
Reply to author
Forward
0 new messages