HTTP Server

<refentry> <refmeta> <refentrytitle>SoupServer</refentrytitle> <manvolnum>3</manvolnum> <refmiscinfo>LIBSOUP-3.0 Library</refmiscinfo> </refmeta>

<refentrytitle>SoupServer</refentrytitle>

<refname>SoupServer</refname> <refpurpose>HTTP server</refpurpose>

<refsect1> <title>Functions</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><returnvalue>SoupServer</returnvalue> * </entry><entry>soup_server_new <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_set_tls_certificate <phrase>()</phrase></entry></row> <row><entry><returnvalue>GTlsCertificate</returnvalue> * </entry><entry>soup_server_get_tls_certificate <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_set_tls_database <phrase>()</phrase></entry></row> <row><entry><returnvalue>GTlsDatabase</returnvalue> * </entry><entry>soup_server_get_tls_database <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_set_tls_auth_mode <phrase>()</phrase></entry></row> <row><entry><returnvalue>GTlsAuthenticationMode</returnvalue> </entry><entry>soup_server_get_tls_auth_mode <phrase>()</phrase></entry></row> <row><entry><returnvalue>gboolean</returnvalue> </entry><entry>soup_server_listen <phrase>()</phrase></entry></row> <row><entry><returnvalue>gboolean</returnvalue> </entry><entry>soup_server_listen_all <phrase>()</phrase></entry></row> <row><entry><returnvalue>gboolean</returnvalue> </entry><entry>soup_server_listen_local <phrase>()</phrase></entry></row> <row><entry><returnvalue>gboolean</returnvalue> </entry><entry>soup_server_listen_socket <phrase>()</phrase></entry></row> <row><entry><returnvalue>GSList</returnvalue> * </entry><entry>soup_server_get_listeners <phrase>()</phrase></entry></row> <row><entry><returnvalue>GSList</returnvalue> * </entry><entry>soup_server_get_uris <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_disconnect <phrase>()</phrase></entry></row> <row><entry><returnvalue>gboolean</returnvalue> </entry><entry>soup_server_is_https <phrase>()</phrase></entry></row> <row><entry><returnvalue>gboolean</returnvalue> </entry><entry>soup_server_accept_iostream <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry><phrase>(</phrase>*SoupServerCallback<phrase>)</phrase> <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_add_handler <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_add_early_handler <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_remove_handler <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry><phrase>(</phrase>*SoupServerWebsocketCallback<phrase>)</phrase> <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_add_websocket_handler <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_add_websocket_extension <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_remove_websocket_extension <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_add_auth_domain <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_remove_auth_domain <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_pause_message <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_unpause_message <phrase>()</phrase></entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Properties</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><type>gboolean</type></entry><entry>raw-paths</entry><entry>Read / Write / Construct Only</entry></row> <row><entry><type>char</type> *</entry><entry>server-header</entry><entry>Read / Write / Construct</entry></row> <row><entry><type>GTlsAuthenticationMode</type></entry><entry>tls-auth-mode</entry><entry>Read / Write / Construct</entry></row> <row><entry><type>GTlsCertificate</type> *</entry><entry>tls-certificate</entry><entry>Read / Write / Construct</entry></row> <row><entry><type>GTlsDatabase</type> *</entry><entry>tls-database</entry><entry>Read / Write / Construct</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Signals</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><returnvalue>void</returnvalue></entry><entry>request-aborted</entry><entry>Run First</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>request-finished</entry><entry>Run First</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>request-read</entry><entry>Run First</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>request-started</entry><entry>Run First</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Types and Values</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry></entry><entry>SoupServer</entry></row> <row><entry>enum</entry><entry>SoupServerListenOptions</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Object Hierarchy</title> <screen> GObject <phrase>╰──</phrase> SoupServer </screen> </refsect1> <refsect1><title>Includes</title><synopsis>#include <libsoup/soup.h> </synopsis></refsect1> <refsect1> <title>Description</title> <para><type>SoupServer</type> implements a simple HTTP server.</para> <para>(The following documentation describes the current <type>SoupServer</type> API, available in <application>libsoup</application> 2.48 and later. See the section "The Old SoupServer Listening API" in the server how-to documentation for details on the older <type>SoupServer</type> API.)</para> <para>To begin, create a server using <function>soup_server_new()</function>. Add at least one handler by calling <function>soup_server_add_handler()</function> or <function>soup_server_add_early_handler()</function>; the handler will be called to process any requests underneath the path you pass. (If you want all requests to go to the same handler, just pass "/" (or <literal>NULL</literal>) for the path.)</para> <para>When a new connection is accepted (or a new request is started on an existing persistent connection), the <type>SoupServer</type> will emit <type>“request-started”</type> and then begin processing the request as described below, but note that once the message is assigned a status-code, then callbacks after that point will be skipped. Note also that it is not defined when the callbacks happen relative to various <type>SoupServerMessage</type> signals.</para> <para>Once the headers have been read, <type>SoupServer</type> will check if there is a <type>SoupAuthDomain</type> (qv) covering the Request-URI; if so, and if the message does not contain suitable authorization, then the <type>SoupAuthDomain</type> will set a status of <literal>SOUP_STATUS_UNAUTHORIZED</literal> on the message.</para> <para>After checking for authorization, <type>SoupServer</type> will look for "early" handlers (added with <function>soup_server_add_early_handler()</function>) matching the Request-URI. If one is found, it will be run; in particular, this can be used to connect to signals to do a streaming read of the request body.</para> <para>(At this point, if the request headers contain "<literal>Expect: 100-continue</literal>", and a status code has been set, then <type>SoupServer</type> will skip the remaining steps and return the response. If the request headers contain "<literal>Expect: 100-continue</literal>" and no status code has been set, <type>SoupServer</type> will return a <literal>SOUP_STATUS_CONTINUE</literal> status before continuing.)</para> <para>The server will then read in the response body (if present). At this point, if there are no handlers at all defined for the Request-URI, then the server will return <literal>SOUP_STATUS_NOT_FOUND</literal> to the client.</para> <para>Otherwise (assuming no previous step assigned a status to the message) any "normal" handlers (added with <function>soup_server_add_handler()</function>) for the message's Request-URI will be run.</para> <para>Then, if the path has a WebSocket handler registered (and has not yet been assigned a status), <type>SoupServer</type> will attempt to validate the WebSocket handshake, filling in the response and setting a status of <literal>SOUP_STATUS_SWITCHING_PROTOCOLS</literal> or <literal>SOUP_STATUS_BAD_REQUEST</literal> accordingly.</para> <para>If the message still has no status code at this point (and has not been paused with <function>soup_server_pause_message()</function>), then it will be given a status of <literal>SOUP_STATUS_INTERNAL_SERVER_ERROR</literal> (because at least one handler ran, but returned without assigning a status).</para> <para>Finally, the server will emit <type>“request-finished”</type> (or <type>“request-aborted”</type> if an I/O error occurred before handling was completed).</para> <para>If you want to handle the special "*" URI (eg, "OPTIONS *"), you must explicitly register a handler for "*"; the default handler will not be used for that case.</para> <para>If you want to process https connections in addition to (or instead of) http connections, you can set the <type>“tls-certificate”</type> property.</para> <para>Once the server is set up, make one or more calls to <function>soup_server_listen()</function>, <function>soup_server_listen_local()</function>, or <function>soup_server_listen_all()</function> to tell it where to listen for connections. (All ports on a <type>SoupServer</type> use the same handlers; if you need to handle some ports differently, such as returning different data for http and https, you'll need to create multiple <type>SoupServers</type>, or else check the passed-in URI in the handler function.).</para> <para><type>SoupServer</type> will begin processing connections as soon as you return to (or start) the main loop for the current thread-default <type>GMainContext</type>.</para> </refsect1> <refsect1> <title>Functions</title> <refsect2> <title>soup_server_new ()</title> <programlisting><returnvalue>SoupServer</returnvalue> * soup_server_new (<parameter>const <type>char</type> *optname1</parameter>, <parameter>...</parameter>);</programlisting> <para>Creates a new <type>SoupServer</type>. This is exactly equivalent to calling <function>g_object_new()</function> and specifying <literal>SOUP_TYPE_SERVER</literal> as the type.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>optname1</para></entry> <entry><para>name of first property to set</para></entry> <entry></entry></row> <row><entry><para>...</para></entry> <entry><para>value of <parameter>optname1</parameter> , followed by additional property/value pairs</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a new <type>SoupServer</type>. If you are using certain legacy properties, this may also return <literal>NULL</literal> if an error occurs. </para> <para><emphasis>[nullable]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_set_tls_certificate ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_set_tls_certificate (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>GTlsCertificate</type> *certificate</parameter>);</programlisting> <para>Sets <parameter>server</parameter> up to do https, using the given SSL/TLS <parameter>certificate</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>certificate</para></entry> <entry><para>a <type>GTlsCertificate</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_get_tls_certificate ()</title> <programlisting><returnvalue>GTlsCertificate</returnvalue> * soup_server_get_tls_certificate (<parameter><type>SoupServer</type> *server</parameter>);</programlisting> <para>Gets the <parameter>server</parameter> SSL/TLS certificate</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a <type>GTlsCertificate</type> or <literal>NULL</literal>. </para> <para><emphasis>[transfer none][nullable]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_set_tls_database ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_set_tls_database (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>GTlsDatabase</type> *tls_database</parameter>);</programlisting> <para>Sets <parameter>server</parameter> 's <type>GTlsDatabase</type> to use for validating SSL/TLS client certificates</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>tls_database</para></entry> <entry><para>a <type>GTlsDatabase</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_get_tls_database ()</title> <programlisting><returnvalue>GTlsDatabase</returnvalue> * soup_server_get_tls_database (<parameter><type>SoupServer</type> *server</parameter>);</programlisting> <para>Gets the <parameter>server</parameter> SSL/TLS database</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a <type>GTlsDatabase</type> or <literal>NULL</literal>. </para> <para><emphasis>[transfer none][nullable]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_set_tls_auth_mode ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_set_tls_auth_mode (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>GTlsAuthenticationMode</type> mode</parameter>);</programlisting> <para>Sets <parameter>server</parameter> 's <type>GTlsAuthenticationMode</type> to use for SSL/TLS client authentication</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>mode</para></entry> <entry><para>a <type>GTlsAuthenticationMode</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_get_tls_auth_mode ()</title> <programlisting><returnvalue>GTlsAuthenticationMode</returnvalue> soup_server_get_tls_auth_mode (<parameter><type>SoupServer</type> *server</parameter>);</programlisting> <para>Gets the <parameter>server</parameter> SSL/TLS client authentication mode</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> a <type>GTlsAuthenticationMode</type></para> </refsect3></refsect2>
<refsect2> <title>soup_server_listen ()</title> <programlisting><returnvalue>gboolean</returnvalue> soup_server_listen (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>GSocketAddress</type> *address</parameter>, <parameter><type>SoupServerListenOptions</type> options</parameter>, <parameter><type>GError</type> **error</parameter>);</programlisting> <para>This attempts to set up <parameter>server</parameter> to listen for connections on <parameter>address</parameter> .</para> <para>If <parameter>options</parameter> includes <literal>SOUP_SERVER_LISTEN_HTTPS</literal>, and <parameter>server</parameter> has been configured for TLS, then <parameter>server</parameter> will listen for https connections on this port. Otherwise it will listen for plain http.</para> <para>You may call this method (along with the other "listen" methods) any number of times on a server, if you want to listen on multiple ports, or set up both http and https service.</para> <para>After calling this method, <parameter>server</parameter> will begin accepting and processing connections as soon as the appropriate <type>GMainContext</type> is run.</para> <para>Note that <type>SoupServer</type> never makes use of dual IPv4/IPv6 sockets; if <parameter>address</parameter> is an IPv6 address, it will only accept IPv6 connections. You must configure IPv4 listening separately.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>address</para></entry> <entry><para>the address of the interface to listen on</para></entry> <entry></entry></row> <row><entry><para>options</para></entry> <entry><para>listening options for this server</para></entry> <entry></entry></row> <row><entry><para>error</para></entry> <entry><para>return location for a <type>GError</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> <literal>TRUE</literal> on success, <literal>FALSE</literal> if <parameter>address</parameter> could not be bound or any other error occurred (in which case <parameter>error</parameter> will be set).</para> </refsect3></refsect2>
<refsect2> <title>soup_server_listen_all ()</title> <programlisting><returnvalue>gboolean</returnvalue> soup_server_listen_all (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>guint</type> port</parameter>, <parameter><type>SoupServerListenOptions</type> options</parameter>, <parameter><type>GError</type> **error</parameter>);</programlisting> <para>This attempts to set up <parameter>server</parameter> to listen for connections on all interfaces on the system. (That is, it listens on the addresses <literal>0.0.0.0</literal> and/or <literal>::</literal>, depending on whether <parameter>options</parameter> includes <literal>SOUP_SERVER_LISTEN_IPV4_ONLY</literal>, <literal>SOUP_SERVER_LISTEN_IPV6_ONLY</literal>, or neither.) If <parameter>port</parameter> is specified, <parameter>server</parameter> will listen on that port. If it is 0, <parameter>server</parameter> will find an unused port to listen on. (In that case, you can use <function>soup_server_get_uris()</function> to find out what port it ended up choosing.)</para> <para>See <function>soup_server_listen()</function> for more details.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>port</para></entry> <entry><para>the port to listen on, or 0</para></entry> <entry></entry></row> <row><entry><para>options</para></entry> <entry><para>listening options for this server</para></entry> <entry></entry></row> <row><entry><para>error</para></entry> <entry><para>return location for a <type>GError</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> <literal>TRUE</literal> on success, <literal>FALSE</literal> if <parameter>port</parameter> could not be bound or any other error occurred (in which case <parameter>error</parameter> will be set).</para> </refsect3></refsect2>
<refsect2> <title>soup_server_listen_local ()</title> <programlisting><returnvalue>gboolean</returnvalue> soup_server_listen_local (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>guint</type> port</parameter>, <parameter><type>SoupServerListenOptions</type> options</parameter>, <parameter><type>GError</type> **error</parameter>);</programlisting> <para>This attempts to set up <parameter>server</parameter> to listen for connections on "localhost" (that is, <literal>127.0.0.1</literal> and/or <literal>::1</literal>, depending on whether <parameter>options</parameter> includes <literal>SOUP_SERVER_LISTEN_IPV4_ONLY</literal>, <literal>SOUP_SERVER_LISTEN_IPV6_ONLY</literal>, or neither). If <parameter>port</parameter> is specified, <parameter>server</parameter> will listen on that port. If it is 0, <parameter>server</parameter> will find an unused port to listen on. (In that case, you can use <function>soup_server_get_uris()</function> to find out what port it ended up choosing.)</para> <para>See <function>soup_server_listen()</function> for more details.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>port</para></entry> <entry><para>the port to listen on, or 0</para></entry> <entry></entry></row> <row><entry><para>options</para></entry> <entry><para>listening options for this server</para></entry> <entry></entry></row> <row><entry><para>error</para></entry> <entry><para>return location for a <type>GError</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> <literal>TRUE</literal> on success, <literal>FALSE</literal> if <parameter>port</parameter> could not be bound or any other error occurred (in which case <parameter>error</parameter> will be set).</para> </refsect3></refsect2>
<refsect2> <title>soup_server_listen_socket ()</title> <programlisting><returnvalue>gboolean</returnvalue> soup_server_listen_socket (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>GSocket</type> *socket</parameter>, <parameter><type>SoupServerListenOptions</type> options</parameter>, <parameter><type>GError</type> **error</parameter>);</programlisting> <para>This attempts to set up <parameter>server</parameter> to listen for connections on <parameter>socket</parameter> .</para> <para>See <function>soup_server_listen()</function> for more details.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>socket</para></entry> <entry><para>a listening <type>GSocket</type></para></entry> <entry></entry></row> <row><entry><para>options</para></entry> <entry><para>listening options for this server</para></entry> <entry></entry></row> <row><entry><para>error</para></entry> <entry><para>return location for a <type>GError</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> <literal>TRUE</literal> on success, <literal>FALSE</literal> if an error occurred (in which case <parameter>error</parameter> will be set).</para> </refsect3></refsect2>
<refsect2> <title>soup_server_get_listeners ()</title> <programlisting><returnvalue>GSList</returnvalue> * soup_server_get_listeners (<parameter><type>SoupServer</type> *server</parameter>);</programlisting> <para>Gets <parameter>server</parameter> 's list of listening sockets.</para> <para>You should treat these sockets as read-only; writing to or modifiying any of these sockets may cause <parameter>server</parameter> to malfunction.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a list of listening sockets. </para> <para><emphasis>[transfer container][element-type Gio.Socket]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_get_uris ()</title> <programlisting><returnvalue>GSList</returnvalue> * soup_server_get_uris (<parameter><type>SoupServer</type> *server</parameter>);</programlisting> <para>Gets a list of URIs corresponding to the interfaces <parameter>server</parameter> is listening on. These will contain IP addresses, not hostnames, and will also indicate whether the given listener is http or https.</para> <para>Note that if you used <function>soup_server_listen_all()</function>, the returned URIs will use the addresses <literal>0.0.0.0</literal> and <literal>::</literal>, rather than actually returning separate URIs for each interface on the system.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a list of <type>GUris</type>, which you must free when you are done with it. </para> <para><emphasis>[transfer full][element-type GUri]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_disconnect ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_disconnect (<parameter><type>SoupServer</type> *server</parameter>);</programlisting> <para>Closes and frees <parameter>server</parameter> 's listening sockets.</para> <para>Note that if there are currently requests in progress on <parameter>server</parameter> , that they will continue to be processed if <parameter>server</parameter> 's <type>GMainContext</type> is still running.</para> <para>You can call <function>soup_server_listen()</function>, etc, after calling this function if you want to start listening again.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_is_https ()</title> <programlisting><returnvalue>gboolean</returnvalue> soup_server_is_https (<parameter><type>SoupServer</type> *server</parameter>);</programlisting> <para>Checks whether <parameter>server</parameter> is capable of https.</para> <para>In order for a server to run https, you must call <function>soup_server_set_ssl_cert_file()</function>, or set the <type>“tls-certificate”</type> property, to provide it with a certificate to use.</para> <para>If you are using the deprecated single-listener APIs, then a return value of <literal>TRUE</literal> indicates that the <type>SoupServer</type> serves https exclusively. If you are using <function>soup_server_listen()</function>, etc, then a <literal>TRUE</literal> return value merely indicates that the server is <emphasis>able</emphasis> to do https, regardless of whether it actually currently is or not. Use <function>soup_server_get_uris()</function> to see if it currently has any https listeners.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> <literal>TRUE</literal> if <parameter>server</parameter> is configured to serve https.</para> </refsect3></refsect2>
<refsect2> <title>soup_server_accept_iostream ()</title> <programlisting><returnvalue>gboolean</returnvalue> soup_server_accept_iostream (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>GIOStream</type> *stream</parameter>, <parameter><type>GSocketAddress</type> *local_addr</parameter>, <parameter><type>GSocketAddress</type> *remote_addr</parameter>, <parameter><type>GError</type> **error</parameter>);</programlisting> <para>Add a new client stream to the <parameter>server</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>stream</para></entry> <entry><para>a <type>GIOStream</type></para></entry> <entry></entry></row> <row><entry><para>local_addr</para></entry> <entry><para>the local <type>GSocketAddress</type> associated with the <parameter>stream</parameter> . </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>remote_addr</para></entry> <entry><para>the remote <type>GSocketAddress</type> associated with the <parameter>stream</parameter> . </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>error</para></entry> <entry><para>return location for a <type>GError</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> <literal>TRUE</literal> on success, <literal>FALSE</literal> if the stream could not be accepted or any other error occurred (in which case <parameter>error</parameter> will be set).</para> </refsect3></refsect2>
<refsect2> <title>SoupServerCallback ()</title> <programlisting><returnvalue>void</returnvalue> <phrase>(</phrase>*SoupServerCallback<phrase>)</phrase> (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>SoupServerMessage</type> *msg</parameter>, <parameter>const <type>char</type> *path</parameter>, <parameter><type>GHashTable</type> *query</parameter>, <parameter><type>gpointer</type> user_data</parameter>);</programlisting> <para>A callback used to handle requests to a <type>SoupServer</type>.</para> <para><parameter>path</parameter> and <parameter>query</parameter> contain the likewise-named components of the Request-URI, subject to certain assumptions. By default, <type>SoupServer</type> decodes all percent-encoding in the URI path, such that "/foo%2Fbar" is treated the same as "/foo/bar". If your server is serving resources in some non-POSIX-filesystem namespace, you may want to distinguish those as two distinct paths. In that case, you can set the SoupServer:raw-paths property when creating the <type>SoupServer</type>, and it will leave those characters undecoded.</para> <para><parameter>query</parameter> contains the query component of the Request-URI parsed according to the rules for HTML form handling. Although this is the only commonly-used query string format in HTTP, there is nothing that actually requires that HTTP URIs use that format; if your server needs to use some other format, you can just ignore <parameter>query</parameter> , and call <function>soup_message_get_uri()</function> and parse the URI's query field yourself.</para> <para>See <function>soup_server_add_handler()</function> and <function>soup_server_add_early_handler()</function> for details of what handlers can/should do.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>the <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>msg</para></entry> <entry><para>the message being processed</para></entry> <entry></entry></row> <row><entry><para>path</para></entry> <entry><para>the path component of <parameter>msg</parameter> 's Request-URI</para></entry> <entry></entry></row> <row><entry><para>query</para></entry> <entry><para>the parsed query component of <parameter>msg</parameter> 's Request-URI. </para></entry> <entry><emphasis>[element-type utf8 utf8][nullable]</emphasis></entry></row> <row><entry><para>user_data</para></entry> <entry><para>the data passed to <function>soup_server_add_handler()</function> or <function>soup_server_add_early_handler()</function>.</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_add_handler ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_add_handler (<parameter><type>SoupServer</type> *server</parameter>, <parameter>const <type>char</type> *path</parameter>, <parameter><type>SoupServerCallback</type> callback</parameter>, <parameter><type>gpointer</type> user_data</parameter>, <parameter><type>GDestroyNotify</type> destroy</parameter>);</programlisting> <para>Adds a handler to <parameter>server</parameter> for requests prefixed by <parameter>path</parameter> . If <parameter>path</parameter> is <literal>NULL</literal> or "/", then this will be the default handler for all requests that don't have a more specific handler. (Note though that if you want to handle requests to the special "*" URI, you must explicitly register a handler for "*"; the default handler will not be used for that case.)</para> <para>For requests under <parameter>path</parameter> (that have not already been assigned a status code by a <type>SoupAuthDomain</type>, an early server handler, or a signal handler), <parameter>callback</parameter> will be invoked after receiving the request body; the <type>SoupServerMessage</type>'s method, request-headers, and request-body properties will be set.</para> <para>After determining what to do with the request, the callback must at a minimum call <function>soup_server_message_set_status()</function> on the message to set the response status code. Additionally, it may set response headers and/or fill in the response body.</para> <para>If the callback cannot fully fill in the response before returning (eg, if it needs to wait for information from a database, or another network server), it should call <function>soup_server_pause_message()</function> to tell <parameter>server</parameter> to not send the response right away. When the response is ready, call <function>soup_server_unpause_message()</function> to cause it to be sent.</para> <para>To send the response body a bit at a time using "chunked" encoding, first call <function>soup_message_headers_set_encoding()</function> to set <literal>SOUP_ENCODING_CHUNKED</literal> on the response-headers. Then call <function>soup_message_body_append()</function> (or soup_message_body_append_bytes)) to append each chunk as it becomes ready, and <function>soup_server_unpause_message()</function> to make sure it's running. (The server will automatically pause the message if it is using chunked encoding but no more chunks are available.) When you are done, call <function>soup_message_body_complete()</function> to indicate that no more chunks are coming.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>path</para></entry> <entry><para>the toplevel path for the handler. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>callback</para></entry> <entry><para>callback to invoke for requests under <parameter>path</parameter> . </para></entry> <entry><emphasis>[scope notified][destroy destroy]</emphasis></entry></row> <row><entry><para>user_data</para></entry> <entry><para>data for <parameter>callback</parameter> </para></entry> <entry></entry></row> <row><entry><para>destroy</para></entry> <entry><para>destroy notifier to free <parameter>user_data</parameter> </para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_add_early_handler ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_add_early_handler (<parameter><type>SoupServer</type> *server</parameter>, <parameter>const <type>char</type> *path</parameter>, <parameter><type>SoupServerCallback</type> callback</parameter>, <parameter><type>gpointer</type> user_data</parameter>, <parameter><type>GDestroyNotify</type> destroy</parameter>);</programlisting> <para>Adds an "early" handler to <parameter>server</parameter> for requests prefixed by <parameter>path</parameter> . Note that "normal" and "early" handlers are matched up together, so if you add a normal handler for "/foo" and an early handler for "/foo/bar", then a request to "/foo/bar" (or any path below it) will run only the early handler. (But if you add both handlers at the same path, then both will get run.)</para> <para>For requests under <parameter>path</parameter> (that have not already been assigned a status code by a <type>SoupAuthDomain</type> or a signal handler), <parameter>callback</parameter> will be invoked after receiving the request headers, but before receiving the request body; the message's method and request-headers properties will be set.</para> <para>Early handlers are generally used for processing requests with request bodies in a streaming fashion. If you determine that the request will contain a message body, normally you would call <function>soup_message_body_set_accumulate()</function> on the message's request-body to turn off request-body accumulation, and connect to the message's <type>“got-chunk”</type> signal to process each chunk as it comes in.</para> <para>To complete the message processing after the full message body has been read, you can either also connect to <type>“got-body”</type>, or else you can register a non-early handler for <parameter>path</parameter> as well. As long as you have not set the status-code by the time <type>“got-body”</type> is emitted, the non-early handler will be run as well.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>path</para></entry> <entry><para>the toplevel path for the handler. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>callback</para></entry> <entry><para>callback to invoke for requests under <parameter>path</parameter> . </para></entry> <entry><emphasis>[scope notified][destroy destroy]</emphasis></entry></row> <row><entry><para>user_data</para></entry> <entry><para>data for <parameter>callback</parameter> </para></entry> <entry></entry></row> <row><entry><para>destroy</para></entry> <entry><para>destroy notifier to free <parameter>user_data</parameter> </para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_remove_handler ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_remove_handler (<parameter><type>SoupServer</type> *server</parameter>, <parameter>const <type>char</type> *path</parameter>);</programlisting> <para>Removes all handlers (early and normal) registered at <parameter>path</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>path</para></entry> <entry><para>the toplevel path for the handler</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>SoupServerWebsocketCallback ()</title> <programlisting><returnvalue>void</returnvalue> <phrase>(</phrase>*SoupServerWebsocketCallback<phrase>)</phrase> (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>SoupServerMessage</type> *msg</parameter>, <parameter>const <type>char</type> *path</parameter>, <parameter><type>SoupWebsocketConnection</type> *connection</parameter>, <parameter><type>gpointer</type> user_data</parameter>);</programlisting> <para>A callback used to handle WebSocket requests to a <type>SoupServer</type>. The callback will be invoked after sending the handshake response back to the client (and is only invoked if the handshake was successful).</para> <para><parameter>path</parameter> contains the path of the Request-URI, subject to the same rules as <type>SoupServerCallback</type> (qv).</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>the <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>path</para></entry> <entry><para>the path component of <parameter>msg</parameter> 's Request-URI</para></entry> <entry></entry></row> <row><entry><para>connection</para></entry> <entry><para>the newly created WebSocket connection</para></entry> <entry></entry></row> <row><entry><para>msg</para></entry> <entry><para>the <type>SoupServerMessage</type></para></entry> <entry></entry></row> <row><entry><para>user_data</para></entry> <entry><para>the data passed to <parameter>soup_server_add_handler</parameter> </para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_add_websocket_handler ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_add_websocket_handler (<parameter><type>SoupServer</type> *server</parameter>, <parameter>const <type>char</type> *path</parameter>, <parameter>const <type>char</type> *origin</parameter>, <parameter><type>char</type> **protocols</parameter>, <parameter><type>SoupServerWebsocketCallback</type> callback</parameter>, <parameter><type>gpointer</type> user_data</parameter>, <parameter><type>GDestroyNotify</type> destroy</parameter>);</programlisting> <para>Adds a WebSocket handler to <parameter>server</parameter> for requests prefixed by <parameter>path</parameter> . (If <parameter>path</parameter> is <literal>NULL</literal> or "/", then this will be the default handler for all requests that don't have a more specific handler.)</para> <para>When a path has a WebSocket handler registered, <parameter>server</parameter> will check incoming requests for WebSocket handshakes after all other handlers have run (unless some earlier handler has already set a status code on the message), and update the request's status, response headers, and response body accordingly.</para> <para>If <parameter>origin</parameter> is non-<literal>NULL</literal>, then only requests containing a matching "Origin" header will be accepted. If <parameter>protocols</parameter> is non-<literal>NULL</literal>, then only requests containing a compatible "Sec-WebSocket-Protocols" header will be accepted. More complicated requirements can be handled by adding a normal handler to <parameter>path</parameter> , and having it perform whatever checks are needed and setting a failure status code if the handshake should be rejected.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>path</para></entry> <entry><para>the toplevel path for the handler. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>origin</para></entry> <entry><para>the origin of the connection. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>protocols</para></entry> <entry><para>the protocols supported by this handler. </para></entry> <entry><emphasis>[nullable][array zero-terminated=1]</emphasis></entry></row> <row><entry><para>callback</para></entry> <entry><para>callback to invoke for successful WebSocket requests under <parameter>path</parameter> . </para></entry> <entry><emphasis>[scope notified][destroy destroy]</emphasis></entry></row> <row><entry><para>user_data</para></entry> <entry><para>data for <parameter>callback</parameter> </para></entry> <entry></entry></row> <row><entry><para>destroy</para></entry> <entry><para>destroy notifier to free <parameter>user_data</parameter> </para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_add_websocket_extension ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_add_websocket_extension (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>GType</type> extension_type</parameter>);</programlisting> <para>Add support for a WebSocket extension of the given <parameter>extension_type</parameter> . When a WebSocket client requests an extension of <parameter>extension_type</parameter> , a new <type>SoupWebsocketExtension</type> of type <parameter>extension_type</parameter> will be created to handle the request.</para> <para>Note that <type>SoupWebsocketExtensionDeflate</type> is supported by default, use <function>soup_server_remove_websocket_extension()</function> if you want to disable it.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>extension_type</para></entry> <entry><para>a <type>GType</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_remove_websocket_extension ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_remove_websocket_extension (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>GType</type> extension_type</parameter>);</programlisting> <para>Removes support for WebSocket extension of type <parameter>extension_type</parameter> (or any subclass of <parameter>extension_type</parameter> ) from <parameter>server</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>extension_type</para></entry> <entry><para>a <type>GType</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_add_auth_domain ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_add_auth_domain (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>SoupAuthDomain</type> *auth_domain</parameter>);</programlisting> <para>Adds an authentication domain to <parameter>server</parameter> . Each auth domain will have the chance to require authentication for each request that comes in; normally auth domains will require authentication for requests on certain paths that they have been set up to watch, or that meet other criteria set by the caller. If an auth domain determines that a request requires authentication (and the request doesn't contain authentication), <parameter>server</parameter> will automatically reject the request with an appropriate status (401 Unauthorized or 407 Proxy Authentication Required). If the request used the SoupServer:100-continue Expectation, <parameter>server</parameter> will reject it before the request body is sent.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>auth_domain</para></entry> <entry><para>a <type>SoupAuthDomain</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_remove_auth_domain ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_remove_auth_domain (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>SoupAuthDomain</type> *auth_domain</parameter>);</programlisting> <para>Removes <parameter>auth_domain</parameter> from <parameter>server</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>auth_domain</para></entry> <entry><para>a <type>SoupAuthDomain</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_pause_message ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_pause_message (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Pauses I/O on <parameter>msg</parameter> . This can be used when you need to return from the server handler without having the full response ready yet. Use <function>soup_server_unpause_message()</function> to resume I/O.</para> <para>This must only be called on a <type>SoupServerMessage</type> which was created by the <type>SoupServer</type> and are currently doing I/O, such as those passed into a <type>SoupServerCallback</type> or emitted in a <type>“request-read”</type> signal.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type> associated with <parameter>server</parameter> .</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_unpause_message ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_unpause_message (<parameter><type>SoupServer</type> *server</parameter>, <parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Resumes I/O on <parameter>msg</parameter> . Use this to resume after calling <function>soup_server_pause_message()</function>, or after adding a new chunk to a chunked response.</para> <para>I/O won't actually resume until you return to the main loop.</para> <para>This must only be called on a <type>SoupServerMessage</type> which was created by the <type>SoupServer</type> and are currently doing I/O, such as those passed into a <type>SoupServerCallback</type> or emitted in a <type>“request-read”</type> signal.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>a <type>SoupServer</type></para></entry> <entry></entry></row> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type> associated with <parameter>server</parameter> .</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2> </refsect1>
<refsect1> <title>Types and Values</title> <refsect2> <title>SoupServer</title> <programlisting>typedef struct _SoupServer SoupServer;</programlisting> <para>Class implementing an HTTP server.</para> </refsect2>
<refsect2> <title>enum SoupServerListenOptions</title> <para>Options to pass to <function>soup_server_listen()</function>, etc.</para> <para><literal>SOUP_SERVER_LISTEN_IPV4_ONLY</literal> and <literal>SOUP_SERVER_LISTEN_IPV6_ONLY</literal> only make sense with <function>soup_server_listen_all()</function> and <function>soup_server_listen_local()</function>, not plain <function>soup_server_listen()</function> (which simply listens on whatever kind of socket you give it). And you cannot specify both of them in a single call.</para> <refsect3> <title>Members</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>SOUP_SERVER_LISTEN_HTTPS</para></entry> <entry><para>Listen for https connections rather than plain http.</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_SERVER_LISTEN_IPV4_ONLY</para></entry> <entry><para>Only listen on IPv4 interfaces.</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_SERVER_LISTEN_IPV6_ONLY</para></entry> <entry><para>Only listen on IPv6 interfaces.</para> </entry> <entry></entry> </row> </tbody></tgroup></informaltable> </refsect3></refsect2> </refsect1>
<refsect1> <title>Property Details</title> <refsect2><title>The <literal>“raw-paths”</literal> property</title> <programlisting> “raw-paths” <type>gboolean</type></programlisting> <para>If %TRUE, percent-encoding in the Request-URI path will not be automatically decoded.</para><para>Owner: SoupServer</para> <para>Flags: Read / Write / Construct Only</para> <para>Default value: FALSE</para> </refsect2>
<refsect2><title>The <literal>“server-header”</literal> property</title> <programlisting> “server-header” <type>char</type> *</programlisting> <para>If non-<literal>NULL</literal>, the value to use for the "Server" header on <type>SoupServerMessage</type>s processed by this server.</para> <para>The Server header is the server equivalent of the User-Agent header, and provides information about the server and its components. It contains a list of one or more product tokens, separated by whitespace, with the most significant product token coming first. The tokens must be brief, ASCII, and mostly alphanumeric (although "-", "_", and "." are also allowed), and may optionally include a "/" followed by a version string. You may also put comments, enclosed in parentheses, between or after the tokens.</para> <para>Some HTTP server implementations intentionally do not use version numbers in their Server header, so that installations running older versions of the server don't end up advertising their vulnerability to specific security holes.</para> <para>As with <type>“user_agent”</type>, if you set a <type>“server_header”</type> property that has trailing whitespace, <type>SoupServer</type> will append its own product token (eg, "<literal>libsoup/2.3.2</literal>") to the end of the header for you.</para> <para>Owner: SoupServer</para> <para>Flags: Read / Write / Construct</para> <para>Default value: NULL</para> </refsect2>
<refsect2><title>The <literal>“tls-auth-mode”</literal> property</title> <programlisting> “tls-auth-mode” <type>GTlsAuthenticationMode</type></programlisting> <para>A <type>GTlsAuthenticationMode</type> for SSL/TLS client authentication</para> <para>Owner: SoupServer</para> <para>Flags: Read / Write / Construct</para> <para>Default value: G_TLS_AUTHENTICATION_NONE</para> </refsect2>
<refsect2><title>The <literal>“tls-certificate”</literal> property</title> <programlisting> “tls-certificate” <type>GTlsCertificate</type> *</programlisting> <para>A <type>GTlsCertificate</type> that has a <type>“private-key”</type> set. If this is set, then the server will be able to speak https in addition to (or instead of) plain http.</para> <para>Owner: SoupServer</para> <para>Flags: Read / Write / Construct</para> </refsect2>
<refsect2><title>The <literal>“tls-database”</literal> property</title> <programlisting> “tls-database” <type>GTlsDatabase</type> *</programlisting> <para>A <type>GTlsDatabase</type> to use for validating SSL/TLS client certificates.</para> <para>Owner: SoupServer</para> <para>Flags: Read / Write / Construct</para> </refsect2> </refsect1>
<refsect1> <title>Signal Details</title> <refsect2><title>The <literal>“request-aborted”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServer</type> *server, <type>SoupServerMessage</type> *message, <type>gpointer</type> user_data)</programlisting> <para>Emitted when processing has failed for a message; this could mean either that it could not be read (if <type>“request_read”</type> has not been emitted for it yet), or that the response could not be written back (if <type>“request_read”</type> has been emitted but <type>“request_finished”</type> has not been).</para> <para><parameter>message</parameter> is in an undefined state when this signal is emitted; the signal exists primarily to allow the server to free any state that it may have allocated in <type>“request_started”</type>.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>the server</para></entry> <entry></entry></row> <row><entry><para>message</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run First</para> </refsect2>
<refsect2><title>The <literal>“request-finished”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServer</type> *server, <type>SoupServerMessage</type> *message, <type>gpointer</type> user_data)</programlisting> <para>Emitted when the server has finished writing a response to a request.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>the server</para></entry> <entry></entry></row> <row><entry><para>message</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run First</para> </refsect2>
<refsect2><title>The <literal>“request-read”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServer</type> *server, <type>SoupServerMessage</type> *message, <type>gpointer</type> user_data)</programlisting> <para>Emitted when the server has successfully read a request. <parameter>message</parameter> will have all of its request-side information filled in, and if the message was authenticated, <parameter>client</parameter> will have information about that. This signal is emitted before any (non-early) handlers are called for the message, and if it sets the message's <type>status_code</type>, then normal handler processing will be skipped.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>the server</para></entry> <entry></entry></row> <row><entry><para>message</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run First</para> </refsect2>
<refsect2><title>The <literal>“request-started”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServer</type> *server, <type>SoupServerMessage</type> *message, <type>gpointer</type> user_data)</programlisting> <para>Emitted when the server has started reading a new request. <parameter>message</parameter> will be completely blank; not even the Request-Line will have been read yet. About the only thing you can usefully do with it is connect to its signals.</para> <para>If the request is read successfully, this will eventually be followed by a <type>“request_read”</type> signal. If a response is then sent, the request processing will end with a <type>“request_finished”</type> signal. If a network error occurs, the processing will instead end with <type>“request_aborted”</type>.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>server</para></entry> <entry><para>the server</para></entry> <entry></entry></row> <row><entry><para>message</para></entry> <entry><para>the new message</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run First</para> </refsect2> </refsect1>
<refsect1> <title>See Also</title> <para><type>SoupAuthDomain</type></para> </refsect1> </refentry>
<refentry> <refmeta> <refentrytitle>SoupServerMessage</refentrytitle> <manvolnum>3</manvolnum> <refmiscinfo>LIBSOUP-3.0 Library</refmiscinfo> </refmeta>

