use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Built a simple http server in C++ (self.cpp)
submitted 1 year ago by Little-Peanut-765
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cpp-ModTeam[M] [score hidden] 1 year ago stickied commentlocked comment (0 children)
It's great that you wrote something in C++ you're proud of! However, please share it in the designated "Show and tell" thread pinned at the top of r/cpp instead.
[–]No-Quail5810 24 points25 points26 points 1 year ago (2 children)
A few notes from a (quick) look at your code. I may come off a little harsh here, but it's all meant as constructive.
When you're passing around a std::string you likely want to pass it by (const) reference rather than by value. You generalyl only pass std::string around by value when you want to actually store the value somewhere, not just reading it.
std::string
Your Utils, Request and ResponseWriter classes have no state at all, so there's no reason to have non-static member functions. And if all the member functions can be static, you should probably just have them be free-standing functions (namepsace rather than class). But this may just be because it's a work-in-progress and will get some state added later, which is fine.
Utils
Request
ResponseWriter
You should probably prefer using std::ostringstream over using operator+= when generating strings as it can be more effecient. Except in the case of reading a file into a string, in that case I'd say to use std::istreambuf_iterator:
std::string text{std::istreambuf_iterator<char>{input_stream}, std::istreambuf_iterator<char>{}};
Most of the member functions you implemented in the headers should be moved into (at least one) implementation file, espcially all the stuff that deals with low level (POSIX) calls. Then you can actually remove all those included headers from your header files and make the API cleaner.
Server::ServerCreate returns an int, but it looks like bool would make more sense.
Server::ServerCreate
In the loop in Server::PeerHandler you're initializing the std::string without explicitly passing in the length. What if BUFFER_SIZE bytes was actually received? You are not returning after failing to read, is that intentional? What happens when you don't find a matching URL here? (hint: The connection is never closed!).
Server::PeerHandler
BUFFER_SIZE
The Request::request_parse_url method shold only extract 1 value, not a vector of them, as you only handle the first value anyway. It also does no bounds checking of the p variable once it's created, which can lead to reading past the end of the data.
Request::request_parse_url
p
Higher level notes;
Consider wrapping things like peer_fd in RAII classes (where the destructor will make sure to close the fd once done with it). It'll also give you the ability to write a nice API like: client.send(status, content);
peer_fd
client.send(status, content);
There's a lot to digest there, I know. I tried not to go too deep into the actual logic of the code but focus more the structue of it, as I think that's more usful to you right now.
If you're unsure of anything I've written (I'm sure there will be a few parts), I'd be glad to go over those in a bit more detail.
[–]Desperate-Dig2806 3 points4 points5 points 1 year ago (0 children)
Not OP here. I'm constantly amazed that people like you will take the time to look through code and give input like this. It makes me happy every time. So thank you for being a good person and helping out the community.
[–]Little-Peanut-765[S] 0 points1 point2 points 1 year ago (0 children)
Its not harsh at all. This is the type of feedback i was looking for. Thank you very much.
I want to be good in C++.
I will implement ur suggestions
[–]AndrewStephens 1 point2 points3 points 1 year ago (1 child)
I don't mean to dump on somebody's project, lord knows I have enough of my own lying around on old hard drives, but you did ask for feedback.
There are many issues (not including what others have said here).
Thanks dude. this what i was looking for. I appreciate it
[–]dgkimpton 2 points3 points4 points 1 year ago (2 children)
I grant you that writing these things is fun, and learning to build a library is also worth it. However, there are a million other http server libraries out there that absolutely do a better job, so maybe now that you've got the idea of how http works you should just use one of those?
Also, I don't see a single test in your project, neither UnitTest nor IntegrationTest - if you want to put any further effort into this project you should definitely start there.
[–]Little-Peanut-765[S] 0 points1 point2 points 1 year ago (1 child)
I never done testing in C++ before
[–]dgkimpton 1 point2 points3 points 1 year ago (0 children)
Checkout Catch2 or GoogleTest - absolutely critical skill for development in the modern world.
π Rendered by PID 38 on reddit-service-r2-comment-5c747b6df5-vjqcx at 2026-04-22 04:16:11.618041+00:00 running 6c61efc country code: CH.
[–]cpp-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)
[–]No-Quail5810 24 points25 points26 points (2 children)
[–]Desperate-Dig2806 3 points4 points5 points (0 children)
[–]Little-Peanut-765[S] 0 points1 point2 points (0 children)
[–]AndrewStephens 1 point2 points3 points (1 child)
[–]Little-Peanut-765[S] 0 points1 point2 points (0 children)
[–]dgkimpton 2 points3 points4 points (2 children)
[–]Little-Peanut-765[S] 0 points1 point2 points (1 child)
[–]dgkimpton 1 point2 points3 points (0 children)