TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Httpserver.h: Single header library for writing non-blocking HTTP servers in C

332 点作者 jeremycw超过 5 年前

20 条评论

_bxg1超过 5 年前
Question: I thought any given C code could go in either headers or c files (or rather, split between headers and c files), and that the difference was only a build concern. So why wouldn't a given library be available in both forms, unless one of them just makes no sense at all? Put differently: why isn't this just "Minimal library for writing non-blocking HTTP servers in C" which people understand to mean "this might make sense to put in a header"?
评论 #21777773 未加载
评论 #21777912 未加载
评论 #21777943 未加载
评论 #21777752 未加载
评论 #21782813 未加载
评论 #21786384 未加载
评论 #21779437 未加载
评论 #21779202 未加载
评论 #21778750 未加载
评论 #21778608 未加载
评论 #21778171 未加载
maxk42超过 5 年前
h2o [1] is a web server and C library that not only supports http 1 &amp; 2, but also usually tops the TechEmpower benchmarks [2].<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;h2o&#x2F;h2o" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;h2o&#x2F;h2o</a><p>[2] <a href="https:&#x2F;&#x2F;www.techempower.com&#x2F;benchmarks&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.techempower.com&#x2F;benchmarks&#x2F;</a>
评论 #21777877 未加载
ebeip90超过 5 年前
1100+ lines and barely a comment after the initial block.<p>It also defines some buffer size names that are likely also declared in other libraries, like `BUF_SIZE`, and will need to be `#undef`ed.
评论 #21778008 未加载
评论 #21778637 未加载
cryptonector超过 5 年前
^Fchunked<p>No chunked support. Well, if ever I use this (and... I do have a pressing use for something like this), that will be a PR I&#x27;ll send in, probably using async.h[0] to allow handlers to be asynchronous.<p>Also, it&#x27;s no fair to compare this server&#x27;s performance to nginx if this server has no TLS support: you&#x27;ll have to setup a reverse proxy, and then what will that be?<p>The lack of URI parsing is not a big deal for me, but it&#x27;d be nice.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;naasking&#x2F;async.h" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;naasking&#x2F;async.h</a>
评论 #21779305 未加载
giancarlostoro超过 5 年前
I like this. I&#x27;ve become a huge fan of using Go for web stuff since it&#x27;s baked in to the language and I can get solutions really quickly. I&#x27;m more likely to go through this code though because it looks interesting.
评论 #21778016 未加载
castratikron超过 5 年前
I had good luck with microhttpd. I wrote a little json web service as part of an existing C application for an embedded platform. Was very DIY but this is C after all.
jsd1982超过 5 年前
It&#x27;s non-blocking for its own http request&#x2F;response handling but will it allow you integrate with its event loop and register your own events to react to? Can your request handler make its own network connections as a client to other servers in a non-blocking way?
评论 #21778353 未加载
ludamad超过 5 年前
Any sort of static analysis to argue this doesn&#x27;t have undefined behaviour bugs? It&#x27;s cool, I just don&#x27;t know a lot of cases where I would want&#x2F;need an HTTP server and wouldn&#x27;t want something more weathered
评论 #21778894 未加载
anon9001超过 5 年前
Neat, but why? Is it just the novelty that it can be done?<p>I thought it was poor form to have a lot of code in headers. This seems like it&#x27;d be better served as a small C http library.
评论 #21777575 未加载
评论 #21777711 未加载
评论 #21777710 未加载
评论 #21777679 未加载
评论 #21777673 未加载
评论 #21777745 未加载
bullen超过 5 年前
At first glance this doesn&#x27;t seem to handle large amounts of body data?<p>Also I find no handling of slow connections.<p>This is definitely a toy.
jacob019超过 5 年前
Might go well with embeded hardware
gigel82超过 5 年前
You forgot to add &quot;for Linux&#x2F;BSD&quot;.
评论 #21779239 未加载
thr0w__4w4y超过 5 年前
Great job. For me, checks all the boxes:<p>. C (could have been C++... embedded MCU platform)<p>. compiles cleanly out of the box<p>. demo is simple, works out of the box, simple to verify<p>I contrast this with my experience a few days ago with the &quot;Space Invaders in C&quot; post (too lazy to reference it or find the exact title). I do development on my Mac all the time (command-line, C++, clang&#x2F;gcc). Tried building Space Invaders. One problem after the next. Gave up after about 20-25 minutes.<p>Cliché as it is, the importance of the &quot;out of box&quot; experience is so important. Especially for a commercial product, which I realize this isn&#x27;t.
mark_l_watson超过 5 年前
I now use mostly Lisp languages (or Haskell), but back in the day I wrote C++ books, acted as a C++ trainer and tech lead. My last professional use of C++ was in the 1990s doing entertainment game, VR, and game AI for SAIC, Nintendo, and Disney.<p>I then went back to using plain C for awhile, and after the complexity of C++, C was so much fun to use.<p>Anyway, I enjoyed reading through this C header file, and it took me back. But, I am sticking with Lisp because for me it is such a higher productivity language.
z3t4超过 5 年前
I like that it looks like Node.js http module. But I&#x27;m too scared to use C with pointers and malloc, so I&#x27;ll stick to Node.js. I&#x27;m however jealous of people that are competent in C, assembly or any other low level systems language.
评论 #21778556 未加载
评论 #21778269 未加载
tom_超过 5 年前
What about Windows?<p>You can get a 3-for-1 with this kind of library by having a libuv implementation.
评论 #21778789 未加载
noobermin超过 5 年前
brundolf is asking a similar yet different question, so I&#x27;ll ask mine: I&#x27;ve heard about modules coming to C++. What are the concerns with headers exactly? I&#x27;m aware of the issues with duplication in object files and ballooning build times, but are there other issues? Is it then something that primarily affect very large code bases?
评论 #21778780 未加载
评论 #21777796 未加载
tus88超过 5 年前
Securely?
amq超过 5 年前
Surprised to see no CI.
sedatk超过 5 年前
This kind of thing is the reason that header files should die and a new module system should emerge in the world of C&#x2F;C++. &quot;Header-only&quot; should stop being a novelty. Distributing or consuming libraries should be much more straightforward and easy as with modern languages. I&#x27;m not sure C++20 modules are the solution, but this certainly isn&#x27;t.
评论 #21778060 未加载
评论 #21777989 未加载
评论 #21779052 未加载