<refentrytitle>SoupServerMessage</refentrytitle>

<refname>SoupServerMessage</refname> <refpurpose>An HTTP server request and response.</refpurpose>

<refsect1> <title>Functions</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><returnvalue>SoupMessageHeaders</returnvalue> * </entry><entry>soup_server_message_get_request_headers <phrase>()</phrase></entry></row> <row><entry><returnvalue>SoupMessageHeaders</returnvalue> * </entry><entry>soup_server_message_get_response_headers <phrase>()</phrase></entry></row> <row><entry><returnvalue>SoupMessageBody</returnvalue> * </entry><entry>soup_server_message_get_request_body <phrase>()</phrase></entry></row> <row><entry><returnvalue>SoupMessageBody</returnvalue> * </entry><entry>soup_server_message_get_response_body <phrase>()</phrase></entry></row> <row><entry>const <returnvalue>char</returnvalue> * </entry><entry>soup_server_message_get_method <phrase>()</phrase></entry></row> <row><entry><returnvalue>SoupHTTPVersion</returnvalue> </entry><entry>soup_server_message_get_http_version <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_message_set_http_version <phrase>()</phrase></entry></row> <row><entry><returnvalue>guint</returnvalue> </entry><entry>soup_server_message_get_status <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_message_set_status <phrase>()</phrase></entry></row> <row><entry>const <returnvalue>char</returnvalue> * </entry><entry>soup_server_message_get_reason_phrase <phrase>()</phrase></entry></row> <row><entry><returnvalue>GUri</returnvalue> * </entry><entry>soup_server_message_get_uri <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_message_set_response <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_server_message_set_redirect <phrase>()</phrase></entry></row> <row><entry><returnvalue>GSocket</returnvalue> * </entry><entry>soup_server_message_get_socket <phrase>()</phrase></entry></row> <row><entry><returnvalue>GSocketAddress</returnvalue> * </entry><entry>soup_server_message_get_local_address <phrase>()</phrase></entry></row> <row><entry><returnvalue>GSocketAddress</returnvalue> * </entry><entry>soup_server_message_get_remote_address <phrase>()</phrase></entry></row> <row><entry>const <returnvalue>char</returnvalue> * </entry><entry>soup_server_message_get_remote_host <phrase>()</phrase></entry></row> <row><entry><returnvalue>gboolean</returnvalue> </entry><entry>soup_server_message_is_options_ping <phrase>()</phrase></entry></row> <row><entry><returnvalue>GIOStream</returnvalue> * </entry><entry>soup_server_message_steal_connection <phrase>()</phrase></entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Signals</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><returnvalue>gboolean</returnvalue></entry><entry>accept-certificate</entry><entry>Run Last</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>disconnected</entry><entry>Run Last</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>finished</entry><entry>Run Last</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>got-body</entry><entry>Run Last</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>got-chunk</entry><entry>Run First</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>got-headers</entry><entry>Run Last</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>wrote-body</entry><entry>Run Last</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>wrote-body-data</entry><entry>Run Last</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>wrote-chunk</entry><entry>Run Last</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>wrote-headers</entry><entry>Run Last</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>wrote-informational</entry><entry>Run Last</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Types and Values</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry></entry><entry>SoupServerMessage</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Object Hierarchy</title> <screen> GObject <phrase>╰──</phrase> SoupServerMessage </screen> </refsect1> <refsect1><title>Includes</title><synopsis>#include <libsoup/soup.h> </synopsis></refsect1> <refsect1> <title>Description</title> <para>A SoupServerMessage represents an HTTP message that is being sent or received on a <type>SoupServer</type></para> <para><type>SoupServer</type> will create <type>SoupServerMessage</type>s automatically for incoming requests, which your application will receive via handlers.</para> <para>Note that libsoup's terminology here does not quite match the HTTP specification: in RFC 2616, an "HTTP-message" is <emphasis>either</emphasis> a Request, <emphasis>or</emphasis> a Response. In libsoup, a <type>SoupServerMessage</type> combines both the request and the response.</para> </refsect1> <refsect1> <title>Functions</title> <refsect2> <title>soup_server_message_get_request_headers ()</title> <programlisting><returnvalue>SoupMessageHeaders</returnvalue> * soup_server_message_get_request_headers (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Get the request headers of <parameter>msg</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a <type>SoupMessageHeaders</type> with the request headers. </para> <para><emphasis>[transfer none]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_get_response_headers ()</title> <programlisting><returnvalue>SoupMessageHeaders</returnvalue> * soup_server_message_get_response_headers (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Get the response headers of <parameter>msg</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a <type>SoupMessageHeaders</type> with the response headers. </para> <para><emphasis>[transfer none]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_get_request_body ()</title> <programlisting><returnvalue>SoupMessageBody</returnvalue> * soup_server_message_get_request_body (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Get the request body of <parameter>msg</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a <type>SoupMessageBody</type>. </para> <para><emphasis>[transfer none]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_get_response_body ()</title> <programlisting><returnvalue>SoupMessageBody</returnvalue> * soup_server_message_get_response_body (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Get the response body of <parameter>msg</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a <type>SoupMessageBody</type>. </para> <para><emphasis>[transfer none]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_get_method ()</title> <programlisting>const <returnvalue>char</returnvalue> * soup_server_message_get_method (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Get the HTTP method of <parameter>msg</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the HTTP method.</para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_get_http_version ()</title> <programlisting><returnvalue>SoupHTTPVersion</returnvalue> soup_server_message_get_http_version (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Get the HTTP version of <parameter>msg</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> a <type>SoupHTTPVersion</type>.</para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_set_http_version ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_message_set_http_version (<parameter><type>SoupServerMessage</type> *msg</parameter>, <parameter><type>SoupHTTPVersion</type> version</parameter>);</programlisting> <para>Set the HTTP version of <parameter>msg</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> <row><entry><para>version</para></entry> <entry><para>a <type>SoupHTTPVersion</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_message_get_status ()</title> <programlisting><returnvalue>guint</returnvalue> soup_server_message_get_status (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Get the HTTP status code of <parameter>msg</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the HTTP status code.</para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_set_status ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_message_set_status (<parameter><type>SoupServerMessage</type> *msg</parameter>, <parameter><type>guint</type> status_code</parameter>, <parameter>const <type>char</type> *reason_phrase</parameter>);</programlisting> <para>Sets <parameter>msg</parameter> 's status code to <parameter>status_code</parameter> . If <parameter>status_code</parameter> is a known value and <parameter>reason_phrase</parameter> is <literal>NULL</literal>, the reason_phrase will be set automatically.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> <row><entry><para>status_code</para></entry> <entry><para>an HTTP status code</para></entry> <entry></entry></row> <row><entry><para>reason_phrase</para></entry> <entry><para>a reason phrase. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_message_get_reason_phrase ()</title> <programlisting>const <returnvalue>char</returnvalue> * soup_server_message_get_reason_phrase (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Get the HTTP reason phrase of <parameter>msg</parameter> or <literal>NULL</literal>.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type>:</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>the reason phrase. </para> <para><emphasis>[nullable]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_get_uri ()</title> <programlisting><returnvalue>GUri</returnvalue> * soup_server_message_get_uri (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Get <parameter>msg</parameter> 's URI.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a <type>GUri</type>. </para> <para><emphasis>[transfer none]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_set_response ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_message_set_response (<parameter><type>SoupServerMessage</type> *msg</parameter>, <parameter>const <type>char</type> *content_type</parameter>, <parameter><type>SoupMemoryUse</type> resp_use</parameter>, <parameter>const <type>char</type> *resp_body</parameter>, <parameter><type>gsize</type> resp_length</parameter>);</programlisting> <para>Convenience function to set the response body of a <type>SoupServerMessage</type>. If <parameter>content_type</parameter> is <literal>NULL</literal>, the response body must be empty as well.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><para>content_type</para></entry> <entry><para>MIME Content-Type of the body. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>resp_use</para></entry> <entry><para>a <type>SoupMemoryUse</type> describing how to handle <parameter>resp_body</parameter> </para></entry> <entry></entry></row> <row><entry><para>resp_body</para></entry> <entry><para>a data buffer containing the body of the message response. </para></entry> <entry><emphasis>[nullable][array length=resp_length][element-type guint8]</emphasis></entry></row> <row><entry><para>resp_length</para></entry> <entry><para>the byte length of <parameter>resp_body</parameter> .</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_message_set_redirect ()</title> <programlisting><returnvalue>void</returnvalue> soup_server_message_set_redirect (<parameter><type>SoupServerMessage</type> *msg</parameter>, <parameter><type>guint</type> status_code</parameter>, <parameter>const <type>char</type> *redirect_uri</parameter>);</programlisting> <para>Sets <parameter>msg</parameter> 's status_code to <parameter>status_code</parameter> and adds a Location header pointing to <parameter>redirect_uri</parameter> . Use this from a <type>SoupServer</type> when you want to redirect the client to another URI.</para> <para><parameter>redirect_uri</parameter> can be a relative URI, in which case it is interpreted relative to <parameter>msg</parameter> 's current URI. In particular, if <parameter>redirect_uri</parameter> is just a path, it will replace the path <emphasis>and query</emphasis> of <parameter>msg</parameter> 's URI.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> <row><entry><para>status_code</para></entry> <entry><para>a 3xx status code</para></entry> <entry></entry></row> <row><entry><para>redirect_uri</para></entry> <entry><para>the URI to redirect <parameter>msg</parameter> to</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_server_message_get_socket ()</title> <programlisting><returnvalue>GSocket</returnvalue> * soup_server_message_get_socket (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Retrieves the <type>GSocket</type> that <parameter>msg</parameter> is associated with.</para> <para>If you are using this method to observe when multiple requests are made on the same persistent HTTP connection (eg, as the ntlm-test test program does), you will need to pay attention to socket destruction as well (eg, by using weak references), so that you do not get fooled when the allocator reuses the memory address of a previously-destroyed socket to represent a new socket.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>the <type>GSocket</type> that <parameter>msg</parameter> is associated with, <literal>NULL</literal> if you used <function>soup_server_accept_iostream()</function>. </para> <para><emphasis>[nullable][transfer none]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_get_local_address ()</title> <programlisting><returnvalue>GSocketAddress</returnvalue> * soup_server_message_get_local_address (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Retrieves the <type>GSocketAddress</type> associated with the local end of a connection.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>the <type>GSocketAddress</type> associated with the local end of a connection, it may be <literal>NULL</literal> if you used <function>soup_server_accept_iostream()</function>. </para> <para><emphasis>[nullable][transfer none]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_get_remote_address ()</title> <programlisting><returnvalue>GSocketAddress</returnvalue> * soup_server_message_get_remote_address (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Retrieves the <type>GSocketAddress</type> associated with the remote end of a connection.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>the <type>GSocketAddress</type> associated with the remote end of a connection, it may be <literal>NULL</literal> if you used <function>soup_server_accept_iostream()</function>. </para> <para><emphasis>[nullable][transfer none]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_get_remote_host ()</title> <programlisting>const <returnvalue>char</returnvalue> * soup_server_message_get_remote_host (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Retrieves the IP address associated with the remote end of a connection.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>the IP address associated with the remote end of a connection, it may be <literal>NULL</literal> if you used <function>soup_server_accept_iostream()</function>. </para> <para><emphasis>[nullable]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_is_options_ping ()</title> <programlisting><returnvalue>gboolean</returnvalue> soup_server_message_is_options_ping (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>Gets if <parameter>msg</parameter> represents an OPTIONS message with the path <literal>*</literal>.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> <literal>TRUE</literal> if is an OPTIONS ping</para> </refsect3></refsect2>
<refsect2> <title>soup_server_message_steal_connection ()</title> <programlisting><returnvalue>GIOStream</returnvalue> * soup_server_message_steal_connection (<parameter><type>SoupServerMessage</type> *msg</parameter>);</programlisting> <para>"Steals" the HTTP connection associated with <parameter>msg</parameter> from its <type>SoupServer</type>. This happens immediately, regardless of the current state of the connection; if the response to <parameter>msg</parameter> has not yet finished being sent, then it will be discarded; you can steal the connection from a <type>“wrote-informational”</type> or <type>“wrote-body”</type> signal handler if you need to wait for part or all of the response to be sent.</para> <para>Note that when calling this function from C, <parameter>msg</parameter> will most likely be freed as a side effect.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupServerMessage</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>the <type>GIOStream</type> formerly associated with <parameter>msg</parameter> (or <literal>NULL</literal> if <parameter>msg</parameter> was no longer associated with a connection). No guarantees are made about what kind of <type>GIOStream</type> is returned. </para> <para><emphasis>[transfer full]</emphasis></para> </refsect3></refsect2> </refsect1>
<refsect1> <title>Types and Values</title> <refsect2> <title>SoupServerMessage</title> <programlisting>typedef struct _SoupServerMessage SoupServerMessage;</programlisting> <para>Class represnting an HTTP request and response pair for a server.</para> </refsect2> </refsect1> <refsect1> <title>Signal Details</title> <refsect2><title>The <literal>“accept-certificate”</literal> signal</title> <programlisting><returnvalue>gboolean</returnvalue> user_function (<type>SoupServerMessage</type> *msg, <type>GTlsCertificate</type> *tls_peer_certificate, <type>GTlsCertificateFlags</type> tls_peer_errors, <type>gpointer</type> user_data)</programlisting> <para>Emitted during the <parameter>msg</parameter> 's connection TLS handshake after client TLS certificate has been received. You can return <literal>TRUE</literal> to accept <parameter>tls_certificate</parameter> despite <parameter>tls_errors</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><para>tls_peer_certificate</para></entry> <entry><para>the peer's <type>GTlsCertificate</type></para></entry> <entry></entry></row> <row><entry><para>tls_peer_errors</para></entry> <entry><para>the tls errors of <parameter>tls_certificate</parameter> </para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> <literal>TRUE</literal> to accept the TLS certificate and stop other handlers from being invoked, or <literal>FALSE</literal> to propagate the event further.</para> </refsect3><para>Flags: Run Last</para> </refsect2>
<refsect2><title>The <literal>“disconnected”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServerMessage</type> *msg, <type>gpointer</type> user_data)</programlisting> <para>Emitted when the <parameter>msg</parameter> 's socket is disconnected.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run Last</para> </refsect2>
<refsect2><title>The <literal>“finished”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServerMessage</type> *msg, <type>gpointer</type> user_data)</programlisting> <para>Emitted when all HTTP processing is finished for a message. (After <type>“wrote-body”</type>).</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run Last</para> </refsect2>
<refsect2><title>The <literal>“got-body”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServerMessage</type> *msg, <type>gpointer</type> user_data)</programlisting> <para>Emitted after receiving the complete request body.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run Last</para> </refsect2>
<refsect2><title>The <literal>“got-chunk”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServerMessage</type> *msg, <type>GBytes</type> *chunk, <type>gpointer</type> user_data)</programlisting> <para>Emitted after receiving a chunk of a message body. Note that "chunk" in this context means any subpiece of the body, not necessarily the specific HTTP 1.1 chunks sent by the other side.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><para>chunk</para></entry> <entry><para>the just-read chunk</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run First</para> </refsect2>
<refsect2><title>The <literal>“got-headers”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServerMessage</type> *msg, <type>gpointer</type> user_data)</programlisting> <para>Emitted after receiving the Request-Line and request headers.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run Last</para> </refsect2>
<refsect2><title>The <literal>“wrote-body”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServerMessage</type> *msg, <type>gpointer</type> user_data)</programlisting> <para>Emitted immediately after writing the complete response body for a message.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run Last</para> </refsect2>
<refsect2><title>The <literal>“wrote-body-data”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServerMessage</type> *msg, <type>guint</type> chunk_size, <type>gpointer</type> user_data)</programlisting> <para>Emitted immediately after writing a portion of the message body to the network.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><para>chunk_size</para></entry> <entry><para>the number of bytes written</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run Last</para> </refsect2>
<refsect2><title>The <literal>“wrote-chunk”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServerMessage</type> *msg, <type>gpointer</type> user_data)</programlisting> <para>Emitted immediately after writing a body chunk for a message.</para> <para>Note that this signal is not parallel to <type>“got-chunk”</type>; it is emitted only when a complete chunk (added with <function>soup_message_body_append()</function> or <function>soup_message_body_append_bytes()</function>) has been written. To get more useful continuous progress information, use <type>“wrote-body-data”</type>.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run Last</para> </refsect2>
<refsect2><title>The <literal>“wrote-headers”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServerMessage</type> *msg, <type>gpointer</type> user_data)</programlisting> <para>Emitted immediately after writing the response headers for a message.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run Last</para> </refsect2>
<refsect2><title>The <literal>“wrote-informational”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupServerMessage</type> *msg, <type>gpointer</type> user_data)</programlisting> <para>Emitted immediately after writing a 1xx (Informational) response.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>the message</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run Last</para> </refsect2> </refsect1>
<refsect1> <title>See Also</title> <para><type>SoupMessageHeaders</type>, <type>SoupMessageBody</type></para> </refsect1> </refentry>
<refentry> <refmeta> <refentrytitle>SoupMessageBody</refentrytitle> <manvolnum>3</manvolnum> <refmiscinfo>LIBSOUP-3.0 Library</refmiscinfo> </refmeta>

