tweaks
3625825 · gmorell · 2026-05-25 16:58
Files changed
modified
lib/git_gud_web/controllers/runner_controller.ex
+25
−1
@@ -483,7 +483,7 @@ defmodule GitGudWeb.RunnerController do
| 483 | 483 | defp decode_request(conn, msg_module) do |
| 484 | 484 | case wire_format(conn) do |
| 485 | 485 | {:protobuf, _} -> |
| 486 | − body = read_proto_body(conn) | |
| 486 | + body = read_proto_body(conn) |> maybe_decompress(conn) | |
| 487 | 487 | |
| 488 | 488 | try do |
| 489 | 489 | {:ok, msg_module.decode(body)} |
@@ -508,6 +508,30 @@ defmodule GitGudWeb.RunnerController do
| 508 | 508 | end |
| 509 | 509 | end |
| 510 | 510 | |
| 511 | + # Connect-Go's HTTP client may set `content-encoding: gzip` on | |
| 512 | + # request bodies above a size threshold (especially final-flush | |
| 513 | + # UpdateLog batches). Plug.Conn doesn't auto-decompress request | |
| 514 | + # bodies, so we have to do it before handing the bytes to the | |
| 515 | + # protobuf decoder — otherwise the decoder sees gzip magic | |
| 516 | + # (`1f 8b ...`) and returns invalid_argument. | |
| 517 | + # | |
| 518 | + # Cheap fail-open if zlib raises (e.g., bytes weren't actually | |
| 519 | + # gzipped despite the header) — pass through the raw body and let | |
| 520 | + # the protobuf decoder surface the real error. | |
| 521 | + defp maybe_decompress(body, conn) do | |
| 522 | + case Plug.Conn.get_req_header(conn, "content-encoding") do | |
| 523 | + [enc | _] when enc in ["gzip", "x-gzip"] -> | |
| 524 | + try do | |
| 525 | + :zlib.gunzip(body) | |
| 526 | + rescue | |
| 527 | + _ -> body | |
| 528 | + end | |
| 529 | + | |
| 530 | + _ -> | |
| 531 | + body | |
| 532 | + end | |
| 533 | + end | |
| 534 | + | |
| 511 | 535 | # Plug.Parsers only invokes its body_reader for parsers it knows |
| 512 | 536 | # about — for `application/protobuf` it doesn't run, so our |
| 513 | 537 | # CacheRawBody assign is empty. Read the body directly when needed. |
Parents: 982f645