diff --git a/engine/basic.go b/engine/basic.go index 1c7acfe1..612edb38 100644 --- a/engine/basic.go +++ b/engine/basic.go @@ -236,11 +236,12 @@ func (ac *Config) LoadBasicWeb(w http.ResponseWriter, req *http.Request, L *lua. } // Stop Lua functions from writing more to this client req.Close = true - - // TODO: Set up the HTTP/QUIC/HTTP/2 Server structs with a ConnContext - // field and then fetch the connection from the req.Context() - // and use it here for closing the connection. - + // Hijack and close the connection, if possible + if hijacker, ok := w.(http.Hijacker); ok { + if conn, _, err := hijacker.Hijack(); err == nil { // success + conn.Close() + } + } return 0 // number of results })) diff --git a/engine/handlers.go b/engine/handlers.go index b3d9621d..feb7d813 100644 --- a/engine/handlers.go +++ b/engine/handlers.go @@ -304,13 +304,16 @@ func (ac *Config) FilePage(w http.ResponseWriter, req *http.Request, filename, l // (especially for the case of a redirect) if httpStatus.code != 0 { recorder.WriteHeader(httpStatus.code) + } else { + recorder.WriteHeader(http.StatusOK) } // Then write to the ResponseWriter utils.WriteRecorder(w, recorder) } } else { - // The flush function just flushes the ResponseWriter + // The flush function just flushes the ResponseWriter, but writes a header first flushFunc := func() { + w.WriteHeader(http.StatusOK) recwatch.Flush(w) } // Run the lua script, with the flush feature diff --git a/samples/www/index.lua b/samples/www/index.lua new file mode 100644 index 00000000..9f421e47 --- /dev/null +++ b/samples/www/index.lua @@ -0,0 +1,5 @@ +print("hello") +flush() +close() +sleep(5) +print("finally")