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

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

Closed
wmealing opened this issue Jan 7, 2024 · 4 comments
Closed

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

wmealing opened this issue Jan 7, 2024 · 4 comments

Comments

@wmealing
Copy link
Contributor

wmealing commented Jan 7, 2024

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
Copy link
Contributor

Tieske commented Jan 8, 2024

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

@EvandroLG
Copy link
Owner

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

@Tieske
Copy link
Contributor

Tieske commented Jan 11, 2024

@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
Copy link
Owner

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.

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