Log
#func Log(ctx: i64)Prints [HTTP], the method and the path of the request to the standard output; no status, since it runs before the handler answers.
import net.http
import net.http.middleware
import net.router
func home(ctx: i64):
middleware.Log(ctx)
middleware.AllowAll(ctx)
middleware.Secure(ctx)
middleware.NoCache(ctx)
http.Text(ctx, "hello")
end
func logo(ctx: i64):
middleware.Cache(ctx, 3600)
http.Text(ctx, "png")
end
func main:
mut r := router.NewRouter()
router.Get(r, "/", home)
router.Get(r, "/logo.png", logo)
mut s := http.NewServer(19624)
http.Use(s, r)
_ := http.RunBackground(s)
a := http.Get("http://127.0.0.1:19624/")
each name in [
"access-control-allow-origin", "x-content-type-options", "x-frame-options", "cache-control"
]:
println name + ": " + http.GetHeader(a, name)
end
println http.GetHeader(http.Get("http://127.0.0.1:19624/logo.png"), "cache-control")
end[HTTP] GET / access-control-allow-origin: * x-content-type-options: nosniff x-frame-options: DENY cache-control: no-store, no-cache, must-revalidate max-age=3600