diff options
author | Dan Winship <danw@gnome.org> | 2012-07-14 09:24:29 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2012-12-10 17:14:57 +0100 |
commit | fea7925589f6b768252b07c9df8f44ee70bca032 (patch) | |
tree | e2e8c3ce66d3cf5c137dccb499d4d8f922e116f1 /libsoup | |
parent | e00cf242322f82f0800956b17d726f0437db683a (diff) | |
download | libsoup-fea7925589f6b768252b07c9df8f44ee70bca032.tar.gz |
SoupRequest: Return better GErrors on parsing failures
In cases where the SoupMessage API would return SOUP_STATUS_MALFORMED,
return a clearer GError in the SoupRequest API.
Diffstat (limited to 'libsoup')
-rw-r--r-- | libsoup/soup-message-client-io.c | 17 | ||||
-rw-r--r-- | libsoup/soup-message-io.c | 2 | ||||
-rw-r--r-- | libsoup/soup-message-private.h | 3 | ||||
-rw-r--r-- | libsoup/soup-message-server-io.c | 12 | ||||
-rw-r--r-- | libsoup/soup-session.c | 4 | ||||
-rw-r--r-- | libsoup/soup-session.h | 4 |
6 files changed, 34 insertions, 8 deletions
diff --git a/libsoup/soup-message-client-io.c b/libsoup/soup-message-client-io.c index 06fe5cc6..1ee4cbb2 100644 --- a/libsoup/soup-message-client-io.c +++ b/libsoup/soup-message-client-io.c @@ -11,6 +11,8 @@ #include <string.h> +#include <glib/gi18n-lib.h> + #include "soup.h" #include "soup-connection.h" #include "soup-message-private.h" @@ -21,7 +23,8 @@ static guint parse_response_headers (SoupMessage *req, char *headers, guint headers_len, SoupEncoding *encoding, - gpointer user_data) + gpointer user_data, + GError **error) { SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (req); SoupHTTPVersion version; @@ -32,8 +35,12 @@ parse_response_headers (SoupMessage *req, req->response_headers, &version, &req->status_code, - &req->reason_phrase)) + &req->reason_phrase)) { + g_set_error_literal (error, SOUP_REQUEST_ERROR, + SOUP_REQUEST_ERROR_PARSING, + _("Could not parse HTTP response")); return SOUP_STATUS_MALFORMED; + } g_object_notify (G_OBJECT (req), SOUP_MESSAGE_STATUS_CODE); g_object_notify (G_OBJECT (req), SOUP_MESSAGE_REASON_PHRASE); @@ -53,8 +60,12 @@ parse_response_headers (SoupMessage *req, else *encoding = soup_message_headers_get_encoding (req->response_headers); - if (*encoding == SOUP_ENCODING_UNRECOGNIZED) + if (*encoding == SOUP_ENCODING_UNRECOGNIZED) { + g_set_error_literal (error, SOUP_REQUEST_ERROR, + SOUP_REQUEST_ERROR_ENCODING, + _("Unrecognized HTTP response encoding")); return SOUP_STATUS_MALFORMED; + } return SOUP_STATUS_OK; } diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c index d38d7432..03f8c0a1 100644 --- a/libsoup/soup-message-io.c +++ b/libsoup/soup-message-io.c @@ -503,7 +503,7 @@ io_read (SoupMessage *msg, GCancellable *cancellable, GError **error) status = io->parse_headers_cb (msg, (char *)io->read_header_buf->data, io->read_header_buf->len, &io->read_encoding, - io->header_data); + io->header_data, error); g_byte_array_set_size (io->read_header_buf, 0); if (status != SOUP_STATUS_OK) { diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h index 86650077..f688515a 100644 --- a/libsoup/soup-message-private.h +++ b/libsoup/soup-message-private.h @@ -52,7 +52,8 @@ typedef guint (*SoupMessageParseHeadersFn)(SoupMessage *msg, char *headers, guint header_len, SoupEncoding *encoding, - gpointer user_data); + gpointer user_data, + GError **error); typedef void (*SoupMessageCompletionFn) (SoupMessage *msg, gpointer user_data); diff --git a/libsoup/soup-message-server-io.c b/libsoup/soup-message-server-io.c index a53e5b7b..e85896b3 100644 --- a/libsoup/soup-message-server-io.c +++ b/libsoup/soup-message-server-io.c @@ -11,13 +11,15 @@ #include <string.h> +#include <glib/gi18n-lib.h> + #include "soup.h" #include "soup-message-private.h" #include "soup-misc-private.h" static guint parse_request_headers (SoupMessage *msg, char *headers, guint headers_len, - SoupEncoding *encoding, gpointer sock) + SoupEncoding *encoding, gpointer sock, GError **error) { SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg); char *req_method, *req_path, *url; @@ -31,8 +33,14 @@ parse_request_headers (SoupMessage *msg, char *headers, guint headers_len, &req_method, &req_path, &version); - if (!SOUP_STATUS_IS_SUCCESSFUL (status)) + if (!SOUP_STATUS_IS_SUCCESSFUL (status)) { + if (status == SOUP_STATUS_MALFORMED) { + g_set_error_literal (error, SOUP_REQUEST_ERROR, + SOUP_REQUEST_ERROR_PARSING, + _("Could not parse HTTP request")); + } return status; + } g_object_set (G_OBJECT (msg), SOUP_MESSAGE_METHOD, req_method, diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c index 20d1c062..85d705a6 100644 --- a/libsoup/soup-session.c +++ b/libsoup/soup-session.c @@ -3816,6 +3816,10 @@ soup_session_request_uri (SoupSession *session, SoupURI *uri, * @SOUP_REQUEST_ERROR_BAD_URI: the URI could not be parsed * @SOUP_REQUEST_ERROR_UNSUPPORTED_URI_SCHEME: the URI scheme is not * supported by this #SoupSession + * @SOUP_REQUEST_ERROR_PARSING: the server's response could not + * be parsed + * @SOUP_REQUEST_ERROR_ENCODING: the server's response was in an + * unsupported format * * A #SoupRequest error. * diff --git a/libsoup/soup-session.h b/libsoup/soup-session.h index acc12a9a..03908625 100644 --- a/libsoup/soup-session.h +++ b/libsoup/soup-session.h @@ -163,7 +163,9 @@ GQuark soup_request_error_quark (void); typedef enum { SOUP_REQUEST_ERROR_BAD_URI, - SOUP_REQUEST_ERROR_UNSUPPORTED_URI_SCHEME + SOUP_REQUEST_ERROR_UNSUPPORTED_URI_SCHEME, + SOUP_REQUEST_ERROR_PARSING, + SOUP_REQUEST_ERROR_ENCODING } SoupRequestError; G_END_DECLS |