# HG changeset patch # User Andrew Shadura # Date 1468500980 -7200 # Node ID d28545413343e05ae394c7074d24736ac36021a2 # Parent 86b39c257c8d8490b3753b121ff601e9e05d77e8 git: include an LF at the end of the service advertisement (Fixes #230) This fixes hg-git/Dulwich and possibly other conservative Git clients, which do not ignore the absence of the LF. The original comment was a guess based on reverse engineering the protocol not specified in the documentation yet at that moment. Now that the documentation exists and states this explicitly, just do as it says. diff -r 86b39c257c8d -r d28545413343 kallithea/lib/middleware/pygrack.py --- a/kallithea/lib/middleware/pygrack.py Tue Jun 14 22:14:39 2016 +0200 +++ b/kallithea/lib/middleware/pygrack.py Thu Jul 14 14:56:20 2016 +0200 @@ -72,14 +72,17 @@ log.debug('command %s not allowed', git_command) return exc.HTTPMethodNotAllowed() - # note to self: - # please, resist the urge to add '\n' to git capture and increment - # line count by 1. - # The code in Git client not only does NOT need '\n', but actually - # blows up if you sprinkle "flush" (0000) as "0001\n". - # It reads binary, per number of bytes specified. - # if you do add '\n' as part of data, count it. - server_advert = '# service=%s' % git_command + # From Documentation/technical/http-protocol.txt shipped with Git: + # + # Clients MUST verify the first pkt-line is `# service=$servicename`. + # Servers MUST set $servicename to be the request parameter value. + # Servers SHOULD include an LF at the end of this line. + # Clients MUST ignore an LF at the end of the line. + # + # smart_reply = PKT-LINE("# service=$servicename" LF) + # ref_list + # "0000" + server_advert = '# service=%s\n' % git_command packet_len = str(hex(len(server_advert) + 4)[2:].rjust(4, '0')).lower() _git_path = kallithea.CONFIG.get('git_path', 'git') cmd = [_git_path, git_command[4:],