git smart-HTTP: pass CONTENT_LENGTH, don't merge stderr
5fe9c0c · gmorell · 2026-06-25 15:53
Message
{commit_body(@commit)}
Files changed
modified
lib/git_gud_web/plugs/git_smart_http.ex
+12
−1
@@ -234,6 +234,14 @@ defmodule GitGudWeb.Plugs.GitSmartHttp do
| 234 | 234 | {"REQUEST_METHOD", method}, |
| 235 | 235 | {"QUERY_STRING", conn.query_string || ""}, |
| 236 | 236 | {"CONTENT_TYPE", first_header(conn, "content-type")}, |
| 237 | + # git http-backend reads the POST body (the upload-pack/receive-pack | |
| 238 | + # request) as a CGI script: it consumes CONTENT_LENGTH bytes from | |
| 239 | + # stdin. Without this it reads nothing, upload-pack gets an empty | |
| 240 | + # request, and the fetch returns an empty pack ("remote end hung up | |
| 241 | + # unexpectedly"). HTTP_CONTENT_ENCODING lets it inflate a gzipped | |
| 242 | + # request body. Both are nil on GET (info/refs) and get dropped. | |
| 243 | + {"CONTENT_LENGTH", first_header(conn, "content-length")}, | |
| 244 | + {"HTTP_CONTENT_ENCODING", first_header(conn, "content-encoding")}, | |
| 237 | 245 | {"REMOTE_USER", "gitgud"}, |
| 238 | 246 | {"REMOTE_ADDR", remote_ip_string(conn)}, |
| 239 | 247 | # Attribute the runs this push triggers to the authenticated |
@@ -274,7 +282,10 @@ defmodule GitGudWeb.Plugs.GitSmartHttp do
| 274 | 282 | :stream, |
| 275 | 283 | :exit_status, |
| 276 | 284 | :use_stdio, |
| 277 | − :stderr_to_stdout, | |
| 285 | + # Do NOT merge stderr into stdout: stdout carries the binary git | |
| 286 | + # protocol (pack stream); any stderr text would corrupt it and | |
| 287 | + # the client errors with "remote end hung up" / "bad pack". | |
| 288 | + # http-backend's stderr lands on the pod log instead. | |
| 278 | 289 | args: ["http-backend"], |
| 279 | 290 | env: Enum.map(env, fn {k, v} -> {String.to_charlist(k), String.to_charlist(v)} end) |
| 280 | 291 | ] |
Parents: e60ba65