Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> That's folk wisdom, but is it actually true? "Hundreds of lines just to grab a query parameter from a URL."

No, because...

> In practice you would probably parse all parameters at once and maybe use a library.

In the 90s I wrote CGI applications in C; a single function, on startup, parsed the request params into an array (today I'd use a hashmap, but I was very young then and didn't know any better) of `struct {char name; char value}`. It was paired with a `get(const char name)` function that returned `const char ` value for the specified name.

TBH, a lot of the "common folk wisdom" about C has more "common" in it than "wisdom". I wonder what a C library would look like today, for handling HTTP requests.

Maybe hashmap for request params, union for the `body` depending on content-type parsing, tree library for JSON parsing/generation, arena allocator for each request, a thread-pool, etc.



Just FYI the 's got swallowed by the HN formatting and made the stuff inbetween italic.

  struct { char *name; char *value}
can bypass the formatting by prepending 2 spaces


> Just FYI the 's got swallowed

Ironically enough your *'s as well.


> I wonder what a C library would look like today, for handling HTTP requests.

Isn't that CURL?


>> I wonder what a C library would look like today, for handling HTTP requests.

> Isn't that CURL?

Curl sends requests, it doesn't handle incoming requests.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: