1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * soup-message.c: HTTP request/response
5 * Copyright (C) 2000-2003, Ximian, Inc.
13 #include "soup-message.h"
15 #include "soup-connection.h"
16 #include "soup-message-private.h"
19 #if ENABLE(TIZEN_PERFORMANCE_TEST_LOG)
20 #include <sys/prctl.h>
21 #ifndef PR_TASK_PERF_USER_TRACE
22 #define PR_TASK_PERF_USER_TRACE 666
23 #define MAX_STRING_LEN 256
26 #define MAX_STRING_LEN 256
28 static void prctl_with_url(const char *prestr, const char *url)
30 char s[MAX_STRING_LEN] = "";
32 int len_pre = strlen(prestr);
33 int len_url = strlen(url);
35 strncpy(s, prestr, len_pre);
36 if(len_pre + len_url < len_max) {
37 strncpy(s+len_pre, url, len_url);
40 int len_part = len_max - len_pre - 10;
41 strncpy(s+len_pre, url, len_part);
42 strncpy(s+len_pre+len_part, "...", MAX_STRING_LEN-len_pre-len_part-1);
43 strncpy(s+len_pre+len_part+3, url+len_url-7, 7);
45 prctl(PR_TASK_PERF_USER_TRACE, s, strlen(s));
48 static void prctl_with_url_and_free(const char *prestr, char *url)
50 prctl_with_url(prestr, url);
56 * SECTION:soup-message
57 * @short_description: An HTTP request and response.
58 * @see_also: #SoupMessageHeaders, #SoupMessageBody
60 * A #SoupMessage represents an HTTP message that is being sent or
63 * For client-side usage, if you are using the traditional
64 * #SoupSession APIs (soup_session_queue_message() and
65 * soup_session_send_message()), you would create a #SoupMessage with
66 * soup_message_new() or soup_message_new_from_uri(), set up its
67 * fields appropriately, and send it. If you are using the newer
68 * #SoupRequest API, you would create a request with
69 * soup_session_request_http() or soup_session_request_http_uri(), and
70 * the returned #SoupRequestHTTP will already have an associated
71 * #SoupMessage that you can retrieve via
72 * soup_request_http_get_message().
74 * For server-side usage, #SoupServer will create #SoupMessage<!--
75 * -->s automatically for incoming requests, which your application
76 * will receive via handlers.
78 * Note that libsoup's terminology here does not quite match the HTTP
79 * specification: in RFC 2616, an "HTTP-message" is
80 * <emphasis>either</emphasis> a Request, <emphasis>or</emphasis> a
81 * Response. In libsoup, a #SoupMessage combines both the request and
87 * @method: the HTTP method
88 * @status_code: the HTTP status code
89 * @reason_phrase: the status phrase associated with @status_code
90 * @request_body: the request body
91 * @request_headers: the request headers
92 * @response_body: the response body
93 * @response_headers: the response headers
95 * Represents an HTTP message being sent or received.
97 * @status_code will normally be a #SoupStatus value, eg,
98 * %SOUP_STATUS_OK, though of course it might actually be an unknown
99 * status code. @reason_phrase is the actual text returned from the
100 * server, which may or may not correspond to the "standard"
101 * description of @status_code. At any rate, it is almost certainly
102 * not localized, and not very descriptive even if it is in the user's
103 * language; you should not use @reason_phrase in user-visible
104 * messages. Rather, you should look at @status_code, and determine an
105 * end-user-appropriate message based on that and on what you were
108 * As described in the #SoupMessageBody documentation, the
109 * @request_body and @response_body <literal>data</literal> fields
110 * will not necessarily be filled in at all times. When the body
111 * fields are filled in, they will be terminated with a '\0' byte
112 * (which is not included in the <literal>length</literal>), so you
113 * can use them as ordinary C strings (assuming that you know that the
114 * body doesn't have any other '\0' bytes).
116 * For a client-side #SoupMessage, @request_body's
117 * <literal>data</literal> is usually filled in right before libsoup
118 * writes the request to the network, but you should not count on
119 * this; use soup_message_body_flatten() if you want to ensure that
120 * <literal>data</literal> is filled in. If you are not using
121 * #SoupRequest to read the response, then @response_body's
122 * <literal>data</literal> will be filled in before
123 * #SoupMessage::finished is emitted. (If you are using #SoupRequest,
124 * then the message body is not accumulated by default, so
125 * @response_body's <literal>data</literal> will always be %NULL.)
127 * For a server-side #SoupMessage, @request_body's %data will be
128 * filled in before #SoupMessage::got_body is emitted.
130 * To prevent the %data field from being filled in at all (eg, if you
131 * are handling the data from a #SoupMessage::got_chunk, and so don't
132 * need to see it all at the end), call
133 * soup_message_body_set_accumulate() on @response_body or
134 * @request_body as appropriate, passing %FALSE.
137 G_DEFINE_TYPE (SoupMessage, soup_message, G_TYPE_OBJECT)
154 #if ENABLE(TIZEN_ON_AUTHENTICATION_REQUESTED)
159 #if ENABLE(TIZEN_TV_DYNAMIC_CERTIFICATE_LOADING)
160 DYNAMIC_CERTIFICATEPATH,
162 #if ENABLE(TIZEN_TV_CERTIFICATE_HANDLING)
169 static guint signals[LAST_SIGNAL] = { 0 };
183 PROP_REQUEST_BODY_DATA,
184 PROP_REQUEST_HEADERS,
186 PROP_RESPONSE_BODY_DATA,
187 PROP_RESPONSE_HEADERS,
188 PROP_TLS_CERTIFICATE,
196 soup_message_init (SoupMessage *msg)
198 SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg);
200 priv->http_version = priv->orig_http_version = SOUP_HTTP_1_1;
201 priv->priority = SOUP_MESSAGE_PRIORITY_NORMAL;
203 msg->request_body = soup_message_body_new ();
204 msg->request_headers = soup_message_headers_new (SOUP_MESSAGE_HEADERS_REQUEST);
205 msg->response_body = soup_message_body_new ();
206 msg->response_headers = soup_message_headers_new (SOUP_MESSAGE_HEADERS_RESPONSE);
210 soup_message_finalize (GObject *object)
212 SoupMessage *msg = SOUP_MESSAGE (object);
213 SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg);
215 soup_message_io_cleanup (msg);
216 if (priv->chunk_allocator_dnotify)
217 priv->chunk_allocator_dnotify (priv->chunk_allocator_data);
219 g_clear_pointer (&priv->uri, soup_uri_free);
220 g_clear_pointer (&priv->first_party, soup_uri_free);
221 g_clear_object (&priv->addr);
223 g_clear_object (&priv->auth);
224 g_clear_object (&priv->proxy_auth);
226 g_slist_free (priv->disabled_features);
228 g_clear_object (&priv->tls_certificate);
230 soup_message_body_free (msg->request_body);
231 soup_message_headers_free (msg->request_headers);
232 soup_message_body_free (msg->response_body);
233 soup_message_headers_free (msg->response_headers);
235 g_free (msg->reason_phrase);
237 G_OBJECT_CLASS (soup_message_parent_class)->finalize (object);
241 soup_message_set_property (GObject *object, guint prop_id,
242 const GValue *value, GParamSpec *pspec)
244 SoupMessage *msg = SOUP_MESSAGE (object);
245 SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg);
249 msg->method = g_intern_string (g_value_get_string (value));
252 soup_message_set_uri (msg, g_value_get_boxed (value));
254 case PROP_HTTP_VERSION:
255 soup_message_set_http_version (msg, g_value_get_enum (value));
258 soup_message_set_flags (msg, g_value_get_flags (value));
260 case PROP_SERVER_SIDE:
261 priv->server_side = g_value_get_boolean (value);
262 if (priv->server_side) {
263 soup_message_headers_set_encoding (msg->response_headers,
264 SOUP_ENCODING_CONTENT_LENGTH);
267 case PROP_STATUS_CODE:
268 soup_message_set_status (msg, g_value_get_uint (value));
270 case PROP_REASON_PHRASE:
271 soup_message_set_status_full (msg, msg->status_code,
272 g_value_get_string (value));
274 case PROP_FIRST_PARTY:
275 soup_message_set_first_party (msg, g_value_get_boxed (value));
277 case PROP_TLS_CERTIFICATE:
278 if (priv->tls_certificate)
279 g_object_unref (priv->tls_certificate);
280 priv->tls_certificate = g_value_dup_object (value);
281 if (priv->tls_errors)
282 priv->msg_flags &= ~SOUP_MESSAGE_CERTIFICATE_TRUSTED;
283 else if (priv->tls_certificate)
284 priv->msg_flags |= SOUP_MESSAGE_CERTIFICATE_TRUSTED;
286 case PROP_TLS_ERRORS:
287 priv->tls_errors = g_value_get_flags (value);
288 if (priv->tls_errors)
289 priv->msg_flags &= ~SOUP_MESSAGE_CERTIFICATE_TRUSTED;
290 else if (priv->tls_certificate)
291 priv->msg_flags |= SOUP_MESSAGE_CERTIFICATE_TRUSTED;
294 priv->priority = g_value_get_enum (value);
297 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
303 soup_message_get_property (GObject *object, guint prop_id,
304 GValue *value, GParamSpec *pspec)
306 SoupMessage *msg = SOUP_MESSAGE (object);
307 SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg);
312 g_value_set_string (value, msg->method);
315 g_value_set_boxed (value, priv->uri);
317 case PROP_HTTP_VERSION:
318 g_value_set_enum (value, priv->http_version);
321 g_value_set_flags (value, priv->msg_flags);
323 case PROP_SERVER_SIDE:
324 g_value_set_boolean (value, priv->server_side);
326 case PROP_STATUS_CODE:
327 g_value_set_uint (value, msg->status_code);
329 case PROP_REASON_PHRASE:
330 g_value_set_string (value, msg->reason_phrase);
332 case PROP_FIRST_PARTY:
333 g_value_set_boxed (value, priv->first_party);
335 case PROP_REQUEST_BODY:
336 g_value_set_boxed (value, msg->request_body);
338 case PROP_REQUEST_BODY_DATA:
339 buf = soup_message_body_flatten (msg->request_body);
340 g_value_take_boxed (value, soup_buffer_get_as_bytes (buf));
341 soup_buffer_free (buf);
343 case PROP_REQUEST_HEADERS:
344 g_value_set_boxed (value, msg->request_headers);
346 case PROP_RESPONSE_BODY:
347 g_value_set_boxed (value, msg->response_body);
349 case PROP_RESPONSE_BODY_DATA:
350 buf = soup_message_body_flatten (msg->response_body);
351 g_value_take_boxed (value, soup_buffer_get_as_bytes (buf));
352 soup_buffer_free (buf);
354 case PROP_RESPONSE_HEADERS:
355 g_value_set_boxed (value, msg->response_headers);
357 case PROP_TLS_CERTIFICATE:
358 g_value_set_object (value, priv->tls_certificate);
360 case PROP_TLS_ERRORS:
361 g_value_set_flags (value, priv->tls_errors);
364 g_value_set_enum (value, priv->priority);
367 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
373 soup_message_real_got_body (SoupMessage *msg)
375 SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg);
376 SoupMessageBody *body;
378 body = priv->server_side ? msg->request_body : msg->response_body;
379 if (soup_message_body_get_accumulate (body)) {
382 buffer = soup_message_body_flatten (body);
383 soup_buffer_free (buffer);
388 soup_message_class_init (SoupMessageClass *message_class)
390 GObjectClass *object_class = G_OBJECT_CLASS (message_class);
392 g_type_class_add_private (message_class, sizeof (SoupMessagePrivate));
394 /* virtual method definition */
395 message_class->got_body = soup_message_real_got_body;
397 /* virtual method override */
398 object_class->finalize = soup_message_finalize;
399 object_class->set_property = soup_message_set_property;
400 object_class->get_property = soup_message_get_property;
405 * SoupMessage::wrote-informational:
408 * Emitted immediately after writing a 1xx (Informational)
409 * response for a (server-side) message.
411 signals[WROTE_INFORMATIONAL] =
412 g_signal_new ("wrote_informational",
413 G_OBJECT_CLASS_TYPE (object_class),
415 G_STRUCT_OFFSET (SoupMessageClass, wrote_informational),
421 * SoupMessage::wrote-headers:
424 * Emitted immediately after writing the headers for a
425 * message. (For a client-side message, this is after writing
426 * the request headers; for a server-side message, it is after
427 * writing the response headers.)
429 signals[WROTE_HEADERS] =
430 g_signal_new ("wrote_headers",
431 G_OBJECT_CLASS_TYPE (object_class),
433 G_STRUCT_OFFSET (SoupMessageClass, wrote_headers),
439 * SoupMessage::wrote-chunk:
442 * Emitted immediately after writing a body chunk for a message.
444 * Note that this signal is not parallel to
445 * #SoupMessage::got_chunk; it is emitted only when a complete
446 * chunk (added with soup_message_body_append() or
447 * soup_message_body_append_buffer()) has been written. To get
448 * more useful continuous progress information, use
449 * #SoupMessage::wrote_body_data.
451 signals[WROTE_CHUNK] =
452 g_signal_new ("wrote_chunk",
453 G_OBJECT_CLASS_TYPE (object_class),
455 G_STRUCT_OFFSET (SoupMessageClass, wrote_chunk),
461 * SoupMessage::wrote-body-data:
463 * @chunk: the data written
465 * Emitted immediately after writing a portion of the message
466 * body to the network.
468 * Unlike #SoupMessage::wrote_chunk, this is emitted after
469 * every successful write() call, not only after finishing a
474 signals[WROTE_BODY_DATA] =
475 g_signal_new ("wrote_body_data",
476 G_OBJECT_CLASS_TYPE (object_class),
478 0, /* FIXME after next ABI break */
485 * SoupMessage::wrote-body:
488 * Emitted immediately after writing the complete body for a
489 * message. (For a client-side message, this means that
490 * libsoup is done writing and is now waiting for the response
491 * from the server. For a server-side message, this means that
492 * libsoup has finished writing the response and is nearly
493 * done with the message.)
495 signals[WROTE_BODY] =
496 g_signal_new ("wrote_body",
497 G_OBJECT_CLASS_TYPE (object_class),
499 G_STRUCT_OFFSET (SoupMessageClass, wrote_body),
505 * SoupMessage::got-informational:
508 * Emitted after receiving a 1xx (Informational) response for
509 * a (client-side) message. The response_headers will be
510 * filled in with the headers associated with the
511 * informational response; however, those header values will
512 * be erased after this signal is done.
514 * If you cancel or requeue @msg while processing this signal,
515 * then the current HTTP I/O will be stopped after this signal
516 * emission finished, and @msg's connection will be closed.
518 signals[GOT_INFORMATIONAL] =
519 g_signal_new ("got_informational",
520 G_OBJECT_CLASS_TYPE (object_class),
522 G_STRUCT_OFFSET (SoupMessageClass, got_informational),
528 * SoupMessage::got-headers:
531 * Emitted after receiving all message headers for a message.
532 * (For a client-side message, this is after receiving the
533 * Status-Line and response headers; for a server-side
534 * message, it is after receiving the Request-Line and request
537 * See also soup_message_add_header_handler() and
538 * soup_message_add_status_code_handler(), which can be used
539 * to connect to a subset of emissions of this signal.
541 * If you cancel or requeue @msg while processing this signal,
542 * then the current HTTP I/O will be stopped after this signal
543 * emission finished, and @msg's connection will be closed.
544 * (If you need to requeue a message--eg, after handling
545 * authentication or redirection--it is usually better to
546 * requeue it from a #SoupMessage::got_body handler rather
547 * than a #SoupMessage::got_headers handler, so that the
548 * existing HTTP connection can be reused.)
550 signals[GOT_HEADERS] =
551 g_signal_new ("got_headers",
552 G_OBJECT_CLASS_TYPE (object_class),
554 G_STRUCT_OFFSET (SoupMessageClass, got_headers),
560 * SoupMessage::got-chunk:
562 * @chunk: the just-read chunk
564 * Emitted after receiving a chunk of a message body. Note
565 * that "chunk" in this context means any subpiece of the
566 * body, not necessarily the specific HTTP 1.1 chunks sent by
569 * If you cancel or requeue @msg while processing this signal,
570 * then the current HTTP I/O will be stopped after this signal
571 * emission finished, and @msg's connection will be closed.
574 g_signal_new ("got_chunk",
575 G_OBJECT_CLASS_TYPE (object_class),
577 G_STRUCT_OFFSET (SoupMessageClass, got_chunk),
581 /* Use %G_SIGNAL_TYPE_STATIC_SCOPE so that
582 * the %SOUP_MEMORY_TEMPORARY buffers used
583 * by soup-message-io.c when emitting this
584 * signal don't get forcibly copied by
587 SOUP_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE);
590 * SoupMessage::got-body:
593 * Emitted after receiving the complete message body. (For a
594 * server-side message, this means it has received the request
595 * body. For a client-side message, this means it has received
596 * the response body and is nearly done with the message.)
598 * See also soup_message_add_header_handler() and
599 * soup_message_add_status_code_handler(), which can be used
600 * to connect to a subset of emissions of this signal.
603 g_signal_new ("got_body",
604 G_OBJECT_CLASS_TYPE (object_class),
606 G_STRUCT_OFFSET (SoupMessageClass, got_body),
612 * SoupMessage::content-sniffed:
614 * @type: the content type that we got from sniffing
615 * @params: (element-type utf8 utf8): a #GHashTable with the parameters
617 * This signal is emitted after #SoupMessage::got-headers, and
618 * before the first #SoupMessage::got-chunk. If content
619 * sniffing is disabled, or no content sniffing will be
620 * performed, due to the sniffer deciding to trust the
621 * Content-Type sent by the server, this signal is emitted
622 * immediately after #SoupMessage::got-headers, and @type is
625 * If the #SoupContentSniffer feature is enabled, and the
626 * sniffer decided to perform sniffing, the first
627 * #SoupMessage::got-chunk emission may be delayed, so that the
628 * sniffer has enough data to correctly sniff the content. It
629 * notified the library user that the content has been
630 * sniffed, and allows it to change the header contents in the
631 * message, if desired.
633 * After this signal is emitted, the data that was spooled so
634 * that sniffing could be done is delivered on the first
635 * emission of #SoupMessage::got-chunk.
639 signals[CONTENT_SNIFFED] =
640 g_signal_new ("content_sniffed",
641 G_OBJECT_CLASS_TYPE (object_class),
651 * SoupMessage::restarted:
654 * Emitted when a request that was already sent once is now
655 * being sent again (eg, because the first attempt received a
656 * redirection response, or because we needed to use
660 g_signal_new ("restarted",
661 G_OBJECT_CLASS_TYPE (object_class),
663 G_STRUCT_OFFSET (SoupMessageClass, restarted),
669 * SoupMessage::finished:
672 * Emitted when all HTTP processing is finished for a message.
673 * (After #SoupMessage::got_body for client-side messages, or
674 * after #SoupMessage::wrote_body for server-side messages.)
677 g_signal_new ("finished",
678 G_OBJECT_CLASS_TYPE (object_class),
680 G_STRUCT_OFFSET (SoupMessageClass, finished),
686 * SoupMessage::network-event:
688 * @event: the network event
689 * @connection: the current state of the network connection
691 * Emitted to indicate that some network-related event
692 * related to @msg has occurred. This essentially proxies the
693 * #GSocketClient::event signal, but only for events that
694 * occur while @msg "owns" the connection; if @msg is sent on
695 * an existing persistent connection, then this signal will
696 * not be emitted. (If you want to force the message to be
697 * sent on a new connection, set the
698 * %SOUP_MESSAGE_NEW_CONNECTION flag on it.)
700 * See #GSocketClient::event for more information on what
701 * the different values of @event correspond to, and what
702 * @connection will be in each case.
706 signals[NETWORK_EVENT] =
707 g_signal_new ("network_event",
708 G_OBJECT_CLASS_TYPE (object_class),
714 G_TYPE_SOCKET_CLIENT_EVENT,
717 #if ENABLE(TIZEN_TV_DYNAMIC_CERTIFICATE_LOADING)
718 signals[DYNAMIC_CERTIFICATEPATH] =
719 g_signal_new ("dynamic-certificatePath",
720 G_OBJECT_CLASS_TYPE (object_class),
729 * SoupMessage::accept-certificate:
731 * @certificate: the certificate
732 * @error: the kind of the certificate errors
734 * Since: webengine2014
736 #if ENABLE(TIZEN_TV_CERTIFICATE_HANDLING)
737 signals[ACCEPT_CERTIFICATE] =
738 g_signal_new ("accept_certificate",
739 G_OBJECT_CLASS_TYPE (object_class),
745 G_TYPE_TLS_CERTIFICATE,
746 G_TYPE_TLS_CERTIFICATE_FLAGS);
749 #if ENABLE(TIZEN_ON_AUTHENTICATION_REQUESTED)
750 signals[AUTHENTICATE] =
751 g_signal_new ("authenticate",
752 G_OBJECT_CLASS_TYPE (object_class),
754 G_STRUCT_OFFSET (SoupMessageClass, authenticate),
764 * SOUP_MESSAGE_METHOD:
766 * Alias for the #SoupMessage:method property. (The message's
769 g_object_class_install_property (
770 object_class, PROP_METHOD,
771 g_param_spec_string (SOUP_MESSAGE_METHOD,
773 "The message's HTTP method",
779 * Alias for the #SoupMessage:uri property. (The message's
782 g_object_class_install_property (
783 object_class, PROP_URI,
784 g_param_spec_boxed (SOUP_MESSAGE_URI,
786 "The message's Request-URI",
790 * SOUP_MESSAGE_HTTP_VERSION:
792 * Alias for the #SoupMessage:http-version property. (The
793 * message's #SoupHTTPVersion.)
795 g_object_class_install_property (
796 object_class, PROP_HTTP_VERSION,
797 g_param_spec_enum (SOUP_MESSAGE_HTTP_VERSION,
799 "The HTTP protocol version to use",
800 SOUP_TYPE_HTTP_VERSION,
804 * SOUP_MESSAGE_FLAGS:
806 * Alias for the #SoupMessage:flags property. (The message's
807 * #SoupMessageFlags.)
809 g_object_class_install_property (
810 object_class, PROP_FLAGS,
811 g_param_spec_flags (SOUP_MESSAGE_FLAGS,
813 "Various message options",
814 SOUP_TYPE_MESSAGE_FLAGS,
818 * SOUP_MESSAGE_SERVER_SIDE:
820 * Alias for the #SoupMessage:server-side property. (%TRUE if
821 * the message was created by #SoupServer.)
823 g_object_class_install_property (
824 object_class, PROP_SERVER_SIDE,
825 g_param_spec_boolean (SOUP_MESSAGE_SERVER_SIDE,
827 "Whether or not the message is server-side rather than client-side",
829 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
831 * SOUP_MESSAGE_STATUS_CODE:
833 * Alias for the #SoupMessage:status-code property. (The
834 * message's HTTP response status code.)
836 g_object_class_install_property (
837 object_class, PROP_STATUS_CODE,
838 g_param_spec_uint (SOUP_MESSAGE_STATUS_CODE,
840 "The HTTP response status code",
844 * SOUP_MESSAGE_REASON_PHRASE:
846 * Alias for the #SoupMessage:reason-phrase property. (The
847 * message's HTTP response reason phrase.)
849 g_object_class_install_property (
850 object_class, PROP_REASON_PHRASE,
851 g_param_spec_string (SOUP_MESSAGE_REASON_PHRASE,
853 "The HTTP response reason phrase",
857 * SOUP_MESSAGE_FIRST_PARTY:
859 * Alias for the #SoupMessage:first-party property. (The
860 * #SoupURI loaded in the application when the message was
866 * SoupMessage:first-party:
868 * The #SoupURI loaded in the application when the message was
873 g_object_class_install_property (
874 object_class, PROP_FIRST_PARTY,
875 g_param_spec_boxed (SOUP_MESSAGE_FIRST_PARTY,
877 "The URI loaded in the application when the message was requested.",
881 * SOUP_MESSAGE_REQUEST_BODY:
883 * Alias for the #SoupMessage:request-body property. (The
884 * message's HTTP request body.)
886 g_object_class_install_property (
887 object_class, PROP_REQUEST_BODY,
888 g_param_spec_boxed (SOUP_MESSAGE_REQUEST_BODY,
890 "The HTTP request content",
891 SOUP_TYPE_MESSAGE_BODY,
894 * SOUP_MESSAGE_REQUEST_BODY_DATA:
896 * Alias for the #SoupMessage:request-body-data property. (The
897 * message's HTTP request body, as a #GBytes.)
902 * SoupMessage:request-body-data:
904 * The message's HTTP request body, as a #GBytes.
908 g_object_class_install_property (
909 object_class, PROP_REQUEST_BODY_DATA,
910 g_param_spec_boxed (SOUP_MESSAGE_REQUEST_BODY_DATA,
912 "The HTTP request body",
916 * SOUP_MESSAGE_REQUEST_HEADERS:
918 * Alias for the #SoupMessage:request-headers property. (The
919 * message's HTTP request headers.)
921 g_object_class_install_property (
922 object_class, PROP_REQUEST_HEADERS,
923 g_param_spec_boxed (SOUP_MESSAGE_REQUEST_HEADERS,
925 "The HTTP request headers",
926 SOUP_TYPE_MESSAGE_HEADERS,
929 * SOUP_MESSAGE_RESPONSE_BODY:
931 * Alias for the #SoupMessage:response-body property. (The
932 * message's HTTP response body.)
934 g_object_class_install_property (
935 object_class, PROP_RESPONSE_BODY,
936 g_param_spec_boxed (SOUP_MESSAGE_RESPONSE_BODY,
938 "The HTTP response content",
939 SOUP_TYPE_MESSAGE_BODY,
942 * SOUP_MESSAGE_RESPONSE_BODY_DATA:
944 * Alias for the #SoupMessage:response-body-data property. (The
945 * message's HTTP response body, as a #GBytes.)
950 * SoupMessage:response-body-data:
952 * The message's HTTP response body, as a #GBytes.
956 g_object_class_install_property (
957 object_class, PROP_RESPONSE_BODY_DATA,
958 g_param_spec_boxed (SOUP_MESSAGE_RESPONSE_BODY_DATA,
959 "Response Body Data",
960 "The HTTP response body",
964 * SOUP_MESSAGE_RESPONSE_HEADERS:
966 * Alias for the #SoupMessage:response-headers property. (The
967 * message's HTTP response headers.)
969 g_object_class_install_property (
970 object_class, PROP_RESPONSE_HEADERS,
971 g_param_spec_boxed (SOUP_MESSAGE_RESPONSE_HEADERS,
973 "The HTTP response headers",
974 SOUP_TYPE_MESSAGE_HEADERS,
977 * SOUP_MESSAGE_TLS_CERTIFICATE:
979 * Alias for the #SoupMessage:tls-certificate property. (The
980 * TLS certificate associated with the message, if any.)
985 * SoupMessage:tls-certificate:
987 * The #GTlsCertificate associated with the message
991 g_object_class_install_property (
992 object_class, PROP_TLS_CERTIFICATE,
993 g_param_spec_object (SOUP_MESSAGE_TLS_CERTIFICATE,
995 "The TLS certificate associated with the message",
996 G_TYPE_TLS_CERTIFICATE,
999 * SOUP_MESSAGE_TLS_ERRORS:
1001 * Alias for the #SoupMessage:tls-errors property. (The
1002 * verification errors on #SoupMessage:tls-certificate.)
1007 * SoupMessage:tls-errors:
1009 * The verification errors on #SoupMessage:tls-certificate
1013 g_object_class_install_property (
1014 object_class, PROP_TLS_ERRORS,
1015 g_param_spec_flags (SOUP_MESSAGE_TLS_ERRORS,
1017 "The verification errors on the message's TLS certificate",
1018 G_TYPE_TLS_CERTIFICATE_FLAGS, 0,
1019 G_PARAM_READWRITE));
1021 * SOUP_MESSAGE_PRIORITY:
1023 * Sets the priority of the #SoupMessage. See
1024 * soup_message_set_priority() for further details.
1028 g_object_class_install_property (
1029 object_class, PROP_PRIORITY,
1030 g_param_spec_enum (SOUP_MESSAGE_PRIORITY,
1032 "The priority of the message",
1033 SOUP_TYPE_MESSAGE_PRIORITY,
1034 SOUP_MESSAGE_PRIORITY_NORMAL,
1035 G_PARAM_READWRITE));
1041 * @method: the HTTP method for the created request
1042 * @uri_string: the destination endpoint (as a string)
1044 * Creates a new empty #SoupMessage, which will connect to @uri
1046 * Return value: the new #SoupMessage (or %NULL if @uri could not
1050 soup_message_new (const char *method, const char *uri_string)
1055 g_return_val_if_fail (method != NULL, NULL);
1056 g_return_val_if_fail (uri_string != NULL, NULL);
1058 uri = soup_uri_new (uri_string);
1062 soup_uri_free (uri);
1066 msg = soup_message_new_from_uri (method, uri);
1067 soup_uri_free (uri);
1072 * soup_message_new_from_uri:
1073 * @method: the HTTP method for the created request
1074 * @uri: the destination endpoint (as a #SoupURI)
1076 * Creates a new empty #SoupMessage, which will connect to @uri
1078 * Return value: the new #SoupMessage
1081 soup_message_new_from_uri (const char *method, SoupURI *uri)
1083 return g_object_new (SOUP_TYPE_MESSAGE,
1084 SOUP_MESSAGE_METHOD, method,
1085 SOUP_MESSAGE_URI, uri,
1090 * soup_message_set_request:
1092 * @content_type: (allow-none): MIME Content-Type of the body
1093 * @req_use: a #SoupMemoryUse describing how to handle @req_body
1094 * @req_body: (allow-none) (array length=req_length) (element-type guint8):
1095 * a data buffer containing the body of the message request.
1096 * @req_length: the byte length of @req_body.
1098 * Convenience function to set the request body of a #SoupMessage. If
1099 * @content_type is %NULL, the request body must be empty as well.
1102 soup_message_set_request (SoupMessage *msg,
1103 const char *content_type,
1104 SoupMemoryUse req_use,
1105 const char *req_body,
1108 g_return_if_fail (SOUP_IS_MESSAGE (msg));
1109 g_return_if_fail (content_type != NULL || req_length == 0);
1112 g_warn_if_fail (strchr (content_type, '/') != NULL);
1114 soup_message_headers_replace (msg->request_headers,
1115 "Content-Type", content_type);
1116 soup_message_body_append (msg->request_body, req_use,
1117 req_body, req_length);
1119 soup_message_headers_remove (msg->request_headers,
1121 soup_message_body_truncate (msg->request_body);
1126 * soup_message_set_response:
1128 * @content_type: (allow-none): MIME Content-Type of the body
1129 * @resp_use: a #SoupMemoryUse describing how to handle @resp_body
1130 * @resp_body: (allow-none) (array length=resp_length) (element-type guint8):
1131 * a data buffer containing the body of the message response.
1132 * @resp_length: the byte length of @resp_body.
1134 * Convenience function to set the response body of a #SoupMessage. If
1135 * @content_type is %NULL, the response body must be empty as well.
1138 soup_message_set_response (SoupMessage *msg,
1139 const char *content_type,
1140 SoupMemoryUse resp_use,
1141 const char *resp_body,
1144 g_return_if_fail (SOUP_IS_MESSAGE (msg));
1145 g_return_if_fail (content_type != NULL || resp_length == 0);
1148 g_warn_if_fail (strchr (content_type, '/') != NULL);
1150 soup_message_headers_replace (msg->response_headers,
1151 "Content-Type", content_type);
1152 soup_message_body_append (msg->response_body, resp_use,
1153 resp_body, resp_length);
1155 soup_message_headers_remove (msg->response_headers,
1157 soup_message_body_truncate (msg->response_body);
1162 soup_message_wrote_informational (SoupMessage *msg)
1164 g_signal_emit (msg, signals[WROTE_INFORMATIONAL], 0);
1168 soup_message_wrote_headers (SoupMessage *msg)
1170 g_signal_emit (msg, signals[WROTE_HEADERS], 0);
1174 soup_message_wrote_chunk (SoupMessage *msg)
1176 g_signal_emit (msg, signals[WROTE_CHUNK], 0);
1180 soup_message_wrote_body_data (SoupMessage *msg, SoupBuffer *chunk)
1182 g_signal_emit (msg, signals[WROTE_BODY_DATA], 0, chunk);
1186 soup_message_wrote_body (SoupMessage *msg)
1188 g_signal_emit (msg, signals[WROTE_BODY], 0);
1192 soup_message_got_informational (SoupMessage *msg)
1194 g_signal_emit (msg, signals[GOT_INFORMATIONAL], 0);
1198 soup_message_got_headers (SoupMessage *msg)
1200 g_signal_emit (msg, signals[GOT_HEADERS], 0);
1204 soup_message_got_chunk (SoupMessage *msg, SoupBuffer *chunk)
1206 g_signal_emit (msg, signals[GOT_CHUNK], 0, chunk);
1210 soup_message_got_body (SoupMessage *msg)
1212 g_signal_emit (msg, signals[GOT_BODY], 0);
1216 soup_message_content_sniffed (SoupMessage *msg, const char *content_type, GHashTable *params)
1218 g_signal_emit (msg, signals[CONTENT_SNIFFED], 0, content_type, params);
1222 soup_message_restarted (SoupMessage *msg)
1224 SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1226 if (priv->msg_flags & SOUP_MESSAGE_CAN_REBUILD)
1227 soup_message_body_truncate (msg->request_body);
1229 g_signal_emit (msg, signals[RESTARTED], 0);
1233 soup_message_finished (SoupMessage *msg)
1235 #if ENABLE(TIZEN_PERFORMANCE_TEST_LOG)
1236 prctl_with_url_and_free("[EVT] soup_msg_fin : ", soup_uri_to_string(soup_message_get_uri(msg), FALSE));
1238 g_signal_emit (msg, signals[FINISHED], 0);
1242 soup_message_network_event (SoupMessage *msg,
1243 GSocketClientEvent event,
1244 GIOStream *connection)
1246 g_signal_emit (msg, signals[NETWORK_EVENT], 0,
1250 #if ENABLE(TIZEN_TV_DYNAMIC_CERTIFICATE_LOADING)
1252 soup_message_dynamic_client_certificate (SoupMessage *msg,
1253 const char* current_host)
1255 const char* get_certpath = NULL;
1257 g_signal_emit (msg, signals[DYNAMIC_CERTIFICATEPATH], 0,
1258 current_host, &get_certpath);
1259 return get_certpath;
1263 #if ENABLE(TIZEN_TV_CERTIFICATE_HANDLING)
1265 soup_message_accept_certificate (SoupMessage *msg,
1266 GTlsCertificate* certificate,
1267 GTlsCertificateFlags errors)
1269 gboolean accept = TRUE;
1270 #if ENABLE(TIZEN_DLOG)
1271 char *uri = soup_uri_to_string(soup_message_get_uri(msg), FALSE);
1273 TIZEN_LOGI("[Accept-Certificate] Certificate error URL: %s", uri);
1275 g_signal_emit (msg, signals[ACCEPT_CERTIFICATE], 0,
1276 certificate, errors, &accept);
1278 #if ENABLE(TIZEN_DLOG)
1287 #if ENABLE(TIZEN_ON_AUTHENTICATION_REQUESTED)
1289 soup_message_authenticate (SoupMessage *msg, SoupAuth *auth, gboolean retrying)
1291 g_signal_emit (msg, signals[AUTHENTICATE], 0, auth, retrying);
1296 header_handler_free (gpointer header_name, GClosure *closure)
1298 g_free (header_name);
1302 header_handler_metamarshal (GClosure *closure, GValue *return_value,
1303 guint n_param_values, const GValue *param_values,
1304 gpointer invocation_hint, gpointer marshal_data)
1306 SoupMessage *msg = g_value_get_object (¶m_values[0]);
1307 SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1308 const char *header_name = marshal_data;
1309 SoupMessageHeaders *hdrs;
1311 hdrs = priv->server_side ? msg->request_headers : msg->response_headers;
1312 if (soup_message_headers_get_one (hdrs, header_name)) {
1313 closure->marshal (closure, return_value, n_param_values,
1314 param_values, invocation_hint,
1315 ((GCClosure *)closure)->callback);
1320 * soup_message_add_header_handler: (skip)
1321 * @msg: a #SoupMessage
1322 * @signal: signal to connect the handler to.
1323 * @header: HTTP response header to match against
1324 * @callback: the header handler
1325 * @user_data: data to pass to @handler_cb
1327 * Adds a signal handler to @msg for @signal, as with
1328 * g_signal_connect(), but the @callback will only be run if @msg's
1329 * incoming messages headers (that is, the
1330 * <literal>request_headers</literal> for a client #SoupMessage, or
1331 * the <literal>response_headers</literal> for a server #SoupMessage)
1332 * contain a header named @header.
1334 * Return value: the handler ID from g_signal_connect()
1337 soup_message_add_header_handler (SoupMessage *msg,
1346 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), 0);
1347 g_return_val_if_fail (signal != NULL, 0);
1348 g_return_val_if_fail (header != NULL, 0);
1349 g_return_val_if_fail (callback != NULL, 0);
1351 closure = g_cclosure_new (callback, user_data, NULL);
1353 header_name = g_strdup (header);
1354 g_closure_set_meta_marshal (closure, header_name,
1355 header_handler_metamarshal);
1356 g_closure_add_finalize_notifier (closure, header_name,
1357 header_handler_free);
1359 return g_signal_connect_closure (msg, signal, closure, FALSE);
1363 status_handler_metamarshal (GClosure *closure, GValue *return_value,
1364 guint n_param_values, const GValue *param_values,
1365 gpointer invocation_hint, gpointer marshal_data)
1367 SoupMessage *msg = g_value_get_object (¶m_values[0]);
1368 guint status = GPOINTER_TO_UINT (marshal_data);
1370 if (msg->status_code == status) {
1371 closure->marshal (closure, return_value, n_param_values,
1372 param_values, invocation_hint,
1373 ((GCClosure *)closure)->callback);
1378 * soup_message_add_status_code_handler: (skip)
1379 * @msg: a #SoupMessage
1380 * @signal: signal to connect the handler to.
1381 * @status_code: status code to match against
1382 * @callback: the header handler
1383 * @user_data: data to pass to @handler_cb
1385 * Adds a signal handler to @msg for @signal, as with
1386 * g_signal_connect(), but the @callback will only be run if @msg has
1387 * the status @status_code.
1389 * @signal must be a signal that will be emitted after @msg's status
1390 * is set. For a client #SoupMessage, this means it can't be a "wrote"
1391 * signal. For a server #SoupMessage, this means it can't be a "got"
1394 * Return value: the handler ID from g_signal_connect()
1397 soup_message_add_status_code_handler (SoupMessage *msg,
1405 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), 0);
1406 g_return_val_if_fail (signal != NULL, 0);
1407 g_return_val_if_fail (callback != NULL, 0);
1409 closure = g_cclosure_new (callback, user_data, NULL);
1410 g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (status_code),
1411 status_handler_metamarshal);
1413 return g_signal_connect_closure (msg, signal, closure, FALSE);
1418 soup_message_set_auth (SoupMessage *msg, SoupAuth *auth)
1420 SoupMessagePrivate *priv;
1423 g_return_if_fail (SOUP_IS_MESSAGE (msg));
1424 g_return_if_fail (auth == NULL || SOUP_IS_AUTH (auth));
1426 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1429 g_object_unref (priv->auth);
1430 soup_message_headers_remove (msg->request_headers,
1437 g_object_ref (priv->auth);
1438 token = soup_auth_get_authorization (auth, msg);
1440 soup_message_headers_replace (msg->request_headers,
1441 "Authorization", token);
1447 soup_message_get_auth (SoupMessage *msg)
1449 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), NULL);
1451 return SOUP_MESSAGE_GET_PRIVATE (msg)->auth;
1455 soup_message_set_proxy_auth (SoupMessage *msg, SoupAuth *auth)
1457 SoupMessagePrivate *priv;
1460 g_return_if_fail (SOUP_IS_MESSAGE (msg));
1461 g_return_if_fail (auth == NULL || SOUP_IS_AUTH (auth));
1463 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1465 if (priv->proxy_auth) {
1466 g_object_unref (priv->proxy_auth);
1467 soup_message_headers_remove (msg->request_headers,
1468 "Proxy-Authorization");
1470 priv->proxy_auth = auth;
1471 if (!priv->proxy_auth)
1474 g_object_ref (priv->proxy_auth);
1475 token = soup_auth_get_authorization (auth, msg);
1476 soup_message_headers_replace (msg->request_headers,
1477 "Proxy-Authorization", token);
1482 soup_message_get_proxy_auth (SoupMessage *msg)
1484 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), NULL);
1486 return SOUP_MESSAGE_GET_PRIVATE (msg)->proxy_auth;
1490 soup_message_get_connection (SoupMessage *msg)
1492 return SOUP_MESSAGE_GET_PRIVATE (msg)->connection;
1496 soup_message_set_connection (SoupMessage *msg,
1497 SoupConnection *conn)
1499 SOUP_MESSAGE_GET_PRIVATE (msg)->connection = conn;
1503 * soup_message_cleanup_response:
1504 * @msg: a #SoupMessage
1506 * Cleans up all response data on @msg, so that the request can be sent
1507 * again and receive a new response. (Eg, as a result of a redirect or
1508 * authorization request.)
1511 soup_message_cleanup_response (SoupMessage *msg)
1513 SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1515 soup_message_body_truncate (msg->response_body);
1516 soup_message_headers_clear (msg->response_headers);
1517 if (priv->server_side) {
1518 soup_message_headers_set_encoding (msg->response_headers,
1519 SOUP_ENCODING_CONTENT_LENGTH);
1522 priv->msg_flags &= ~SOUP_MESSAGE_CONTENT_DECODED;
1524 msg->status_code = SOUP_STATUS_NONE;
1525 if (msg->reason_phrase) {
1526 g_free (msg->reason_phrase);
1527 msg->reason_phrase = NULL;
1529 priv->http_version = priv->orig_http_version;
1531 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_STATUS_CODE);
1532 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_REASON_PHRASE);
1533 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_HTTP_VERSION);
1534 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_FLAGS);
1535 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_TLS_CERTIFICATE);
1536 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_TLS_ERRORS);
1541 * @SOUP_MESSAGE_NO_REDIRECT: The session should not follow redirect
1542 * (3xx) responses received by this message.
1543 * @SOUP_MESSAGE_CAN_REBUILD: The caller will rebuild the request
1544 * body if the message is restarted; see
1545 * soup_message_body_set_accumulate() for more details.
1546 * @SOUP_MESSAGE_OVERWRITE_CHUNKS: Deprecated: equivalent to calling
1547 * soup_message_body_set_accumulate() on the incoming message body
1548 * (ie, #SoupMessage:response_body for a client-side request),
1550 * @SOUP_MESSAGE_CONTENT_DECODED: Set by #SoupContentDecoder to
1551 * indicate that it has removed the Content-Encoding on a message (and
1552 * so headers such as Content-Length may no longer accurately describe
1554 * @SOUP_MESSAGE_CERTIFICATE_TRUSTED: if set after an https response
1555 * has been received, indicates that the server's SSL certificate is
1556 * trusted according to the session's CA.
1557 * @SOUP_MESSAGE_NEW_CONNECTION: Requests that the message should be
1558 * sent on a newly-created connection, not reusing an existing
1559 * persistent connection. Note that messages with non-idempotent
1560 * #SoupMessage:method<!-- -->s behave this way by default, unless
1561 * #SOUP_MESSAGE_IDEMPOTENT is set.
1562 * @SOUP_MESSAGE_IDEMPOTENT: The message is considered idempotent,
1563 * regardless its #SoupMessage:method, and allows reuse of existing
1564 * idle connections, instead of always requiring a new one, unless
1565 * #SOUP_MESSAGE_NEW_CONNECTION is set.
1567 * Various flags that can be set on a #SoupMessage to alter its
1572 * soup_message_set_flags:
1573 * @msg: a #SoupMessage
1574 * @flags: a set of #SoupMessageFlags values
1576 * Sets the specified flags on @msg.
1579 soup_message_set_flags (SoupMessage *msg, SoupMessageFlags flags)
1581 SoupMessagePrivate *priv;
1583 g_return_if_fail (SOUP_IS_MESSAGE (msg));
1584 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1586 if ((priv->msg_flags ^ flags) & SOUP_MESSAGE_OVERWRITE_CHUNKS) {
1587 soup_message_body_set_accumulate (
1588 priv->server_side ? msg->request_body : msg->response_body,
1589 !(flags & SOUP_MESSAGE_OVERWRITE_CHUNKS));
1592 priv->msg_flags = flags;
1593 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_FLAGS);
1597 * soup_message_get_flags:
1598 * @msg: a #SoupMessage
1600 * Gets the flags on @msg
1602 * Return value: the flags
1605 soup_message_get_flags (SoupMessage *msg)
1607 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), 0);
1609 return SOUP_MESSAGE_GET_PRIVATE (msg)->msg_flags;
1614 * @SOUP_HTTP_1_0: HTTP 1.0 (RFC 1945)
1615 * @SOUP_HTTP_1_1: HTTP 1.1 (RFC 2616)
1617 * Indicates the HTTP protocol version being used.
1621 * soup_message_set_http_version:
1622 * @msg: a #SoupMessage
1623 * @version: the HTTP version
1625 * Sets the HTTP version on @msg. The default version is
1626 * %SOUP_HTTP_1_1. Setting it to %SOUP_HTTP_1_0 will prevent certain
1627 * functionality from being used.
1630 soup_message_set_http_version (SoupMessage *msg, SoupHTTPVersion version)
1632 SoupMessagePrivate *priv;
1634 g_return_if_fail (SOUP_IS_MESSAGE (msg));
1635 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1637 priv->http_version = version;
1638 if (msg->status_code == SOUP_STATUS_NONE)
1639 priv->orig_http_version = version;
1640 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_HTTP_VERSION);
1644 * soup_message_get_http_version:
1645 * @msg: a #SoupMessage
1647 * Gets the HTTP version of @msg. This is the minimum of the
1648 * version from the request and the version from the response.
1650 * Return value: the HTTP version
1653 soup_message_get_http_version (SoupMessage *msg)
1655 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), SOUP_HTTP_1_0);
1657 return SOUP_MESSAGE_GET_PRIVATE (msg)->http_version;
1661 * soup_message_is_keepalive:
1662 * @msg: a #SoupMessage
1664 * Determines whether or not @msg's connection can be kept alive for
1665 * further requests after processing @msg, based on the HTTP version,
1666 * Connection header, etc.
1668 * Return value: %TRUE or %FALSE.
1671 soup_message_is_keepalive (SoupMessage *msg)
1673 const char *c_conn, *s_conn;
1675 c_conn = soup_message_headers_get_list (msg->request_headers,
1677 s_conn = soup_message_headers_get_list (msg->response_headers,
1680 if (msg->status_code == SOUP_STATUS_OK &&
1681 msg->method == SOUP_METHOD_CONNECT)
1684 /* Not persistent if the server sent a terminate-by-EOF response */
1685 if (soup_message_headers_get_encoding (msg->response_headers) == SOUP_ENCODING_EOF)
1688 if (SOUP_MESSAGE_GET_PRIVATE (msg)->http_version == SOUP_HTTP_1_0) {
1689 /* In theory, HTTP/1.0 connections are only persistent
1690 * if the client requests it, and the server agrees.
1691 * But some servers do keep-alive even if the client
1692 * doesn't request it. So ignore c_conn.
1695 if (!s_conn || !soup_header_contains (s_conn, "Keep-Alive"))
1698 /* Normally persistent unless either side requested otherwise */
1699 if (c_conn && soup_header_contains (c_conn, "close"))
1701 if (s_conn && soup_header_contains (s_conn, "close"))
1711 * soup_message_set_uri:
1712 * @msg: a #SoupMessage
1713 * @uri: the new #SoupURI
1715 * Sets @msg's URI to @uri. If @msg has already been sent and you want
1716 * to re-send it with the new URI, you need to call
1717 * soup_session_requeue_message().
1720 soup_message_set_uri (SoupMessage *msg, SoupURI *uri)
1722 SoupMessagePrivate *priv;
1724 g_return_if_fail (SOUP_IS_MESSAGE (msg));
1725 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1728 soup_uri_free (priv->uri);
1730 g_object_unref (priv->addr);
1733 priv->uri = soup_uri_copy (uri);
1735 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_URI);
1739 * soup_message_get_uri:
1740 * @msg: a #SoupMessage
1744 * Return value: (transfer none): the URI @msg is targeted for.
1747 soup_message_get_uri (SoupMessage *msg)
1749 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), NULL);
1751 return SOUP_MESSAGE_GET_PRIVATE (msg)->uri;
1755 * soup_message_get_address:
1756 * @msg: a #SoupMessage
1758 * Gets the address @msg's URI points to. After first setting the
1759 * URI on a message, this will be unresolved, although the message's
1760 * session will resolve it before sending the message.
1762 * Return value: (transfer none): the address @msg's URI points to
1767 soup_message_get_address (SoupMessage *msg)
1769 SoupMessagePrivate *priv;
1771 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), NULL);
1773 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1775 priv->addr = soup_address_new (priv->uri->host,
1782 * soup_message_set_status:
1783 * @msg: a #SoupMessage
1784 * @status_code: an HTTP status code
1786 * Sets @msg's status code to @status_code. If @status_code is a
1787 * known value, it will also set @msg's reason_phrase.
1790 soup_message_set_status (SoupMessage *msg, guint status_code)
1792 g_return_if_fail (SOUP_IS_MESSAGE (msg));
1793 g_return_if_fail (status_code != 0);
1795 g_free (msg->reason_phrase);
1797 msg->status_code = status_code;
1798 msg->reason_phrase = g_strdup (soup_status_get_phrase (status_code));
1799 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_STATUS_CODE);
1800 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_REASON_PHRASE);
1804 * soup_message_set_status_full:
1805 * @msg: a #SoupMessage
1806 * @status_code: an HTTP status code
1807 * @reason_phrase: a description of the status
1809 * Sets @msg's status code and reason phrase.
1812 soup_message_set_status_full (SoupMessage *msg,
1814 const char *reason_phrase)
1816 g_return_if_fail (SOUP_IS_MESSAGE (msg));
1817 g_return_if_fail (status_code != 0);
1818 g_return_if_fail (reason_phrase != NULL);
1820 g_free (msg->reason_phrase);
1822 msg->status_code = status_code;
1823 msg->reason_phrase = g_strdup (reason_phrase);
1824 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_STATUS_CODE);
1825 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_REASON_PHRASE);
1829 * SoupChunkAllocator:
1830 * @msg: the #SoupMessage the chunk is being allocated for
1831 * @max_len: the maximum length that will be read, or 0.
1832 * @user_data: the data passed to soup_message_set_chunk_allocator()
1834 * The prototype for a chunk allocation callback. This should allocate
1835 * a new #SoupBuffer and return it for the I/O layer to read message
1836 * body data off the network into.
1838 * If @max_len is non-0, it indicates the maximum number of bytes that
1839 * could be read, based on what is known about the message size. Note
1840 * that this might be a very large number, and you should not simply
1841 * try to allocate that many bytes blindly. If @max_len is 0, that
1842 * means that libsoup does not know how many bytes remain to be read,
1843 * and the allocator should return a buffer of a size that it finds
1846 * If the allocator returns %NULL, the message will be paused. It is
1847 * up to the application to make sure that it gets unpaused when it
1848 * becomes possible to allocate a new buffer.
1850 * Return value: the new buffer (or %NULL)
1852 * Deprecated: Use #SoupRequest if you want to read into your
1857 * soup_message_set_chunk_allocator:
1858 * @msg: a #SoupMessage
1859 * @allocator: the chunk allocator callback
1860 * @user_data: data to pass to @allocator
1861 * @destroy_notify: destroy notifier to free @user_data when @msg is
1864 * Sets an alternate chunk-allocation function to use when reading
1865 * @msg's body when using the traditional (ie,
1866 * non-#SoupRequest<!-- -->-based) API. Every time data is available
1867 * to read, libsoup will call @allocator, which should return a
1868 * #SoupBuffer. (See #SoupChunkAllocator for additional details.)
1869 * Libsoup will then read data from the network into that buffer, and
1870 * update the buffer's <literal>length</literal> to indicate how much
1873 * Generally, a custom chunk allocator would be used in conjunction
1874 * with soup_message_body_set_accumulate() %FALSE and
1875 * #SoupMessage::got_chunk, as part of a strategy to avoid unnecessary
1876 * copying of data. However, you cannot assume that every call to the
1877 * allocator will be followed by a call to your
1878 * #SoupMessage::got_chunk handler; if an I/O error occurs, then the
1879 * buffer will be unreffed without ever having been used. If your
1880 * buffer-allocation strategy requires special cleanup, use
1881 * soup_buffer_new_with_owner() rather than doing the cleanup from the
1882 * #SoupMessage::got_chunk handler.
1884 * The other thing to remember when using non-accumulating message
1885 * bodies is that the buffer passed to the #SoupMessage::got_chunk
1886 * handler will be unreffed after the handler returns, just as it
1887 * would be in the non-custom-allocated case. If you want to hand the
1888 * chunk data off to some other part of your program to use later,
1889 * you'll need to ref the #SoupBuffer (or its owner, in the
1890 * soup_buffer_new_with_owner() case) to ensure that the data remains
1893 * Deprecated: #SoupRequest provides a much simpler API that lets you
1894 * read the response directly into your own buffers without needing to
1895 * mess with callbacks, pausing/unpausing, etc.
1898 soup_message_set_chunk_allocator (SoupMessage *msg,
1899 SoupChunkAllocator allocator,
1901 GDestroyNotify destroy_notify)
1903 SoupMessagePrivate *priv;
1905 g_return_if_fail (SOUP_IS_MESSAGE (msg));
1907 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1909 if (priv->chunk_allocator_dnotify)
1910 priv->chunk_allocator_dnotify (priv->chunk_allocator_data);
1912 priv->chunk_allocator = allocator;
1913 priv->chunk_allocator_data = user_data;
1914 priv->chunk_allocator_dnotify = destroy_notify;
1918 * soup_message_disable_feature:
1919 * @msg: a #SoupMessage
1920 * @feature_type: the #GType of a #SoupSessionFeature
1922 * This disables the actions of #SoupSessionFeature<!-- -->s with the
1923 * given @feature_type (or a subclass of that type) on @msg, so that
1924 * @msg is processed as though the feature(s) hadn't been added to the
1925 * session. Eg, passing #SOUP_TYPE_CONTENT_SNIFFER for @feature_type
1926 * will disable Content-Type sniffing on the message.
1928 * You must call this before queueing @msg on a session; calling it on
1929 * a message that has already been queued is undefined. In particular,
1930 * you cannot call this on a message that is being requeued after a
1931 * redirect or authentication.
1936 soup_message_disable_feature (SoupMessage *msg, GType feature_type)
1938 SoupMessagePrivate *priv;
1940 g_return_if_fail (SOUP_IS_MESSAGE (msg));
1942 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1944 priv->disabled_features = g_slist_prepend (priv->disabled_features,
1945 GSIZE_TO_POINTER (feature_type));
1949 soup_message_disables_feature (SoupMessage *msg, gpointer feature)
1951 SoupMessagePrivate *priv;
1954 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), FALSE);
1956 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1958 for (f = priv->disabled_features; f; f = f->next) {
1959 if (G_TYPE_CHECK_INSTANCE_TYPE (feature, (GType) GPOINTER_TO_SIZE (f->data)))
1966 * soup_message_get_first_party:
1967 * @msg: a #SoupMessage
1969 * Gets @msg's first-party #SoupURI
1971 * Returns: (transfer none): the @msg's first party #SoupURI
1976 soup_message_get_first_party (SoupMessage *msg)
1978 SoupMessagePrivate *priv;
1980 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), NULL);
1982 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
1983 return priv->first_party;
1987 * soup_message_set_first_party:
1988 * @msg: a #SoupMessage
1989 * @first_party: the #SoupURI for the @msg's first party
1991 * Sets @first_party as the main document #SoupURI for @msg. For
1992 * details of when and how this is used refer to the documentation for
1993 * #SoupCookieJarAcceptPolicy.
1998 soup_message_set_first_party (SoupMessage *msg,
1999 SoupURI *first_party)
2001 SoupMessagePrivate *priv;
2003 g_return_if_fail (SOUP_IS_MESSAGE (msg));
2004 g_return_if_fail (first_party != NULL);
2006 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
2008 if (priv->first_party) {
2009 if (soup_uri_equal (priv->first_party, first_party))
2012 soup_uri_free (priv->first_party);
2015 priv->first_party = soup_uri_copy (first_party);
2016 g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_FIRST_PARTY);
2020 soup_message_set_https_status (SoupMessage *msg, SoupConnection *conn)
2024 sock = conn ? soup_connection_get_socket (conn) : NULL;
2025 if (sock && soup_socket_is_ssl (sock)) {
2026 GTlsCertificate *certificate;
2027 GTlsCertificateFlags errors;
2030 SOUP_SOCKET_TLS_CERTIFICATE, &certificate,
2031 SOUP_SOCKET_TLS_ERRORS, &errors,
2034 #if ENABLE(TIZEN_CERTIFICATE_FILE_SET)
2035 if (errors && soup_message_is_from_session_restore (msg)) {
2036 TIZEN_LOGD ("msg[%p] errors[%d]", msg, errors);
2038 TIZEN_LOGD ("msg[%p] changed errors[%d]", msg, errors);
2043 SOUP_MESSAGE_TLS_CERTIFICATE, certificate,
2044 SOUP_MESSAGE_TLS_ERRORS, errors,
2047 g_object_unref (certificate);
2050 SOUP_MESSAGE_TLS_CERTIFICATE, NULL,
2051 SOUP_MESSAGE_TLS_ERRORS, 0,
2057 * soup_message_get_https_status:
2058 * @msg: a #SoupMessage
2059 * @certificate: (out) (transfer none): @msg's TLS certificate
2060 * @errors: (out): the verification status of @certificate
2062 * If @msg is using https (or attempted to use https but got
2063 * %SOUP_STATUS_SSL_FAILED), this retrieves the #GTlsCertificate
2064 * associated with its connection, and the #GTlsCertificateFlags
2065 * showing what problems, if any, have been found with that
2068 * Return value: %TRUE if @msg used/attempted https, %FALSE if not
2073 soup_message_get_https_status (SoupMessage *msg,
2074 GTlsCertificate **certificate,
2075 GTlsCertificateFlags *errors)
2077 SoupMessagePrivate *priv;
2079 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), FALSE);
2081 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
2084 *certificate = priv->tls_certificate;
2086 *errors = priv->tls_errors;
2087 return priv->tls_certificate != NULL;
2091 * soup_message_set_redirect:
2092 * @msg: a #SoupMessage
2093 * @status_code: a 3xx status code
2094 * @redirect_uri: the URI to redirect @msg to
2096 * Sets @msg's status_code to @status_code and adds a Location header
2097 * pointing to @redirect_uri. Use this from a #SoupServer when you
2098 * want to redirect the client to another URI.
2100 * @redirect_uri can be a relative URI, in which case it is
2101 * interpreted relative to @msg's current URI. In particular, if
2102 * @redirect_uri is just a path, it will replace the path
2103 * <emphasis>and query</emphasis> of @msg's URI.
2108 soup_message_set_redirect (SoupMessage *msg, guint status_code,
2109 const char *redirect_uri)
2114 location = soup_uri_new_with_base (soup_message_get_uri (msg), redirect_uri);
2115 g_return_if_fail (location != NULL);
2117 soup_message_set_status (msg, status_code);
2118 location_str = soup_uri_to_string (location, FALSE);
2119 soup_message_headers_replace (msg->response_headers, "Location",
2121 g_free (location_str);
2122 soup_uri_free (location);
2126 soup_message_set_soup_request (SoupMessage *msg,
2129 SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg);
2131 priv->request = req;
2135 * soup_message_get_soup_request:
2136 * @msg: a #SoupMessage
2138 * If @msg is associated with a #SoupRequest, this returns that
2139 * request. Otherwise it returns %NULL.
2141 * Return value: (transfer none): @msg's associated #SoupRequest
2146 soup_message_get_soup_request (SoupMessage *msg)
2148 SoupMessagePrivate *priv;
2150 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), NULL);
2152 priv = SOUP_MESSAGE_GET_PRIVATE (msg);
2153 return priv->request;
2157 * SoupMessagePriority:
2158 * @SOUP_MESSAGE_PRIORITY_VERY_LOW: The lowest priority, the messages
2159 * with this priority will be the last ones to be attended.
2160 * @SOUP_MESSAGE_PRIORITY_LOW: Use this for low priority messages, a
2161 * #SoupMessage with the default priority will be processed first.
2162 * @SOUP_MESSAGE_PRIORITY_NORMAL: The default priotity, this is the
2163 * priority assigned to the #SoupMessage by default.
2164 * @SOUP_MESSAGE_PRIORITY_HIGH: High priority, a #SoupMessage with
2165 * this priority will be processed before the ones with the default
2167 * @SOUP_MESSAGE_PRIORITY_VERY_HIGH: The highest priority, use this
2168 * for very urgent #SoupMessage as they will be the first ones to be
2171 * Priorities that can be set on a #SoupMessage to instruct the
2172 * message queue to process it before any other message with lower
2177 * soup_message_set_priority:
2178 * @msg: a #SoupMessage
2179 * @priority: the #SoupMessagePriority
2181 * Sets the priority of a message. Note that this won't have any
2182 * effect unless used before the message is added to the session's
2183 * message processing queue.
2185 * The message will be placed just before any other previously added
2186 * message with lower priority (messages with the same priority are
2187 * processed on a FIFO basis).
2189 * Setting priorities does not currently work with #SoupSessionSync
2190 * (or with synchronous messages on a plain #SoupSession) because in
2191 * the synchronous/blocking case, priority ends up being determined
2192 * semi-randomly by thread scheduling.
2197 soup_message_set_priority (SoupMessage *msg,
2198 SoupMessagePriority priority)
2200 g_return_if_fail (SOUP_IS_MESSAGE (msg));
2202 g_object_set (msg, SOUP_MESSAGE_PRIORITY, priority, NULL);
2206 * soup_message_get_priority:
2207 * @msg: a #SoupMessage
2209 * Retrieves the #SoupMessagePriority. If not set this value defaults
2210 * to #SOUP_MESSAGE_PRIORITY_NORMAL.
2212 * Return value: the priority of the message.
2217 soup_message_get_priority (SoupMessage *msg)
2219 g_return_val_if_fail (SOUP_IS_MESSAGE (msg), SOUP_MESSAGE_PRIORITY_NORMAL);
2221 return SOUP_MESSAGE_GET_PRIVATE (msg)->priority;
2224 #if ENABLE(TIZEN_CERTIFICATE_FILE_SET)
2225 gboolean soup_message_is_from_session_restore (SoupMessage *msg)
2227 char *target_field = "Cache-Control";
2228 char *target_value = "max-stale=86400";
2229 const char *value = NULL;
2234 // This criteria to decide session restore can be changed according to WebKit.
2235 value = soup_message_headers_get_one (msg->request_headers, target_field);
2236 if (value && !strcmp (value, target_value)) {
2237 TIZEN_LOGD ("msg[%p] return TRUE", msg);