This file is indexed.

/usr/share/gtk-doc/html/libsoup-2.4/libsoup-client-howto.html is in libsoup2.4-doc 2.38.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Soup Client Basics</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="index.html" title="libsoup Reference Manual">
<link rel="up" href="ch01.html" title="Tutorial">
<link rel="prev" href="libsoup-build-howto.html" title="Compiling with libsoup">
<link rel="next" href="libsoup-server-howto.html" title="Soup Server Basics">
<meta name="generator" content="GTK-Doc V1.18 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
<td><a accesskey="p" href="libsoup-build-howto.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="ch01.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">libsoup Reference Manual</th>
<td><a accesskey="n" href="libsoup-server-howto.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="libsoup-client-howto"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle">Soup Client Basics</span></h2>
<p>Soup Client Basics — Client-side tutorial</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsect2">
<a name="idp4797088"></a><h3>Creating a <span class="type">SoupSession</span>
</h3>
<p>
The first step in using the client API is to create a <a class="link" href="SoupSession.html" title="SoupSession"><span class="type">SoupSession</span></a>. The session object
encapsulates all of the state that <span class="application">libsoup</span>
is keeping on behalf of your program; cached HTTP connections,
authentication information, etc.
</p>
<p>
There are two subclasses of <a class="link" href="SoupSession.html" title="SoupSession"><span class="type">SoupSession</span></a> that you can use, with
slightly different behavior:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
	<a class="link" href="SoupSessionAsync.html" title="SoupSessionAsync"><span class="type">SoupSessionAsync</span></a>,
	which uses callbacks and the glib main loop to provide
	asynchronous I/O.
    </p></li>
<li class="listitem"><p>
	<a class="link" href="SoupSessionSync.html" title="SoupSessionSync"><span class="type">SoupSessionSync</span></a>,
	which uses blocking I/O rather than callbacks, making it more
	suitable for threaded applications.
    </p></li>
</ul></div>
<p>
If you want to do a mix of mainloop-based and blocking I/O, you will
need to create two different session objects.
</p>
<p>
When you create the session (with <a class="link" href="SoupSessionAsync.html#soup-session-async-new-with-options" title="soup_session_async_new_with_options ()"><code class="function">soup_session_async_new_with_options</code></a>
or <a class="link" href="SoupSessionSync.html#soup-session-sync-new-with-options" title="soup_session_sync_new_with_options ()"><code class="function">soup_session_sync_new_with_options</code></a>),
you can specify various additional options:
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><a class="link" href="SoupSession.html#SOUP-SESSION-MAX-CONNS:CAPS" title="SOUP_SESSION_MAX_CONNS"><code class="literal">SOUP_SESSION_MAX_CONNS</code></a></span></p></td>
<td><p>
	    Allows you to set the maximum total number of connections
	    the session will have open at one time. (Once it reaches
	    this limit, it will either close idle connections, or
	    wait for existing connections to free up before starting
	    new requests.)
	</p></td>
</tr>
<tr>
<td><p><span class="term"><a class="link" href="SoupSession.html#SOUP-SESSION-MAX-CONNS-PER-HOST:CAPS" title="SOUP_SESSION_MAX_CONNS_PER_HOST"><code class="literal">SOUP_SESSION_MAX_CONNS_PER_HOST</code></a></span></p></td>
<td><p>
	    Allows you to set the maximum total number of connections
	    the session will have open <span class="emphasis"><em>to a single
	    host</em></span> at one time.
	</p></td>
</tr>
<tr>
<td><p><span class="term"><a class="link" href="SoupSession.html#SOUP-SESSION-USE-NTLM:CAPS" title="SOUP_SESSION_USE_NTLM"><code class="literal">SOUP_SESSION_USE_NTLM</code></a></span></p></td>
<td><p>
	    If <code class="literal">TRUE</code>, then Microsoft NTLM
	    authentication will be used if available (and will be
	    preferred to HTTP Basic or Digest authentication).
	    If <code class="literal">FALSE</code>, NTLM authentication won't be
	    used, even if it's the only authentication type available.
	    (NTLM works differently from the standard HTTP
	    authentication types, so it needs to be handled
	    specially.)
	</p></td>
