Class
BirbResponseStream
unstable since: 0.6
Description [src]
final class Birb.ResponseStream : Gio.OutputStream
{
/* No available fields */
}
A subclass of GOutputStream that can be used for mocking.
Note: Currently only text based streams are supported.
This stream lets you automate responses. It is an output stream that can be written to and will scan that for regex patterns in a sequential fashion.
If the current regex pattern is found, the associated response will be provided on the input stream and it will start looking for the next pattern.
Below is a simple example testing an HTTP GET request that uses the trailing “\r\n\r\n” of the request as the pattern to match.
GBytes *bytes = NULL;
GBytes *received = NULL;
GError *error = NULL;
GInputStream *input = NULL;
GOutputStream *response = NULL;
gconstpointer read_data = NULL;
gsize read_data_size = 0;
response = birb_response_stream_new();
birb_response_stream_add_response(BIRB_RESPONSE_STREAM(response),
"\r\n\r\n",
"200 OK\r\nContent-Length: 0\r\n\r\n",
&error);
g_assert_no_error(error);
input = birb_response_stream_get_input_stream(BIRB_RESPONSE_STREAM(response));
bytes = g_bytes_new_static("GET / HTTP/1.1\r\n\r\n", 18);
g_output_stream_write_bytes(response, bytes, NULL, NULL);
g_bytes_unref(bytes);
received = g_input_stream_read_bytes(input, 4096, NULL, NULL);
read_data = g_bytes_get_data(received, &read_data_size);
g_assert_cmpmem(read_data, read_data_size,
"200 OK\r\nContent-Length: 0\r\n\r\n", 29);
g_bytes_unref(received);
g_object_unref(response);
Available since: 0.6
Constructors
birb_response_stream_new_iostream
Creates a new response stream wrapped with g_simple_io_stream_new().
unstable since: 0.6
Instance methods
birb_response_stream_add_response
Adds the given regex pattern and response pair.
unstable since: 0.6
Methods inherited from GOutputStream (31)
Please see GOutputStream for a full list of methods.
Signals
Signals inherited from GObject (1)
GObject::notify
The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.