summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gweb/gweb.c15
-rw-r--r--gweb/gweb.h2
2 files changed, 17 insertions, 0 deletions
diff --git a/gweb/gweb.c b/gweb/gweb.c
index 1add7106..bfeecc87 100644
--- a/gweb/gweb.c
+++ b/gweb/gweb.c
@@ -41,6 +41,7 @@
#define SESSION_FLAG_USE_TLS (1 << 0)
struct _GWebResult {
+ guint status;
const guint8 *buffer;
gsize length;
};
@@ -340,6 +341,7 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
while (str != NULL) {
char *start = session->current_line;
+ unsigned int code;
*str = '\0';
count = strlen(start);
@@ -362,6 +364,11 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
//printf("[ %s ]\n", start);
+ if (session->result.status == 0) {
+ if (sscanf(start, "HTTP/%*s %u %*s", &code) == 1)
+ session->result.status = code;
+ }
+
str = memchr(session->current_line, '\n',
bytes_read - consumed);
}
@@ -628,6 +635,14 @@ guint g_web_request(GWeb *web, GWebMethod method, const char *url,
return web->next_query_id++;
}
+guint16 g_web_result_get_status(GWebResult *result)
+{
+ if (result == NULL)
+ return 0;
+
+ return result->status;
+}
+
gboolean g_web_result_get_chunk(GWebResult *result,
const guint8 **chunk, gsize *length)
{
diff --git a/gweb/gweb.h b/gweb/gweb.h
index daeb262d..24c84a03 100644
--- a/gweb/gweb.h
+++ b/gweb/gweb.h
@@ -67,6 +67,8 @@ guint g_web_request(GWeb *web, GWebMethod method, const char *url,
gboolean g_web_cancel(GWeb *web, guint id);
+guint16 g_web_result_get_status(GWebResult *result);
+
gboolean g_web_result_get_chunk(GWebResult *result,
const guint8 **chunk, gsize *length);