roadrunner-server / roadrunner

🤯 High-performance PHP application server, process manager written in Go and powered with plugins
https://docs.roadrunner.dev
MIT License
7.91k stars 413 forks source link

[💡 FEATURE REQUEST]: Static HTTP middleware, immutable option. #1985

Open Warxcell opened 3 months ago

Warxcell commented 3 months ago

Plugin

HTTP Middleware (any)

I have an idea!

it would be cool if static HTTP middleware have option immutable - so when turned on - it would scan all files in root dir on startup and cache their properties in memory, so with that option roadrunner won't need Static HTTP middleware slows down request processing by ~10% because RR has to check each request for the corresponding file. thus enabling static http middleware, will have zero performance impact. Furthermore it can be used to send https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control immutable option.

image

Because some projects may run inside docker with read-only filesystem, so roadrunner can be 100% sure that files WON'T change after startup.

rustatian commented 3 months ago

Hey @Warxcell 👋 This is a great idea 👍 Would you be able to send a PR ?

Warxcell commented 3 months ago

Hey @Warxcell 👋 This is a great idea 👍 Would you be able to send a PR ?

I will try, but I don't have any experience with Go. :rofl:

rustatian commented 3 months ago

Sure, you may use a map[string]*os.File to have the list of scanned files. Should also check for nils, handle errors on accessing the file (log them, but not interrupt a request) and delete that file if the user deleted it from the disk, for example.

rustatian commented 3 months ago

I'll help you on the review stage 😃

Warxcell commented 3 months ago

https://github.com/roadrunner-server/static/pull/126

this is my progress so far, I have difficulties: how to scan rootDir for files, recursively?

rustatian commented 2 months ago

@Warxcell You may use filepath.Walk

Warxcell commented 2 months ago

@Warxcell You may use filepath.Walk

Thanks! I think I'm ready, but no idea how to test it tho :D neither found tests for this middleware