Index: protocols/twitter/twitter.h
===================================================================
--- protocols/twitter/twitter.h	(revision 9e8c945b0c0e794fdc33413ad87feb4606a07981)
+++ protocols/twitter/twitter.h	(revision ddc2de54664ec25b95bbce997fbbb6a7104f1203)
@@ -57,4 +57,5 @@
 	guint64 last_status_id; /* For undo */
 	gint main_loop_id;
+	struct http_request *stream;
 	struct groupchat *timeline_gc;
 	gint http_fails;
Index: protocols/twitter/twitter_http.c
===================================================================
--- protocols/twitter/twitter_http.c	(revision 9e8c945b0c0e794fdc33413ad87feb4606a07981)
+++ protocols/twitter/twitter_http.c	(revision ddc2de54664ec25b95bbce997fbbb6a7104f1203)
@@ -47,6 +47,6 @@
  * This is actually pretty generic function... Perhaps it should move to the lib/http_client.c
  */
-void *twitter_http(struct im_connection *ic, char *url_string, http_input_function func,
-		   gpointer data, int is_post, char **arguments, int arguments_len)
+struct http_request *twitter_http(struct im_connection *ic, char *url_string, http_input_function func,
+		                  gpointer data, int is_post, char **arguments, int arguments_len)
 {
 	struct twitter_data *td = ic->proto_data;
@@ -55,4 +55,5 @@
 	void *ret;
 	char *url_arguments;
+	url_t *base_url = NULL;
 
 	url_arguments = g_strdup("");
@@ -67,4 +68,13 @@
 		}
 	}
+	
+	if (strstr(url_string, "://")) {
+		base_url = g_new0(url_t, 1);
+		if (!url_set(base_url, url_string)) {
+			g_free(base_url);
+			return NULL;
+		}
+	}
+	
 	// Make the request.
 	g_string_printf(request, "%s %s%s%s%s HTTP/1.0\r\n"
@@ -72,6 +82,8 @@
 			"User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n",
 			is_post ? "POST" : "GET",
-			td->url_path, url_string,
-			is_post ? "" : "?", is_post ? "" : url_arguments, td->url_host);
+			base_url ? base_url->file : td->url_path,
+			base_url ? "" : url_string,
+			is_post ? "" : "?", is_post ? "" : url_arguments,
+			base_url ? base_url->host : td->url_host);
 
 	// If a pass and user are given we append them to the request.
@@ -80,5 +92,8 @@
 		char *full_url;
 
-		full_url = g_strconcat(set_getstr(&ic->acc->set, "base_url"), url_string, NULL);
+		if (base_url)
+			full_url = g_strdup(url_string);
+		else
+			full_url = g_strconcat(set_getstr(&ic->acc->set, "base_url"), url_string, NULL);
 		full_header = oauth_http_header(td->oauth_info, is_post ? "POST" : "GET",
 						full_url, url_arguments);
@@ -109,8 +124,12 @@
 	}
 
-	ret = http_dorequest(td->url_host, td->url_port, td->url_ssl, request->str, func, data);
+	if (base_url)
+		ret = http_dorequest(base_url->host, base_url->port, base_url->proto == PROTO_HTTPS, request->str, func, data);
+	else
+		ret = http_dorequest(td->url_host, td->url_port, td->url_ssl, request->str, func, data);
 
 	g_free(url_arguments);
 	g_string_free(request, TRUE);
+	g_free(base_url);
 	return ret;
 }
Index: protocols/twitter/twitter_http.h
===================================================================
--- protocols/twitter/twitter_http.h	(revision 9e8c945b0c0e794fdc33413ad87feb4606a07981)
+++ protocols/twitter/twitter_http.h	(revision ddc2de54664ec25b95bbce997fbbb6a7104f1203)
@@ -30,6 +30,6 @@
 struct oauth_info;
 
-void *twitter_http(struct im_connection *ic, char *url_string, http_input_function func,
-                   gpointer data, int is_post, char** arguments, int arguments_len);
+struct http_request *twitter_http(struct im_connection *ic, char *url_string, http_input_function func,
+                                  gpointer data, int is_post, char** arguments, int arguments_len);
 
 #endif //_TWITTER_HTTP_H
Index: protocols/twitter/twitter_lib.c
===================================================================
--- protocols/twitter/twitter_lib.c	(revision 9e8c945b0c0e794fdc33413ad87feb4606a07981)
+++ protocols/twitter/twitter_lib.c	(revision ddc2de54664ec25b95bbce997fbbb6a7104f1203)
@@ -727,6 +727,46 @@
 }
 
-static void twitter_http_get_home_timeline(struct http_request *req);
-static void twitter_http_get_mentions(struct http_request *req);
+static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor);
+static void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor);
+
+static void twitter_http_stream(struct http_request *req)
+{
+	int len;
+	int i;
+	char c;
+	json_value *j;
+	
+	printf( "%d bytes in stream\n", req->body_size );
+	
+	/* m/^[\d\s]*/      /* why is there a second commend here? :-) */
+	for (i = 0; i < req->body_size; i ++) {
+		if (!isspace(req->reply_body[i]) && !isdigit(req->reply_body[i]))
+			break;
+	}
+	
+	/* Nothing but numbers and whitespace in there. Try again later. */
+	if (i == req->body_size)
+		return;
+	
+	/* Get length. */
+	if (sscanf(req->reply_body, "%d", &len) != 1)
+		return;
+	
+	if (req->body_size < i + len) {
+		printf("Not enough bytes in buffer yet\n");
+		return;
+	}
+	
+	http_flush_bytes(req, i);
+	c = req->reply_body[len];
+	req->reply_body[len] = '\0';
+	
+	printf("JSON: %s\n", req->reply_body);
+	printf("parsed: %p\n", (j = json_parse(req->reply_body)));
+	json_value_free(j);
+	req->reply_body[len] = c;
+	
+	http_flush_bytes(req, len);
+}
 
 /**
@@ -751,4 +791,21 @@
 	if (include_mentions) {
 		twitter_get_mentions(ic, next_cursor);
+	}
+	
+	static int bla = 0;
+	
+	if (bla)
+		return;
+	bla = 1;
+	
+	char *args[4];
+	args[0] = "with";
+	args[1] = "followings";
+	args[2] = "delimited";
+	args[3] = "length";
+	
+	if ((td->stream = twitter_http(ic, "https://userstream.twitter.com/1.1/user.json",
+	                               twitter_http_stream, ic, 0, args, 4))) {
+		td->stream->flags |= HTTPC_STREAMING;
 	}
 }
@@ -810,8 +867,11 @@
 }
 
+static void twitter_http_get_home_timeline(struct http_request *req);
+static void twitter_http_get_mentions(struct http_request *req);
+
 /**
  * Get the timeline.
  */
-void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor)
+static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor)
 {
 	struct twitter_data *td = ic->proto_data;
@@ -849,5 +909,5 @@
  * Get mentions.
  */
-void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor)
+static void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor)
 {
 	struct twitter_data *td = ic->proto_data;
Index: protocols/twitter/twitter_lib.h
===================================================================
--- protocols/twitter/twitter_lib.h	(revision 9e8c945b0c0e794fdc33413ad87feb4606a07981)
+++ protocols/twitter/twitter_lib.h	(revision ddc2de54664ec25b95bbce997fbbb6a7104f1203)
@@ -81,6 +81,4 @@
 void twitter_get_timeline(struct im_connection *ic, gint64 next_cursor);
 void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor);
-void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor);
-void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor);
 void twitter_get_statuses_friends(struct im_connection *ic, gint64 next_cursor);
 