</tr>
<tr>
<td><p><span class="term"><a class="link" href="SoupSession.html#SOUP-SESSION-SSL-CA-FILE:CAPS" title="SOUP_SESSION_SSL_CA_FILE"><code class="literal">SOUP_SESSION_SSL_CA_FILE</code></a></span></p></td>
<td><p>
	    Points to a file containing certificates for recognized
	    SSL Certificate Authorities. If this is set, then HTTPS
	    connections will be checked against these authorities, and
	    rejected if they can't be verified. (Otherwise all SSL
	    certificates will be accepted automatically.)
	</p></td>
</tr>
<tr>
<td><p><span class="term"><a class="link" href="SoupSession.html#SOUP-SESSION-ASYNC-CONTEXT:CAPS" title="SOUP_SESSION_ASYNC_CONTEXT"><code class="literal">SOUP_SESSION_ASYNC_CONTEXT</code></a></span></p></td>
<td><p>
	    A <a href="/usr/share/gtk-doc/html/glib/glib-The-Main-Event-Loop.html#GMainContext"><span class="type">GMainContext</span></a>
	    which the session will use for asynchronous operations.
	    This can be set if you want to use a
	    <span class="type">SoupSessionAsync</span> in a thread other than the
	    main thread.
	</p></td>
</tr>
<tr>
<td><p><span class="term"><a class="link" href="SoupSession.html#SOUP-SESSION-ADD-FEATURE:CAPS" title="SOUP_SESSION_ADD_FEATURE"><code class="literal">SOUP_SESSION_ADD_FEATURE</code></a> and <a class="link" href="SoupSession.html#SOUP-SESSION-ADD-FEATURE-BY-TYPE:CAPS" title="SOUP_SESSION_ADD_FEATURE_BY_TYPE"><code class="literal">SOUP_SESSION_ADD_FEATURE_BY_TYPE</code></a></span></p></td>
<td><p>
	    These allow you to specify <a class="link" href="SoupSessionFeature.html" title="SoupSessionFeature"><span class="type">SoupSessionFeature</span></a>s
	    (discussed <a class="link" href="libsoup-client-howto.html#session-features" title="Session features">below</a>)
	    to add at construct-time.
	</p></td>
</tr>
</tbody>
</table></div>
<p>
If you don't need to specify any options, you can just use <a class="link" href="SoupSessionAsync.html#soup-session-async-new" title="soup_session_async_new ()"><code class="function">soup_session_async_new</code></a> or
<a class="link" href="SoupSessionSync.html#soup-session-sync-new" title="soup_session_sync_new ()"><code class="function">soup_session_sync_new</code></a>,
which take no arguments.
</p>
</div>
<hr>
<div class="refsect2">
<a name="session-features"></a><h3>Session features</h3>
<p>
Additional session functionality is provided as <a class="link" href="SoupSessionFeature.html" title="SoupSessionFeature"><span class="type">SoupSessionFeature</span></a>s,
which can be added to a session, via the <a class="link" href="SoupSession.html#SOUP-SESSION-ADD-FEATURE:CAPS" title="SOUP_SESSION_ADD_FEATURE"><code class="literal">SOUP_SESSION_ADD_FEATURE</code></a>
and <a class="link" href="SoupSession.html#SOUP-SESSION-ADD-FEATURE-BY-TYPE:CAPS" title="SOUP_SESSION_ADD_FEATURE_BY_TYPE"><code class="literal">SOUP_SESSION_ADD_FEATURE_BY_TYPE</code></a>
options at session-construction-time, or afterward via the <a class="link" href="SoupSession.html#soup-session-add-feature" title="soup_session_add_feature ()"><code class="function">soup_session_add_feature</code></a>
and <a class="link" href="SoupSession.html#soup-session-add-feature-by-type" title="soup_session_add_feature_by_type ()"><code class="function">soup_session_add_feature_by_type</code></a>
functions. Some of the features available in
<span class="application">libsoup</span> are:
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><a class="link" href="SoupLogger.html" title="SoupLogger"><span class="type">SoupLogger</span></a></span></p></td>
<td><p>
	    A debugging aid, which logs all of libsoup's HTTP traffic
	    to <code class="literal">stdout</code> (or another place you specify).
	</p></td>
</tr>
<tr>
<td><p><span class="term"><a class="link" href="SoupCookieJar.html" title="SoupCookieJar"><span class="type">SoupCookieJar</span></a> and <a class="link" href="SoupCookieJarText.html" title="SoupCookieJarText"><span class="type">SoupCookieJarText</span></a></span></p></td>
<td><p>
	    Support for HTTP cookies. <span class="type">SoupCookieJar</span>
	    provides non-persistent cookie storage, while
	    <span class="type">SoupCookieJarText</span> uses a text file to keep
	    track of cookies between sessions.
	</p></td>
