EvandroLG / pegasus.lua

:rocket: Pegasus.lua is an http server to work with web applications written in Lua language.
http://evandrolg.github.io/pegasus.lua/
MIT License
421 stars 36 forks source link

Should I have called req:headers() before req:post() #135

Closed wmealing closed 10 months ago

wmealing commented 10 months ago

In my trivial example.

local pegasus = require 'pegasus'

local server = pegasus:new({
  host='127.0.0.1', 
  port='9090',
  location='root/'
})

server:start(function (req, res)
      local h = req:headers()
      local data = req:receiveBody()
      print(data) 
      res:addHeader('Content-Type', 'text/html'):write('hello pegasus world!')
end)

I needed to call req:headers() to ensure that the content length attribute of req is set correctly, without this I couldn't get the body of the post request.

Have I misunderstood or is this expected behavior?

I'd be willing to attempt a fix if you're good with that.

Thanks in advance.

Tieske commented 10 months ago

the fix is in #130 , see: bae2516 (#130)

EvandroLG commented 10 months ago

@Tieske, since both PRs are quite big, would you mind creating a separate one specifically for this fix?

Tieske commented 10 months ago

@EvandroLG see #139 also created some other smaller indepedent PR's from the bigger one. Please review one-by-one, once merged I'll rebase the bigger one

EvandroLG commented 10 months ago

Thanks, @Tieske! I will be reviewing the other ones in the upcoming days.

@wmealing I just merged the solution created by @Tieske for your issue. I will be closing this issue. Please feel free to re-open if you need it.