<refentrytitle>SoupMessageBody</refentrytitle>

<refname>SoupMessageBody</refname> <refpurpose>HTTP message body</refpurpose>

<refsect1> <title>Functions</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><returnvalue>SoupMessageBody</returnvalue> * </entry><entry>soup_message_body_new <phrase>()</phrase></entry></row> <row><entry><returnvalue>SoupMessageBody</returnvalue> * </entry><entry>soup_message_body_ref <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_message_body_unref <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_message_body_set_accumulate <phrase>()</phrase></entry></row> <row><entry><returnvalue>gboolean</returnvalue> </entry><entry>soup_message_body_get_accumulate <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_message_body_append <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_message_body_append_bytes <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_message_body_append_take <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_message_body_truncate <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_message_body_complete <phrase>()</phrase></entry></row> <row><entry><returnvalue>GBytes</returnvalue> * </entry><entry>soup_message_body_flatten <phrase>()</phrase></entry></row> <row><entry><returnvalue>GBytes</returnvalue> * </entry><entry>soup_message_body_get_chunk <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_message_body_got_chunk <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_message_body_wrote_chunk <phrase>()</phrase></entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Types and Values</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry>enum</entry><entry>SoupMemoryUse</entry></row> <row><entry></entry><entry>SoupMessageBody</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Object Hierarchy</title> <screen> GBoxed <phrase>╰──</phrase> SoupMessageBody </screen> </refsect1> <refsect1><title>Includes</title><synopsis>#include <libsoup/soup.h> </synopsis></refsect1> <refsect1> <title>Description</title> <para><type>SoupMessageBody</type> represents the request or response body of a <type>SoupMessage</type>.</para> </refsect1> <refsect1> <title>Functions</title> <refsect2> <title>soup_message_body_new ()</title> <programlisting><returnvalue>SoupMessageBody</returnvalue> * soup_message_body_new (<parameter><type>void</type></parameter>);</programlisting> <para>Creates a new <type>SoupMessageBody</type>. <type>SoupMessage</type> uses this internally; you will not normally need to call it yourself.</para> <refsect3> <title>Returns</title> <para> a new <type>SoupMessageBody</type>.</para> </refsect3></refsect2>
<refsect2> <title>soup_message_body_ref ()</title> <programlisting><returnvalue>SoupMessageBody</returnvalue> * soup_message_body_ref (<parameter><type>SoupMessageBody</type> *body</parameter>);</programlisting> <para>Atomically increments the reference count of <parameter>body</parameter> by one.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the passed in <type>SoupMessageBody</type></para> </refsect3></refsect2>
<refsect2> <title>soup_message_body_unref ()</title> <programlisting><returnvalue>void</returnvalue> soup_message_body_unref (<parameter><type>SoupMessageBody</type> *body</parameter>);</programlisting> <para>Atomically decrements the reference count of <parameter>body</parameter> by one. When the reference count reaches zero, the resources allocated by <parameter>body</parameter> are freed</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_message_body_set_accumulate ()</title> <programlisting><returnvalue>void</returnvalue> soup_message_body_set_accumulate (<parameter><type>SoupMessageBody</type> *body</parameter>, <parameter><type>gboolean</type> accumulate</parameter>);</programlisting> <para>Sets or clears the accumulate flag on <parameter>body</parameter> . (The default value is <literal>TRUE</literal>.) If set to <literal>FALSE</literal>, <parameter>body</parameter> 's data field will not be filled in after the body is fully sent/received, and the chunks that make up <parameter>body</parameter> may be discarded when they are no longer needed.</para> <para>If you set the flag to <literal>FALSE</literal> on the <type>SoupMessage</type> request_body of a client-side message, it will block the accumulation of chunks into <parameter>body</parameter> 's data field, but it will not normally cause the chunks to be discarded after being written like in the server-side <type>SoupMessage</type> response_body case, because the request body needs to be kept around in case the request needs to be sent a second time due to redirection or authentication.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> <row><entry><para>accumulate</para></entry> <entry><para>whether or not to accumulate body chunks in <parameter>body</parameter> </para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_message_body_get_accumulate ()</title> <programlisting><returnvalue>gboolean</returnvalue> soup_message_body_get_accumulate (<parameter><type>SoupMessageBody</type> *body</parameter>);</programlisting> <para>Gets the accumulate flag on <parameter>body</parameter> ; see <function>soup_message_body_set_accumulate()</function> for details.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the accumulate flag for <parameter>body</parameter> .</para> </refsect3></refsect2>
<refsect2> <title>soup_message_body_append ()</title> <programlisting><returnvalue>void</returnvalue> soup_message_body_append (<parameter><type>SoupMessageBody</type> *body</parameter>, <parameter><type>SoupMemoryUse</type> use</parameter>, <parameter><type>gconstpointer</type> data</parameter>, <parameter><type>gsize</type> length</parameter>);</programlisting> <para>Appends <parameter>length</parameter> bytes from <parameter>data</parameter> to <parameter>body</parameter> according to <parameter>use</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> <row><entry><para>use</para></entry> <entry><para>how to use <parameter>data</parameter> </para></entry> <entry></entry></row> <row><entry><para>data</para></entry> <entry><para>data to append. </para></entry> <entry><emphasis>[array length=length][element-type guint8]</emphasis></entry></row> <row><entry><para>length</para></entry> <entry><para>length of <parameter>data</parameter> </para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_message_body_append_bytes ()</title> <programlisting><returnvalue>void</returnvalue> soup_message_body_append_bytes (<parameter><type>SoupMessageBody</type> *body</parameter>, <parameter><type>GBytes</type> *buffer</parameter>);</programlisting> <para>Appends the data from <parameter>buffer</parameter> to <parameter>body</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> <row><entry><para>buffer</para></entry> <entry><para>a <type>GBytes</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_message_body_append_take ()</title> <programlisting><returnvalue>void</returnvalue> soup_message_body_append_take (<parameter><type>SoupMessageBody</type> *body</parameter>, <parameter><type>guchar</type> *data</parameter>, <parameter><type>gsize</type> length</parameter>);</programlisting> <para>Appends <parameter>length</parameter> bytes from <parameter>data</parameter> to <parameter>body</parameter> .</para> <para>This function is exactly equivalent to <function>soup_message_body_append()</function> with <literal>SOUP_MEMORY_TAKE</literal> as second argument; it exists mainly for convenience and simplifying language bindings.</para> <para><emphasis>[rename-to soup_message_body_append]</emphasis></para><refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> <row><entry><para>data</para></entry> <entry><para>data to append. </para></entry> <entry><emphasis>[array length=length][transfer full]</emphasis></entry></row> <row><entry><para>length</para></entry> <entry><para>length of <parameter>data</parameter> </para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_message_body_truncate ()</title> <programlisting><returnvalue>void</returnvalue> soup_message_body_truncate (<parameter><type>SoupMessageBody</type> *body</parameter>);</programlisting> <para>Deletes all of the data in <parameter>body</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_message_body_complete ()</title> <programlisting><returnvalue>void</returnvalue> soup_message_body_complete (<parameter><type>SoupMessageBody</type> *body</parameter>);</programlisting> <para>Tags <parameter>body</parameter> as being complete; Call this when using chunked encoding after you have appended the last chunk.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_message_body_flatten ()</title> <programlisting><returnvalue>GBytes</returnvalue> * soup_message_body_flatten (<parameter><type>SoupMessageBody</type> *body</parameter>);</programlisting> <para>Fills in <parameter>body</parameter> 's data field with a buffer containing all of the data in <parameter>body</parameter> (plus an additional '\0' byte not counted by <parameter>body</parameter> 's length field).</para> <para>Return: (transfer full): a <type>GBytes</type> containing the same data as <parameter>body</parameter> . (You must <function>g_bytes_unref()</function> this if you do not want it.)</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_message_body_get_chunk ()</title> <programlisting><returnvalue>GBytes</returnvalue> * soup_message_body_get_chunk (<parameter><type>SoupMessageBody</type> *body</parameter>, <parameter><type>goffset</type> offset</parameter>);</programlisting> <para>Gets a <type>GBytes</type> containing data from <parameter>body</parameter> starting at <parameter>offset</parameter> . The size of the returned chunk is unspecified. You can iterate through the entire body by first calling <function>soup_message_body_get_chunk()</function> with an offset of 0, and then on each successive call, increment the offset by the length of the previously-returned chunk.</para> <para>If <parameter>offset</parameter> is greater than or equal to the total length of <parameter>body</parameter> , then the return value depends on whether or not <function>soup_message_body_complete()</function> has been called or not; if it has, then <function>soup_message_body_get_chunk()</function> will return a 0-length chunk (indicating the end of <parameter>body</parameter> ). If it has not, then <function>soup_message_body_get_chunk()</function> will return <literal>NULL</literal> (indicating that <parameter>body</parameter> may still potentially have more data, but that data is not currently available).</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> <row><entry><para>offset</para></entry> <entry><para>an offset</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a <type>GBytes</type>, or <literal>NULL</literal>. </para> <para><emphasis>[nullable]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_message_body_got_chunk ()</title> <programlisting><returnvalue>void</returnvalue> soup_message_body_got_chunk (<parameter><type>SoupMessageBody</type> *body</parameter>, <parameter><type>GBytes</type> *chunk</parameter>);</programlisting> <para>Handles the <type>SoupMessageBody</type> part of receiving a chunk of data from the network. Normally this means appending <parameter>chunk</parameter> to <parameter>body</parameter> , exactly as with <function>soup_message_body_append_bytes()</function>, but if you have set <parameter>body</parameter> 's accumulate flag to <literal>FALSE</literal>, then that will not happen.</para> <para>This is a low-level method which you should not normally need to use.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> <row><entry><para>chunk</para></entry> <entry><para>a <type>GBytes</type> received from the network</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_message_body_wrote_chunk ()</title> <programlisting><returnvalue>void</returnvalue> soup_message_body_wrote_chunk (<parameter><type>SoupMessageBody</type> *body</parameter>, <parameter><type>GBytes</type> *chunk</parameter>);</programlisting> <para>Handles the <type>SoupMessageBody</type> part of writing a chunk of data to the network. Normally this is a no-op, but if you have set <parameter>body</parameter> 's accumulate flag to <literal>FALSE</literal>, then this will cause <parameter>chunk</parameter> to be discarded to free up memory.</para> <para>This is a low-level method which you should not need to use, and there are further restrictions on its proper use which are not documented here.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>body</para></entry> <entry><para>a <type>SoupMessageBody</type></para></entry> <entry></entry></row> <row><entry><para>chunk</para></entry> <entry><para>a <type>GBytes</type> returned from <function>soup_message_body_get_chunk()</function></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2> </refsect1>
<refsect1> <title>Types and Values</title> <refsect2> <title>enum SoupMemoryUse</title> <para>The lifetime of the memory being passed.</para> <refsect3> <title>Members</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>SOUP_MEMORY_STATIC</para></entry> <entry><para>The memory is statically allocated and constant; libsoup can use the passed-in buffer directly and not need to worry about it being modified or freed.</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_MEMORY_TAKE</para></entry> <entry><para>The caller has allocated the memory and libsoup will assume ownership of it and free it with <function>g_free()</function>.</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_MEMORY_COPY</para></entry> <entry><para>The passed-in data belongs to the caller and libsoup will copy it into new memory leaving the caller free to reuse the original memory.</para> </entry> <entry></entry> </row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>SoupMessageBody</title> <programlisting>typedef struct { const char *data; goffset length; } SoupMessageBody; </programlisting> <para>A <type>SoupMessage</type> request or response body.</para> <para>Note that while <parameter>length</parameter> always reflects the full length of the message body, <parameter>data</parameter> is normally <literal>NULL</literal>, and will only be filled in after <function>soup_message_body_flatten()</function> is called. For client-side messages, this automatically happens for the response body after it has been fully read. Likewise, for server-side messages, the request body is automatically filled in after being read.</para> <para>As an added bonus, when <parameter>data</parameter> is filled in, it is always terminated with a '\0' byte (which is not reflected in <parameter>length</parameter> ).</para> <refsect3> <title>Members</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>const <type>char</type> *<structfield>data</structfield>;</para></entry> <entry><para>the data. </para></entry> <entry><emphasis>[array length=length][element-type guint8]</emphasis></entry> </row> <row><entry><para><type>goffset</type> <structfield>length</structfield>;</para></entry> <entry><para>length of <parameter>data</parameter> </para></entry> <entry></entry> </row> </tbody></tgroup></informaltable> </refsect3> </refsect2> </refsect1>
<refsect1> <title>See Also</title> <para><type>SoupMessage</type></para> </refsect1> </refentry>