w3soft.org by unix-world
0.00
HTTP simple server written in Vala
A simple HTTP server developed in Vala language for Linux and *BSD operating systems, based on Glib
programming language: vala 0.48 or later
operating system: linux, bsd
Updated: 2023-08-24
HTTP server, Vala language
// file: http-simple-server.vala
using GLib;
void default_handler(Soup.Server server, Soup.Message msg, string path, GLib.HashTable? query, Soup.ClientContext client) {
string response_text = """
<html>
<body>
<p>Current location: %s</p>
<p><a href="/xml">Test XML</a></p>
</body>
</html>""".printf (path);
msg.set_response("text/html", Soup.MemoryUse.COPY, response_text.data);
}
void xml_handler(Soup.Server server, Soup.Message msg, string path, GLib.HashTable? query, Soup.ClientContext client) {
string response_text = "<node><subnode>test</subnode></node>";
msg.set_response("text/xml", Soup.MemoryUse.COPY, response_text.data);
}
void main () {
var server = new Soup.Server (Soup.SERVER_PORT, 18888);
server.add_handler ("/", default_handler);
server.add_handler ("/xml", xml_handler);
server.run ();
}
Code compilation
valac --pkg libsoup-2.4 http-simple-server.vala