12 February 2014

Contents:

HTTP Server in C, explained

HTTP Authentication in C/C++

HTTP Server in C, source example

Handle POST Multipart and X-Form in C

HTTP Server in C++ from C source

Simple Authentication in Node.js

Simple HTTP Server in Java

Server simple Authentication in Java

Java server Authentication based on Cookies

Handling POST requests in Node JS

POST requests in Java application

Classes and objects in C

* * *

HTTP Server in C, explained

What would itch you to write a server in C? Well, for that you might have four legit reasons: overheads, speed and control, your love for plain C, and (my favourite) ➝ the artistic combination of the previous three :) Link here, and the C source code is here.

Simple Authentication in Node.js

When you write a server, ordinarily you have to protect it (or its specific routes) from unauthorised access. It could be done through the HTTP cookies, which are persistent and live only within the communication between the client ('s browser) and the server. Link here.

Handle POST Multipart and X-Form in C Server

Often, uh, very often, writing a POST reader/handler is a sort of embarrassing predicament. Some browsers send the POST content along with the request (in the request's body); some send them exceptionally as a separate chunks of bytes; some combine the two strategies depending on the POST message size. More here.

HTTP Server in C++

First off, you can compile the C code with the C++ compiler without a hitch. You should only pay attention to the (char*) and (const char*) reciprocal referencing, which is not a big deal at all. Put bluntly, you may take the C source (compiled with gcc ver. 7.5 [Ubuntu]) and compiled with g++ ver. 7.5 [Ubuntu]) without issues, although, as concerns the C code, gcc seems to do a slightly better job. Here is the C++ source.

HTTP Authentication in C/C++

When the servers requires the client's credential (usually, username and password, but it could be any other information as well), the server respond with HTTP/1.1 401 Unauthorized. It also includes the expected scheme (which in this case is WWW-Authenticate: Basic) and could also include the realm (e.g. realm="Protected. Enter your password"). Then the server waits for the client's reply. Continue here.

Simple HTTP Server in Java

You may meticulously take care of  correctly setting and configuring sockets' options, binding, accepting and listening to the port, as you have to in C/C++, or you may prefer to benefit of what the Java developers have already done (com.sun.net.httpserver), and focus on your application's logics. With Java you are always on the safe side. More here.

Server simple Authentication in Java

You may adopt one of two strategies: (1) use the provided Basic Authenticator, or (2) implement the authentication by cookies, as explained in Node.js authentication. More here.

Classes and objects in C

If, for reasons other than sheer amusement, you need C with classes/objects, you better use C++. This is what C++ is primarily for. However, you can also simulate classes/objects in plain C. More here.