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

[PATCH] Add ERR support to smart HTTP

From
ILIlari Liusvaara <ilari.liusvaara@elisanet.fi>
Date
Sep 5, 2010, 17:30 UTC
Message-ID
<1283707815-32038-1-git-send-email-ilari.liusvaara@elisanet.fi>

All "true smart transports" support ERR packets, allowing server to send back error message explaining reasons for refusing the request instead of just rudely closing connection without any error.

However, since smart HTTP isn't "true smart transport", but instead dumb one from git main executable perspective, smart HTTP needs to implement its own version of this.

Now that Gitolite supports HTTP too, it needs to be able to send error messages for authorization failures back to client so that's one probable user for this feature.

The error is sent as '<packetlength># ERR <message>" and must be the first packet in response. The reason for putting the '#' there is that old git versions will interpret that as invalid server response and print (at least the first line of) the error together with complaint of invalid response (mangling it a bit but it will still be understandable, in manner similar to existing smart transport ERR messages).

Thus for example server response:
"0031# ERR W access for foo/alice/a1 DENIED to bob"
Will cause the following to be printed:
"fatal: remote error: W access for foo/alice/a1 DENIED to bob"

If the git version is old and doesn't support this feature, then the message will be:

"fatal: invalid server response; got '# ERR W access for foo/alice/a1 DENIED to bob'"

Which is at least undertandable.
Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
---
 remote-curl.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/remote-curl.c b/remote-curl.c
index 24fbb9a..46fa971 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -153,6 +153,8 @@ static struct discovery* discover_refs(const char *service)
 
 		if (packet_get_line(&buffer, &last->buf, &last->len) <= 0)
 			die("%s has invalid packet header", refs_url);
+		if (buffer.len >= 6 && !strncmp(buffer.buf, "# ERR ", 6))
+			die("remote error: %s", buffer.buf + 6);
 		if (buffer.len && buffer.buf[buffer.len - 1] == '\n')
 			strbuf_setlen(&buffer, buffer.len - 1);
 
-- 
1.7.2.4.g27652
Next: Jonathan Nieder
Message 1 of 18 in “Add ERR support to smart HTTP”
  1. Add ERR support to smart HTTPIlari Liusvaara, Sep 5, 2010
  2. Jonathan NiederSep 5, 2010
  3. Ilari LiusvaaraSep 5, 2010
  4. Ævar Arnfjörð BjarmasonSep 5, 2010
  5. Ilari LiusvaaraSep 5, 2010
  6. Jakub NarebskiSep 5, 2010
  7. Sitaram ChamartySep 6, 2010
  8. Sitaram ChamartySep 6, 2010
  9. Ævar Arnfjörð BjarmasonSep 6, 2010
  10. Jakub NarebskiSep 6, 2010
  11. Joshua JuranSep 6, 2010
  12. Shawn O. PearceSep 6, 2010
  13. Sitaram ChamartySep 6, 2010
  14. Shawn O. PearceSep 6, 2010
  15. Sitaram ChamartySep 8, 2010
  16. Sitaram ChamartySep 6, 2010
  17. Jakub NarebskiSep 6, 2010
  18. Jonathan NiederSep 5, 2010

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.