</tr>
</tbody>
</table></div>
<p>
And in <span class="application">libsoup-gnome</span>:
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><a class="link" href="libsoup-2.4-soup-gnome-features.html#SOUP-TYPE-PROXY-RESOLVER-GNOME:CAPS" title="SOUP_TYPE_PROXY_RESOLVER_GNOME"><span class="type">SoupProxyResolverGNOME</span></a></span></p></td>
<td><p>
	    A feature that automatically determines the correct HTTP
	    proxy to use for requests.
	</p></td>
</tr>
<tr>
<td><p><span class="term"><a class="link" href="SoupCookieJarSqlite.html" title="SoupCookieJarSqlite"><span class="type">SoupCookieJarSqlite</span></a></span></p></td>
<td><p>
	    Support for HTTP cookies stored in an
	    <span class="application">SQLite</span> database.
	</p></td>
</tr>
</tbody>
</table></div>
<p>
Use the "add_feature_by_type" property/function to add features that
don't require any configuration (such as <a class="link" href="libsoup-2.4-soup-gnome-features.html#SOUP-TYPE-PROXY-RESOLVER-GNOME:CAPS" title="SOUP_TYPE_PROXY_RESOLVER_GNOME"><span class="type">SoupProxyResolverGNOME</span></a>),
and the "add_feature" property/function to add features that must be
constructed first (such as <a class="link" href="SoupLogger.html" title="SoupLogger"><span class="type">SoupLogger</span></a>). For example, an
application might do something like the following:
</p>
<div class="informalexample"><pre class="programlisting">
	session = soup_session_async_new_with_options (
#ifdef HAVE_LIBSOUP_GNOME
		SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_PROXY_RESOLVER_GNOME,
#endif
		NULL);
	if (debug_level) {
		SoupLogger *logger;

		logger = soup_logger_new (debug_level, -1);
		soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger));
		g_object_unref (logger);
	}
</pre></div>
</div>
<hr>
<div class="refsect2">
<a name="idp309312"></a><h3>Creating and Sending SoupMessages</h3>
<p>
Once you have a session, you do HTTP traffic using <a class="link" href="SoupMessage.html" title="SoupMessage"><span class="type">SoupMessage</span></a>. In the simplest
case, you only need to create the message and it's ready to send:
</p>
<div class="informalexample"><pre class="programlisting">
	SoupMessage *msg;

	msg = soup_message_new ("GET", "http://example.com/");
</pre></div>
<p>
In more complicated cases, you can use various <a class="link" href="SoupMessage.html" title="SoupMessage">SoupMessage</a>, <a class="link" href="SoupMessageHeaders.html" title="SoupMessageHeaders">SoupMessageHeaders</a>, and <a class="link" href="SoupMessageBody.html" title="SoupMessageBody">SoupMessageBody</a> methods to set the
request headers and body of the message:
</p>
<div class="informalexample"><pre class="programlisting">
	SoupMessage *msg;

	msg = soup_message_new ("POST", "http://example.com/form.cgi");
	soup_message_set_request (msg, "application/x-www-form-urlencoded",
				  SOUP_MEMORY_COPY, formdata, strlen (formdata));
	soup_message_headers_append (msg-&gt;request_headers, "Referer", referring_url);
</pre></div>
<p>
(Although this is a bad example, because
<span class="application">libsoup</span> actually has convenience methods
for dealing with <a class="link" href="libsoup-2.4-HTML-Form-Support.html" title="HTML Form Support">HTML
forms</a>, as well as <a class="link" href="libsoup-2.4-XMLRPC-Support.html" title="XMLRPC Support">XML-RPC</a>.)
</p>
<p>
You can also use <a class="link" href="SoupMessage.html#soup-message-set-flags" title="soup_message_set_flags ()"><code class="function">soup_message_set_flags</code></a>
to change some default behaviors. For example, by default,
<span class="type">SoupSession</span> automatically handles responses from the
server that redirect to another URL. If you would like to handle these
yourself, you can set the <a class="link" href="SoupMessage.html#SOUP-MESSAGE-NO-REDIRECT:CAPS"><code class="literal">SOUP_MESSAGE_NO_REDIRECT</code></a>
flag.
</p>
<div class="refsect3">
<a name="idp3349168"></a><h4>Sending a Message Synchronously</h4>
<p>
To send a message and wait for the response, use <a class="link" href="SoupSession.html#soup-session-send-message" title="soup_session_send_message ()"><code class="function">soup_session_send_message</code></a>:
</p>
<div class="informalexample"><pre class="programlisting">
	guint status;

	status = soup_session_send_message (session, msg);
