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

x.vweb: add configuration options and handle incomplete requests #20868

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Casper64
Copy link
Member

This pr adds a Config struct to x.vweb to change the default behaviour of vweb.

When vweb encounters an incomplete request it will now wait until a timeout occurs for new data instead of immediately closing the connection. The Config struct contains an option to limit the number of incomplete requests per connetion that are allowed before the connection is closed.

The Config struct also adds the option to limit the maximum HTTP header size and the maximum body length for a request.

// done frees the current incomplete request header buffer and reset the HTTP request.
// use this function when the connection is kept open, but the request is handled
@[manualfree]
pub fn (mut ir IncomingRequest) done() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this public? The structure itself is not, and it is used only for the incoming_requests field of RequestParams, which itself is not public.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I think I forgot to use it, I'll check

@Casper64 Casper64 marked this pull request as draft February 20, 2024 19:45
@Casper64
Copy link
Member Author

io.BufferedReader will erase any existing data from its buffer when it refills. Another solution is needed to store the already read data from an incomplete request. Or a custom "StringReader" which keeps the read data in the buffer

@JalonSolov
Copy link
Contributor

It shouldn't be a problem to cache the header until it's completely read.

@Casper64
Copy link
Member Author

It shouldn't be a problem to cache the header until it's completely read.

No, but the problem is that I can't access the data to cache it. And can't read the data first, because the net library only takes a buffered reader has argument when parsing only the request headers.

So I'll probably need to add another function as well

@JalonSolov
Copy link
Contributor

Now that x.vweb has become veb (and x.vweb is deprecated), perhaps this should be adapted to veb 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

Successfully merging this pull request may close these issues.

3 participants