Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic examples simply crash #142

Closed
laulin opened this issue May 22, 2024 · 7 comments
Closed

Basic examples simply crash #142

laulin opened this issue May 22, 2024 · 7 comments

Comments

@laulin
Copy link

laulin commented May 22, 2024

Hello,

I was just looking at this library, I install it and when I run basic example (write.lua, querystring.lua, ...), it crashes with following error :

Pegasus is up on 0.0.0.0:9090
Request for: GET /index.html
lua5.3: /usr/local/share/lua/5.3/pegasus/response.lua:122: can't set status code, it was already sent
stack traceback:
	[C]: in function 'assert'
	/usr/local/share/lua/5.3/pegasus/response.lua:122: in function 'pegasus.response.statusCode'
	/usr/local/share/lua/5.3/pegasus/response.lua:154: in function 'pegasus.response.writeDefaultErrorMessage'
	/usr/local/share/lua/5.3/pegasus/handler.lua:142: in function 'pegasus.handler.processRequest'
	/usr/local/share/lua/5.3/pegasus/init.lua:31: in function 'pegasus.start'
	write.lua:5: in main chunk
	[C]: in ?

I read response.lua, I saw the flag "_headersSended" but I dont catch the meaning of assert(not _headersSended ...). May be someone can explain that part ?

Thank you for your time !

@Tieske
Copy link
Contributor

Tieske commented May 22, 2024

Can you be more specific? which example are you trying to run?

@laulin
Copy link
Author

laulin commented May 22, 2024

I found the problem : in Handler:processRequest (handler.lua:137), the fonction expectes the callback return something (eg true) otherwise it will return the error message. So the example should be :

local Pegasus = require 'pegasus'

local server = Pegasus:new({location="/index.html"})

server:start(function (req, res)
  res:addHeader('Content-Type', 'text/html'):write('hello pegasus world!')
  return true
end)

@Tieske
Copy link
Contributor

Tieske commented May 22, 2024

Mind creating a PR with a fix for the example?

@laulin
Copy link
Author

laulin commented May 23, 2024

Sure, I just did it. But examples "copas.lua" and "app.lua" can't be fixed : pegasus.json is missing in the repository. Do you know why this feature was removed ?

@Tieske
Copy link
Contributor

Tieske commented May 23, 2024

dang, yup, that was never merged, see #138 .

I'll send a fix for that one.

EDIT: fix is in #145

@Tieske
Copy link
Contributor

Tieske commented May 30, 2024

@laulin I think this can be closed now, PR's have been merged.

@EvandroLG
Copy link
Owner

Closing it, thanks guys!
@laulin please feel free to reopen this if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants