Git development
 help / color / mirror / Atom feed
From: Nick Hengeveld <nickh@reactrix.com>
To: git@vger.kernel.org
Subject: Re: Cloning from sites with 404 overridden
Date: Wed, 22 Mar 2006 10:36:21 -0800	[thread overview]
Message-ID: <20060322183621.GP3997@reactrix.com> (raw)
In-Reply-To: <20060322172227.GO3997@reactrix.com>

On Wed, Mar 22, 2006 at 09:22:27AM -0800, Nick Hengeveld wrote:

> It might be feasible to detect this condition using the Content-Type:
> header in the server response.  So far, all the GIT repositories I've
> tried return text/plain for loose objects and a special 404 page will
> likely be text/html.

Something like this:

http_fetch: report text/html responses for loose objects

Some HTTP server environments return a 200 status and text/html error
document or a redirect to one rather than a 404 status if a loose
object does not exist.  This patch detects and reports this condition
to differentiate between a misconfigured server and an actual corrupt
object on the server.

Signed-off-by: Nick Hengeveld <nickh@reactrix.com>


---

 http-fetch.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

61069cc348640fef2b8c503b8b8f00f689872cab
diff --git a/http-fetch.c b/http-fetch.c
index dc67218..ee5b585 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -41,6 +41,7 @@ struct object_request
 	CURLcode curl_result;
 	char errorstr[CURL_ERROR_SIZE];
 	long http_code;
+	char *content_type;
 	unsigned char real_sha1[20];
 	SHA_CTX c;
 	z_stream stream;
@@ -258,9 +259,15 @@ static void finish_object_request(struct
 
 static void process_object_response(void *callback_data)
 {
+	char *content_type;
 	struct object_request *obj_req =
 		(struct object_request *)callback_data;
 
+	curl_easy_getinfo(obj_req->slot->curl, CURLINFO_CONTENT_TYPE,
+			  &content_type);
+	if (content_type)
+		obj_req->content_type = strdup(content_type);
+
 	obj_req->curl_result = obj_req->slot->curl_result;
 	obj_req->http_code = obj_req->slot->http_code;
 	obj_req->slot = NULL;
@@ -298,6 +305,8 @@ static void release_object_request(struc
 			entry->next = entry->next->next;
 	}
 
+	if (obj_req->content_type)
+		free(obj_req->content_type);
 	free(obj_req->url);
 	free(obj_req);
 }
@@ -340,6 +349,7 @@ void prefetch(unsigned char *sha1)
 	memcpy(newreq->sha1, sha1, 20);
 	newreq->repo = alt;
 	newreq->url = NULL;
+	newreq->content_type = NULL;
 	newreq->local = -1;
 	newreq->state = WAITING;
 	snprintf(newreq->filename, sizeof(newreq->filename), "%s", filename);
@@ -836,7 +846,14 @@ static int fetch_object(struct alt_base 
 				    obj_req->http_code, hex);
 	} else if (obj_req->zret != Z_STREAM_END) {
 		corrupt_object_found++;
-		ret = error("File %s (%s) corrupt", hex, obj_req->url);
+		if (obj_req->content_type &&
+		    !strcmp(obj_req->content_type, "text/html")) {
+			ret = error("text/html response for file %s (%s)",
+				    sha1_to_hex(obj_req->sha1), obj_req->url);
+		} else {
+			ret = error("File %s (%s) corrupt",
+				    sha1_to_hex(obj_req->sha1), obj_req->url);
+		}
 	} else if (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) {
 		ret = error("File %s has bad hash", hex);
 	} else if (obj_req->rename < 0) {
-- 
1.2.4.gb1bc1d-dirty

  reply	other threads:[~2006-03-22 18:36 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-22  2:59 Cloning from sites with 404 overridden linux
2006-03-22  3:12 ` Shawn Pearce
2006-03-22  4:13   ` Linus Torvalds
2006-03-22  6:06 ` Marco Costalba
2006-03-22  6:47   ` Junio C Hamano
2006-03-22 13:36 ` Andreas Ericsson
2006-03-24 17:29   ` Mark Wooding
2006-03-24 17:52     ` Junio C Hamano
2006-03-24 17:53     ` Linus Torvalds
2006-03-24 18:16     ` Morten Welinder
2006-03-24 18:40     ` Andreas Ericsson
2006-03-22 17:22 ` Nick Hengeveld
2006-03-22 18:36   ` Nick Hengeveld [this message]
2006-03-22 19:05     ` Junio C Hamano
2006-03-22 19:22       ` Junio C Hamano
2006-03-23 18:43         ` Nick Hengeveld
2006-03-23 20:45           ` Junio C Hamano
2006-03-22 21:24       ` Radoslaw Szkodzinski
  -- strict thread matches above, loose matches on Subject: below --
2006-03-19 10:52 Marco Costalba
2006-03-19 13:25 ` Paolo Ciarrocchi
2006-03-19 14:04   ` Marco Costalba
2006-03-19 19:37     ` Junio C Hamano
2006-03-19 21:40       ` Marco Costalba
2006-03-19 23:21         ` Junio C Hamano
2006-03-20  6:31           ` Marco Costalba
2006-03-20  8:44             ` Junio C Hamano
2006-03-20 12:17               ` Marco Costalba
2006-03-20 18:29       ` Lukas Sandström
2006-03-20 19:43         ` Petr Baudis
2006-03-20 19:54         ` Nick Hengeveld
2006-03-19 19:47     ` Junio C Hamano
2006-03-19 21:31       ` Petr Baudis
2006-03-19 21:43         ` Petr Baudis
2006-03-19 21:45         ` Marco Costalba
2006-03-20  4:32       ` Randal L. Schwartz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060322183621.GP3997@reactrix.com \
    --to=nickh@reactrix.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox