Live data from Hacker News

Althttpd: Simple webserver in a single C file

sqlite.org

31–40 of 345 posts

Re: Althttpd: Simple webserver in a single C file

#33
post #24

/* ** Test procedure for ParseRfc822Date */ void TestParseRfc822Date(void){ time_t t1, t2; for(t1=0; t1 There's only two billion integers, guess we can test them all. Well, substantially fewer than two billion with that skip. I wonder if that completes in a few seconds.

This loop doesn’t test them all - it tests every 1/127th integer, so it only runs about 16 million times.

Re: Althttpd: Simple webserver in a single C file

#34

One file of 2600 lines, guess if you give up common sense and follow this approach you can even create a kernel in one file

AFAIK FreeRTOS is a kernel and distributed as a single file.

Maybe that was true at some point, but it’s no longer true. FreeRTOS consists of a core of 6-7 .c files (some of which may be optional) plus 2-3 board support source files. See their GitHub mirror: https://github.com/FreeRTOS/FreeRTOS-Kernel

Re: Althttpd: Simple webserver in a single C file

#35
> A separate process is started for each incoming connection, and that process is wholly focused on serving that one connection.

It makes you wonder just how "heavy" operating system processes actually are. We may not need to worry about the complexity of trying to multiple run async requests in a single process/thread in all cases.

Re: Althttpd: Simple webserver in a single C file

#36
post #2

Here is the actual single C-code file: https://sqlite.org/althttpd/file?name=althttpd.c Something I absolutely love about text based protocols such as HTTP/1 is how easy you can implement it in any virtually programming language. Sure, the implementation is not top-of-the-notch, but it just damned works, it is portable, it is understandable by humans. That's something what's got lost with HTTP/2 and HTTP/3, respectiv…

HTTP/1 simplicity comes not from text nature, but from it's clear concept and limited functionality. At core, it's just request-reply + key-value metadata. Whenever it's text, or binary, it does not matter much. But writing HTTP/2 frame types in letters would not make them any easier to understand.

There are also keep-alive, caching (a big topic), chunked transfer encoding, header parsing peculiarities, and authentication in HTTP. The combination of these creates some nice opportunities for implementation bugs. Source: have worked on a client-side implementation.

Now, HTTP/2 isn't even conceptually simple, I agree about that... it seems ugly.

Re: Althttpd: Simple webserver in a single C file

#37
post #10
post #2

Here is the actual single C-code file: https://sqlite.org/althttpd/file?name=althttpd.c Something I absolutely love about text based protocols such as HTTP/1 is how easy you can implement it in any virtually programming language. Sure, the implementation is not top-of-the-notch, but it just damned works, it is portable, it is understandable by humans. That's something what's got lost with HTTP/2 and HTTP/3, respectiv…

HTTP is serious about backward compatibility, so a client that speaks HTTP/1.1 (or HTTP/1.0 + Host header) can still talk to most servers out there. Similarly, if you write a server that only speaks HTTP/1.1 (or HTTP/1.0 + Host header), you can put it behind a reverse proxy or load balancer that handles higher versions, does connection management, and terminates TLS. It will work perfectly fine, only without some of…

> you can put it behind a reverse proxy or load balancer that handles higher versions, does connection management, and terminates TLS

This is even standard practice in many production deployments. Typically you want the proxy or load balancer anyway and there's often little benefit (if any) to using HTTP/2 or HTTP/3 over a very low-latency, high reliability local network.

Re: Althttpd: Simple webserver in a single C file

#38
post #22
post #10

Earlier quoted context omitted.

HTTP is serious about backward compatibility, so a client that speaks HTTP/1.1 (or HTTP/1.0 + Host header) can still talk to most servers out there. Similarly, if you write a server that only speaks HTTP/1.1 (or HTTP/1.0 + Host header), you can put it behind a reverse proxy or load balancer that handles higher versions, does connection management, and terminates TLS. It will work perfectly fine, only without some of…

That seems like a high risk of http desync attacks, if you're only implementing a subset of http/1.1.

How would one attack a static page?

Re: Althttpd: Simple webserver in a single C file

#39

One file of 2600 lines, guess if you give up common sense and follow this approach you can even create a kernel in one file

I am not sure exactly where you were trying to go with this, but 2600 lines is actually pretty short for a C program.

Re: Althttpd: Simple webserver in a single C file

#40
post #2

Here is the actual single C-code file: https://sqlite.org/althttpd/file?name=althttpd.c Something I absolutely love about text based protocols such as HTTP/1 is how easy you can implement it in any virtually programming language. Sure, the implementation is not top-of-the-notch, but it just damned works, it is portable, it is understandable by humans. That's something what's got lost with HTTP/2 and HTTP/3, respectiv…

Once you have to support HTTP/1.1 it's not really a text-based protocol, because support for chunked encoding is mandatory for clients. (Yes the chunk headers are technically text, but it's interspersed with arbitrary binary data. It's not something you can easily read in a text editor.)
Post reply on HN