Skip to content

Commit

Permalink
Add experimental code
Browse files Browse the repository at this point in the history
  • Loading branch information
xyproto committed Oct 2, 2024
1 parent 3755f33 commit f811651
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
11 changes: 6 additions & 5 deletions engine/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}))

Expand Down
5 changes: 4 additions & 1 deletion engine/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions samples/www/index.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
print("hello")
flush()
close()
sleep(5)
print("finally")

0 comments on commit f811651

Please sign in to comment.