</pre></div>
<p>
(If you use <code class="function">soup_session_send_message</code> with a
<a class="link" href="SoupSessionAsync.html" title="SoupSessionAsync"><span class="type">SoupSessionAsync</span></a>,
it will run the main loop itself until the message is complete.)
</p>
<p>
The return value from <code class="function">soup_session_send_message</code>
is a <a class="link" href="libsoup-2.4-soup-status.html" title="soup-status">libsoup status code</a>,
indicating either a transport error that prevented the message from
being sent, or the HTTP status that was returned by the server in
response to the message. (The status is also available as
<code class="literal">msg-&gt;status_code</code>.)
</p>
</div>
<div class="refsect3">
<a name="idp3353456"></a><h4>Sending a Message Asynchronously</h4>
<p>
To send a message asynchronously, use <a class="link" href="SoupSession.html#soup-session-queue-message" title="soup_session_queue_message ()"><code class="function">soup_session_queue_message</code></a>:
</p>
<div class="informalexample"><pre class="programlisting">
	...
	soup_session_queue_message (session, msg, my_callback, my_callback_data);
	...
}

static void
my_callback (SoupSession *session, SoupMessage *msg, gpointer user_data)
{
	/* Handle the response here */
}
</pre></div>
<p>
The message will be added to the session's queue, and eventually (when
control is returned back to the main loop), it will be sent and the
response be will be read. When the message is complete,
<code class="literal">callback</code> will be invoked, along with the data you
passed to <code class="function">soup_session_queue_message</code>.
</p>
<p>
<a class="link" href="SoupSession.html#soup-session-queue-message" title="soup_session_queue_message ()"><code class="function">soup_session_queue_message</code></a>
steals a reference to the message object, and unrefs it after the last
callback is invoked on it. So in the usual case, messages sent
asynchronously will be automatically freed for you without you needing
to do anything. (Of course, this wouldn't work when using the synchronous
API, since you will usually need continue working with the message
after calling <a class="link" href="SoupSession.html#soup-session-send-message" title="soup_session_send_message ()"><code class="function">soup_session_send_message</code></a>,
so in that case, you must unref it explicitly when you are done with
it.)
</p>
<p>
(If you use <a class="link" href="SoupSession.html#soup-session-queue-message" title="soup_session_queue_message ()"><code class="function">soup_session_queue_message</code></a>
with a <a class="link" href="SoupSessionSync.html" title="SoupSessionSync"><span class="type">SoupSessionSync</span></a>, the
message will be sent in another thread, with the callback eventually
being invoked in the session's <a class="link" href="SoupSession.html#SOUP-SESSION-ASYNC-CONTEXT:CAPS" title="SOUP_SESSION_ASYNC_CONTEXT"><code class="literal">SOUP_SESSION_ASYNC_CONTEXT</code></a>.)
</p>
</div>
</div>
<hr>
<div class="refsect2">
<a name="idp3360112"></a><h3>Processing the Response</h3>
<p>
Once you have received the response from the server, synchronously or
asynchronously, you can look at the response fields in the
<code class="literal">SoupMessage</code> to decide what to do next. The
<em class="structfield"><code>status_code</code></em> and
<em class="structfield"><code>reason_phrase</code></em> fields contain the numeric
status and textual status response from the server.
<em class="structfield"><code>response_headers</code></em> contains the response
headers, which you can investigate using <a class="link" href="SoupMessageHeaders.html#soup-message-headers-get" title="soup_message_headers_get ()"><code class="function">soup_message_headers_get</code></a> and
<a class="link" href="SoupMessageHeaders.html#soup-message-headers-foreach" title="soup_message_headers_foreach ()"><code class="function">soup_message_headers_foreach</code></a>.
The response body (if any) is in the
<em class="structfield"><code>response_body</code></em> field.
</p>
<p>
<a class="link" href="SoupMessageHeaders.html" title="SoupMessageHeaders"><span class="type">SoupMessageHeaders</span></a>
automatically parses several important headers in
<em class="structfield"><code>response_headers</code></em> for you and provides
specialized accessors for them. Eg, <a class="link" href="SoupMessageHeaders.html#soup-message-headers-get-content-type" title="soup_message_headers_get_content_type ()"><code class="function">soup_message_headers_get_content_type</code></a>.
There are several generic methods such as <a class="link" href="libsoup-2.4-Soup-Miscellaneous-Utilities.html#soup-header-parse-param-list" title="soup_header_parse_param_list ()"><code class="function">soup_header_parse_param_list</code></a>
(for parsing an attribute-list-type header) and <a class="link" href="libsoup-2.4-Soup-Miscellaneous-Utilities.html#soup-header-contains" title="soup_header_contains ()"><code class="function">soup_header_contains</code></a>
(for quickly testing if a list-type header contains a particular
token). These handle the various syntactical oddities of parsing HTTP
headers much better than functions like
<code class="function">g_strsplit</code> or <code class="function">strstr</code>.
</p>
</div>
<hr>
<div class="refsect2">
<a name="idp3367056"></a><h3>Intermediate/Automatic Processing</h3>
<p>
You can also connect to various <span class="type">SoupMessage</span> signals to do
processing at intermediate stages of HTTP I/O. Eg, the <a class="link" href="SoupMessage.html#SoupMessage-got-chunk" title='The "got-chunk" signal'><code class="literal">got-chunk</code></a>
signal is emitted as each piece of the response body is read (allowing
you to provide progress information when receiving a large response,
for example). <span class="type">SoupMessage</span> also provides two convenience
methods, <a class="link" href="SoupMessage.html#soup-message-add-header-handler" title="soup_message_add_header_handler ()"><code class="function">soup_message_add_header_handler</code></a>,
and <a class="link" href="SoupMessage.html#soup-message-add-status-code-handler" title="soup_message_add_status_code_handler ()"><code class="function">soup_message_add_status_code_handler</code></a>,
which allow you to set up a signal handler that will only be invoked
for messages with certain response headers or status codes.
<span class="type">SoupSession</span> uses this internally to handle authentication
and redirection.
</p>
<p>
When using the synchronous API, the callbacks and signal handlers will
be invoked during the call to <a class="link" href="SoupSession.html#soup-session-send-message" title="soup_session_send_message ()"><code class="function">soup_session_send_message</code></a>.
</p>
<p>
To automatically set up handlers on all messages sent via a session,
you can connect to the session's <a class="link" href="SoupSession.html#SoupSession-request-started" title='The "request-started" signal'><code class="literal">request_started</code></a>
signal, and add handlers to each message from there.
</p>
</div>
<hr>
<div class="refsect2">
<a name="idp3372264"></a><h3>Handling Authentication</h3>
<p>
<span class="type">SoupSession</span> handles most of the details of HTTP
authentication for you. If it receives a 401 ("Unauthorized") or 407
("Proxy Authentication Required") response, the session will emit the
<a class="link" href="SoupSession.html#SoupSession-authenticate" title='The "authenticate" signal'>authenticate</a> signal,
providing you with a <a class="link" href="SoupAuth.html" title="SoupAuth"><span class="type">SoupAuth</span></a> object indicating the
authentication type ("Basic", "Digest", or "NTLM") and the realm name
provided by the server. If you have a username and password available
(or can generate one), call <a class="link" href="SoupAuth.html#soup-auth-authenticate" title="soup_auth_authenticate ()"><code class="function">soup_auth_authenticate</code></a>
to give the information to libsoup. The session will automatically
requeue the message and try it again with that authentication
information. (If you don't call
<code class="function">soup_auth_authenticate</code>, the session will just
return the message to the application with its 401 or 407 status.)
</p>
<p>
If the server doesn't accept the username and password provided, the
session will emit <a class="link" href="SoupSession.html#SoupSession-authenticate" title='The "authenticate" signal'>authenticate</a> again, with the
<code class="literal">retrying</code> parameter set to <code class="literal">TRUE</code>. This lets the
application know that the information it provided earlier was
incorrect, and gives it a chance to try again. If this
username/password pair also doesn't work, the session will contine to
emit <code class="literal">authenticate</code> again and again until the
provided username/password successfully authenticates, or until the
signal handler fails to call <a class="link" href="SoupAuth.html#soup-auth-authenticate" title="soup_auth_authenticate ()"><code class="function">soup_auth_authenticate</code></a>,
at which point <span class="application">libsoup</span> will allow the
message to fail (with status 401 or 407).
</p>
<p>
If you need to handle authentication asynchronously (eg, to pop up a
password dialog without recursively entering the main loop), you can
do that as well. Just call <a class="link" href="SoupSession.html#soup-session-pause-message" title="soup_session_pause_message ()"><code class="function">soup_session_pause_message</code></a>
on the message before returning from the signal handler, and
<code class="function">g_object_ref</code> the <span class="type">SoupAuth</span>. Then,
later on, after calling <code class="function">soup_auth_authenticate</code>
(or deciding not to), call <a class="link" href="SoupSession.html#soup-session-unpause-message" title="soup_session_unpause_message ()"><code class="function">soup_session_unpause_message</code></a>
to resume the paused message.
</p>
</div>
<hr>
<div class="refsect2">
<a name="idp3381008"></a><h3>Multi-threaded usage</h3>
<p>
The only explicitly thread-safe operations in
<span class="application">libsoup</span> are <a class="link" href="SoupSessionSync.html" title="SoupSessionSync"><span class="type">SoupSessionSync</span></a>'s
implementations of the <a class="link" href="SoupSession.html" title="SoupSession"><span class="type">SoupSession</span></a> methods. So
after creating a <span class="type">SoupSessionSync</span>, you can call <a class="link" href="SoupSession.html#soup-session-send-message" title="soup_session_send_message ()"><code class="function">soup_session_send_message</code></a>
and <a class="link" href="SoupSession.html#soup-session-cancel-message" title="soup_session_cancel_message ()"><code class="function">soup_session_cancel_message</code></a>
on it from any thread. But, eg, while the session is processing a
message, you should not call any <a class="link" href="SoupMessage.html" title="SoupMessage"><span class="type">SoupMessage</span></a> methods on it
from any thread other than the one in which it is being sent. (That
is, you should not call any <span class="type">SoupMessage</span> methods on it
except from a message or session callback or signal handler.)
</p>
<p>
All other objects (including <a class="link" href="SoupSessionAsync.html" title="SoupSessionAsync"><span class="type">SoupSessionAsync</span></a>)
should only be used from a single thread, with objects that are also
only be used from that thread. (And in particular, if you set a
non-default <a href="/usr/share/gtk-doc/html/glib/glib-The-Main-Event-Loop.html#GMainContext"><span class="type">GMainContext</span></a> on a session,
socket, etc, then you can only use that object from the thread in
which that <span class="type">GMainContext</span> is running.)
</p>
</div>
<hr>
<div class="refsect2">
<a name="idp3386744"></a><h3>Sample Programs</h3>
<p>
A few sample programs are available in the
<span class="application">libsoup</span> sources:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
	<span class="bold"><strong><code class="literal">get</code></strong></span> is a simple command-line
	HTTP GET utility using the asynchronous API.
    </p></li>
<li class="listitem"><p>
	<span class="bold"><strong><code class="literal">getbug</code></strong></span> is a trivial
	demonstration of the <a class="link" href="libsoup-2.4-XMLRPC-Support.html" title="XMLRPC Support">XMLRPC</a> interface.
	(<span class="bold"><strong><code class="literal">xmlrpc-test</code></strong></span> provides
	a slightly more complicated example.)
    </p></li>
<li class="listitem"><p>
	<span class="bold"><strong><code class="literal">auth-test</code></strong></span> shows how to use
	authentication handlers and status-code handlers, although in
	a fairly unusual way.
    </p></li>
<li class="listitem"><p>
	<span class="bold"><strong><code class="literal">simple-proxy</code></strong></span> uses both the
	client and server APIs to create a simple (and not very
	RFC-compliant) proxy server. It shows how to use the <a class="link" href="SoupMessage.html#SoupMessageFlags" title="enum SoupMessageFlags"><code class="literal">SOUP_MESSAGE_OVERWRITE_CHUNKS</code></a>
	flag when reading a message to save memory by processing each
	chunk of the message as it is read, rather than accumulating
	them all into a single buffer to process all at the end.
    </p></li>
</ul></div>
<p>
More complicated examples are available in GNOME CVS. The <a class="ulink" href="http://live.gnome.org/LibSoup" target="_top"><span class="application">libsoup</span>
pages</a> on the GNOME wiki include a <a class="ulink" href="http://live.gnome.org/LibSoup/Users" target="_top">list of applications using
<span class="application">libsoup</span></a>.
</p>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.18</div>
</body>
</html>