$OpenBSD: patch-modules_http-neon-method_c,v 1.2 2008/06/23 12:20:16 deanna Exp $
--- modules/http-neon-method.c.orig	Mon Nov 12 03:36:43 2007
+++ modules/http-neon-method.c	Sat Jun 21 17:58:39 2008
@@ -1188,7 +1188,7 @@ propfind_result (void *userdata, const char *href, con
 	time_t	time;
 	gulong  size;
 	ne_uri  uri;
-	char *unesc_path;
+	char *unesc_path, *unesc_ctx_path;
 
 	ctx = (PropfindContext *) userdata;
 
@@ -1205,10 +1205,10 @@ propfind_result (void *userdata, const char *href, con
 	info = gnome_vfs_file_info_new ();
 	unesc_path = ne_path_unescape (uri.path);
 	info->name = g_path_get_basename (unesc_path);
-	NE_FREE (unesc_path);
 
+	unesc_ctx_path = ne_path_unescape (ctx->path);
 	DEBUG_HTTP_2 ("Comparing: \n\t[%s] \n\t[%s]", ctx->path, uri.path);
-	if (ne_path_compare (ctx->path, uri.path) == 0) {
+	if (ne_path_compare (unesc_ctx_path, unesc_path) == 0) {
 		DEBUG_HTTP_3 ("target");
 		ctx->target = info;
 
@@ -1225,6 +1225,8 @@ propfind_result (void *userdata, const char *href, con
 		ctx->children = g_list_append (ctx->children, info);
 	}
 
+	NE_FREE (unesc_ctx_path);
+	NE_FREE (unesc_path);
 	ne_uri_free (&uri);
 
 	/* getlastmodified */
@@ -1771,6 +1773,25 @@ http_context_open (GnomeVFSURI *uri, HttpContext **con
 	return GNOME_VFS_OK;
 }
 
+static gboolean
+http_context_host_matches (HttpContext *context, const char *glob)
+{
+	GnomeVFSToplevelURI *uri;
+	GPatternSpec *spec;
+	gboolean res;
+
+	uri = gnome_vfs_uri_get_toplevel (context->uri);
+
+	if (uri == NULL ||  uri->host_name == NULL || glob == NULL)
+		return FALSE;
+
+	spec = g_pattern_spec_new (glob);
+	res = g_pattern_match_string (spec, uri->host_name);
+	g_pattern_spec_free (spec);
+
+	return res;
+}
+
 static GnomeVFSResult
 http_follow_redirect (HttpContext *context)
 {
@@ -2345,6 +2366,20 @@ http_transfer_start (HttpFileHandle *handle)
 	return GNOME_VFS_ERROR_INTERNAL;
 }
 
+/* TRUE means we can range, ie server is sane, FALSE means FAIL */
+static gboolean
+i_can_haz_range_cause_serverz_not_br0ken (HttpContext *hctx)
+{
+	gboolean br0ken = FALSE;
+
+	if (http_context_host_matches (hctx, "*youtube.*")) {
+		DEBUG_HTTP ("Youtube detected! Cannot use ranged gets");
+		br0ken = TRUE;
+	}
+
+	return br0ken == FALSE;
+}
+
 /* ************************************************************************** */
 
 static GnomeVFSResult
@@ -2400,19 +2435,12 @@ do_open (GnomeVFSMethod 	*method,
 			return result;
 		} 
 	} else {
-		handle->use_range = (mode & GNOME_VFS_OPEN_RANDOM);
+		handle->use_range = i_can_haz_range_cause_serverz_not_br0ken (hctx);
+		DEBUG_HTTP ("Use range: %s\n", handle->use_range ? "on" : "off");
 	}
 
 	result = http_transfer_start (handle);	
 
-	if (result == GNOME_VFS_OK && mode & GNOME_VFS_OPEN_READ) {
-		
-		if (handle->use_range && ! handle->can_range) {
-			/*Review: Not supported or invalid open mode ? */
-			result = GNOME_VFS_ERROR_NOT_SUPPORTED;
-		}	
-	} 
-		
 	if (result != GNOME_VFS_OK) {
 		http_file_handle_destroy (handle);
 		handle = NULL;
