xyproto / algernon

Small self-contained pure-Go web server with Lua, Teal, Markdown, Ollama, HTTP/2, QUIC, Redis, SQLite and PostgreSQL support ++
https://algernon.roboticoverlords.org
BSD 3-Clause "New" or "Revised" License
2.81k stars 138 forks source link

Lua scripts are downloaded when QUIC is enabled #102

Open linkerlin opened 2 years ago

linkerlin commented 2 years ago

algernon --cache=images --redis=localhost:6379 -s /root/owrt_www :443 is OK. algernon -u --cache=images --redis=localhost:6379 -s /root/owrt_www :443 will make *.lua can be downloaded. @ current master code

xyproto commented 2 years ago

Thanks for reporting! I'll reproduce the issue and look into it.

xyproto commented 2 years ago

I'm currently unable to reproduce the issue. Here are the steps I tried:

git clone https://github.com/xyproto/algernon
cd algernon
go build -mod=vendor
sudo setcap cap_net_bind_service=+ep ./algernon
./algernon --cache=images -s samples :443

Then in another window ("Hello, Lua!" is the reply I got back from the server):

curl -k 'https://localhost/lua/'
Hello, Lua!
curl -k 'https://localhost/lua/index.lua'
Hello, Lua!

And then with ./algernon -u --cache=images -s samples :443, I get the same replies:

curl -k 'https://localhost/lua/'
Hello, Lua!
curl -k 'https://localhost/lua/index.lua'
Hello, Lua!

The same thing happens if I add a test.lua file and try to download it.

What are the steps to reproduce the issue?

linkerlin commented 2 years ago

Added a line :

content([=[text/html; charset=utf-8]=]);

fixed it. weired.

xyproto commented 2 years ago

Declaring the content type at the top of a Lua script with a call to content is a good practice, but the lack of one should not cause the contents of the Lua script to be downloaded. If this happens, it's a bug, and I would very much like to fix it.

algernon/samples/index.lua only contains print("Hello, Lua!"), and the file is not downloaded. If I change it to something else like 2+3, the file is not downloaded either.

Please include the steps to reproduce the issue.

linkerlin commented 2 years ago

Finally, I know why . If I put -u at the first arg of arglist algernon -u --cache=images --redis=localhost:6379 -s /root/owrt_www :443 problem reproduced! And if I move the -u to the last of the arglist, everything is fine. algernon --cache=images --redis=localhost:6379 -s -u /root/owrt_www :443

Maybe the init of Algernon is too complex without a lua script? What about added a init.lua for the init of Algernon?

tooolbox commented 2 years ago

Maybe the init of Algernon is too complex without a lua script? What about added a init.lua for the init of Algernon?

You already proposed init.lua and that has its own merits but not as an imagined decomplication of the command-line flags. Seems like there's just a bug that needs to be fixed.

xyproto commented 2 years ago

When running both of these commands, everything works fine here:

Nothing I could find in the source code hints that the order of the -u flag should matter.

Please provide steps that I can follow to reproduce the issue here. I don't have /root/owrt_www and the files that are there.

linkerlin commented 2 years ago
  • go build -mod=vendor

DEBUG SITE Click Hello Lua will download a lua-file; Click Counter is OK. Updated algernon from github and rebuld it with go build -mod=vendor. algernon --cache=images --redis=localhost:6379 -s -u /root/owrt_www :443 DEBUG SITE The samples is the same as algernon/samples from the source code. Why?

linkerlin commented 2 years ago

Added

content([=[text/html; charset=utf-8]=]);

to /samples/permissions/index.lua at line 0 fixed the download file problem.

linkerlin commented 2 years ago

Maybe added a checking for any http-response head missing content key and added
content: "text/html; charset=utf-8" as default ?

linkerlin commented 2 years ago

Update: change browser from chrome to safari, and problem disappeared.

linkerlin commented 2 years ago

Update: change browser from chrome to safari, and problem disappeared.

Safari donnot connect to my site with QUIC. So the -u option is the root cause.

linkerlin commented 2 years ago

I have try to remove -u and the chrome also work . What happened?

xyproto commented 2 years ago
  1. Is there anything unusual about the Lua files in /root/owrt_www? Unusual permissions, uppercase filenames or unusual unicode symbols?
  2. Please provide steps to reproduce the issue that will also work on systems that don't have /root/owrt_www, if possible.

I will try reproducing the issue in Chrome as well.

linkerlin commented 2 years ago
  1. Is there anything unusual about the Lua files in /root/owrt_www? Unusual permissions, uppercase filenames or unusual unicode symbols?
  2. Please provide steps to reproduce the issue that will also work on systems that don't have /root/owrt_www, if possible.

I will try reproducing the issue in Chrome as well.

You're right. When some bad-thing happened in a non-debug-mode algernon, it will triger a download .