git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Cloning from sites with 404 overridden

From
NHNick Hengeveld <nickh@reactrix.com>
Date
Mar 22, 2006, 18:36 UTC
Message-ID
<20060322183621.GP3997@reactrix.com>
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
Previous: Nick HengeveldNext: Junio C Hamano
Message 13 of 18 in “Re: Cloning from sites with 404 overridden”
  1. linux@horizon.comMar 22, 2006
  2. Shawn PearceMar 22, 2006
  3. Linus TorvaldsMar 22, 2006
  4. Marco CostalbaMar 22, 2006
  5. Junio C HamanoMar 22, 2006
  6. Andreas EricssonMar 22, 2006
  7. Mark WoodingMar 24, 2006
  8. Junio C HamanoMar 24, 2006
  9. Linus TorvaldsMar 24, 2006
  10. Morten WelinderMar 24, 2006
  11. Andreas EricssonMar 24, 2006
  12. Nick HengeveldMar 22, 2006
  13. Nick HengeveldMar 22, 2006
  14. Junio C HamanoMar 22, 2006
  15. Junio C HamanoMar 22, 2006
  16. Nick HengeveldMar 23, 2006
  17. Junio C HamanoMar 23, 2006
  18. Radoslaw SzkodzinskiMar 22, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.