Skip to content

v0.2.0-alpha

Pre-release
Pre-release
Compare
Choose a tag to compare
@arteymix arteymix released this 26 Jun 20:36
· 813 commits to master since this release

This release brings a new asynchronous API for processing Request and Response objects based on a RAII pattern and taking advantage of automated reference counting from the Vala compiler.

This series mark the stabilization of APIs and any subsequent releases will be subjected to rigorous semantic versionning.

You can verify the release against the following SHA-1 checksum: 570f6711921bb31f0b2284f5baf5a76b31608e96

Changeset

  • resources required to process a client request follows the lifecycle of a Connection object that inherits from IOStream
  • VSGI.Application have been replaced by a delegate to simplify how an application can be defined
  • libsoup-2.4 implementation uses the connection with steal_connection to provide authentic stream operations and a better throughput
  • waf 1.8.11 brings fixes for the --thread option which will be useful for future VSGI implementations
  • write_head and write_head_async to write the head of the response
  • considerably improves the documentation
  • head_written property in Response
  • better fault tolerance with more error handling
  • VSGI implementations are easier to stub and test

General

The changes ensure that the connection is kept alive as long as it is being referenced and since the Request holds such a reference and that the Response holds a Request reference, holding any of these two instances is sufficient to perform stream operations.

Typically, the resources would be freed when returning the control to the server, but this approach does not work with asynchronous operations as they will execute later on.

The first attempt was to introduce a end signal to explicitly notify the server that the resources could be freed, but it was unreliable and really not taking advantage of the automated memory management provided by Vala.

new Server ((req, res, end) => {
    end (); // end must be invoked
});

Now, we simply wrap all the resources within an object following the RAII programming pattern. Resources are freed when both Request and Response are disposed.

new Server ((req, res) => {
    // now,req and res will be freed and thus the connection
});

Writting the head of the response

Two new functions allows one to write the head of the response either synchronously or asynchronously. This is done automatically if the body property is accessed for the first time in Response.

Now, an application must invoke write_head or write_head_async at least once during its processing, unless what an empty message will be produced.

app.get ("", (req, res) => {
    res.status = 404;
    res.write_head ();
});

More testable VSGI implementations

VSGI implementations have been made more testable by exposing easily mockable constructor arguments like IOStream and HashTable.

Consequently, the code coverage has greatly improved to reach 65.59% and it will continuously improve over time.