Class

BirbResponseStream

since: 0.6

Description [src]

final class Birb.ResponseStream : Gio.OutputStream
  implements Gio.PollableOutputStream {
  /* 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

Creates a new response stream.

since: 0.6

birb_response_stream_new_iostream

Creates a new response stream wrapped with g_simple_io_stream_new().

since: 0.6

Instance methods

birb_response_stream_add_response

Adds the given regex pattern and response pair.

since: 0.6

birb_response_stream_get_input_stream

Gets the input stream.

since: 0.6

Methods inherited from GOutputStream (31)

Please see GOutputStream for a full list of methods.

Methods inherited from GObject (43)

Please see GObject for a full list of methods.

Methods inherited from GPollableOutputStream (5)
g_pollable_output_stream_can_poll

Checks if stream is actually pollable. Some classes may implement GPollableOutputStream but have only certain instances of that class be pollable. If this method returns FALSE, then the behavior of other GPollableOutputStream methods is undefined.

g_pollable_output_stream_create_source

Creates a GSource that triggers when stream can be written, or cancellable is triggered or an error occurs. The callback on the source is of the GPollableSourceFunc type.

g_pollable_output_stream_is_writable

Checks if stream can be written.

g_pollable_output_stream_write_nonblocking

Attempts to write up to count bytes from buffer to stream, as with g_output_stream_write(). If stream is not currently writable, this will immediately return G_IO_ERROR_WOULD_BLOCK, and you can use g_pollable_output_stream_create_source() to create a GSource that will be triggered when stream is writable.

g_pollable_output_stream_writev_nonblocking

Attempts to write the bytes contained in the n_vectors vectors to stream, as with g_output_stream_writev(). If stream is not currently writable, this will immediately return %G_POLLABLE_RETURN_WOULD_BLOCK, and you can use g_pollable_output_stream_create_source() to create a GSource that will be triggered when stream is writable. error will not be set in that case.

Properties

Birb.ResponseStream:input-stream

The input stream that users should write to.

since: 0.6

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.

Class structure

struct BirbResponseStreamClass {
  GOutputStreamClass parent_class;
  
}

No description available.

Class members
parent_class: GOutputStreamClass

No description available.