Skip to content

fasthttp: improve minimal server example#26072

Merged
spytheman merged 1 commit into
vlang:masterfrom
kimshrier:better-fasthttp-example
Dec 26, 2025
Merged

fasthttp: improve minimal server example#26072
spytheman merged 1 commit into
vlang:masterfrom
kimshrier:better-fasthttp-example

Conversation

@kimshrier

Copy link
Copy Markdown
Contributor

While experimenting with fasthttp on darwin and FreeBSD, the minimal server example, which does function, does not comply with the HTTP protocol exactly. When using curl to hit the server, it complains about a response using HTTP 0.9. Adding a status header to the response gets past that hurdle. However, it then complains about other missing headers and no reply content.

The changes I am proposing make the response compatible with HTTP/1.1 and has enough headers and content to keep curl happy. This might make it more obvious to people using this module that they are responsible for crafting legitimate responses which includes the headers. I tried to keep the code minimal while satisfying the protocol constraints.

I do have another question.

I was able to copy fasthttp_darwin.v to fasthttp_freebsd.v and everything works with no changes. I suspect that the same would work for OpenBSD, NetBSD, and DragonflyBSD. However, I think having 5 identical copies of the kqueue implementation under os specific file names would not be ideal.

Unfortunately, I have to work with many different languages in my day job and I don't have the proper mindset to really write v code in proper idiomatic v. I only get to write v code in my spare time which is quite scarce at the moment.

My first idea is to create a fasthttp_default.v file with the kqueue implementation enclosed in:

$if darwin || freebsd || openbsd || netbsd || dragonflybsd {
...
}

and remove the fasthttp_darwin.v file. Somehow, that doesn't feel right.

I am open to any suggestions.

@JalonSolov

Copy link
Copy Markdown
Collaborator

You can make one named fasthttp_bsd.v, and that should apply to all the BSD flavors. If it doesn't, it should, just as there is a _nix.v to apply to all unix flavors, etc.

@kimshrier

Copy link
Copy Markdown
Contributor Author

Thanks for the pointer. I was unaware of that capability. I knew about _nix.v but I didn't know what _bsd.v would get me.

@spytheman spytheman requested a review from enghitalo December 22, 2025 04:51
@enghitalo

enghitalo commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

About the second: If the kqueue can handle it, I don't see why not.

@enghitalo

enghitalo commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

Regarding the documentation and examples, I think it's a great idea to change that to be closer to the standards. I would only use string builder to avoid low-performance concatenation and other things.

@vlang vlang deleted a comment from Jengro777 Dec 24, 2025

@enghitalo enghitalo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use string builder instead

Comment thread vlib/fasthttp/README.md
headers := [
status_line,
'Content-Type: text/plain',
'Content-Length: ${body.len}',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use string builder

@spytheman

Copy link
Copy Markdown
Contributor

I am merging it as it is, since correctness comes first before performance. It is a definite improvement on that front. The examples should be as clear as possible too.

@spytheman

Copy link
Copy Markdown
Contributor

(it is also Christmas, and a major release is coming soon)

@spytheman spytheman merged commit 15368a3 into vlang:master Dec 26, 2025
5 checks passed
@kimshrier kimshrier deleted the better-fasthttp-example branch April 28, 2026 02:04
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.

4 participants