CodeSampleX

Exemplo

req 0.7.2: Measure a 303 redirect after Req 0.7.2 encodes a JSON POST using an offline adapter

Amostra verificada para hex req 0.7.2: Measure a 303 redirect after Req 0.7.2 encodes a JSON POST using an offline adapter. O contrato rodou em elixir 1 …

sha256:57dca645282763e9d6f66858b3d74356c8d500fcc6a730e19b3187f45238fd43

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
2
Chaves de assinatura que o compilaram
2
Ambiente declarado elixir 1 linux x64 elixir 1 elixir mix

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
elixir 1 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · hex@1
2026-08-17
elixir 1 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · hex@1
2026-08-18

Caso

HOW
Objetivo
Measure a 303 redirect after Req 0.7.2 encodes a JSON POST using an offline adapter
Pacotes
Símbolos
  • Req.request!
  • Req.Request.get_header
Ambiente
elixir 1
Criado
2026-08-17T04:46:35Z

Contrato

  1. assert the offline adapter first receives POST /start whose body iodata becomes the exact JSON bytes and whose content-type is application/json
  2. assert the adapter's 303 Location response triggers a second offline request to /final as GET with nil body and no content-type
  3. assert Req.request! returns the second adapter response with status 200 and body ok

Arquivos

  • NOTES.md
  • csx.json
  • mix.exs
  • mix.lock
  • test/contract_test.exs
  • test/test_helper.exs

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

NOTES.md
# Req JSON POST Redirect Rewriting

`search_known_solution` returned a compatible Req request-construction sample
and a separate redirect sample, but neither directly proved this exact JSON
body boundary. The contract captures both invocations of a fully offline
adapter: the original encoded POST and the bodyless GET produced by a 303.
csx.json
{"buildCommand":["mix","deps.compile","--no-deps-check"],"case":{"believed":"Following a 303 after a JSON POST keeps the POST method, encoded body, and content-type on the redirected request.","caseId":"case:sha256:71316b3b796574ac127bded512b018df4634e3f0ad54eb9711d011ce64026884","contract":["assert the offline adapter first receives POST /start whose body iodata becomes the exact JSON bytes and whose content-type is application/json","assert the adapter's 303 Location response triggers a second offline request to /final as GET with nil body and no content-type","assert Req.request! returns the second adapter response with status 200 and body ok"],"goal":"Measure a 303 redirect after Req 0.7.2 encodes a JSON POST using an offline adapter","kind":"HOW","packages":["pkg:hex/req@0.7.2"],"schemaVersion":1,"symbols":["Req.request!","Req.Request.get_header"]},"contractCommand":["mix","test","--no-deps-check"],"environment":{"arch":"x64","ecosystem":"hex","executionContext":"elixir","language":"elixir","os":"linux","packageManager":"mix","runtime":"elixir","runtimeVersion":"1","schemaVersion":1},"license":"MIT-0","packages":["pkg:hex/req@0.7.2"],"schemaVersion":1,"symbols":["Req.request!","Req.Request.get_header"],"verifierAdapter":"hex@1"}
mix.exs
defmodule CsxReqRedirect.MixProject do
  use Mix.Project

  def project do
    [
      app: :csx_req_redirect,
      version: "0.1.0",
      elixir: "~> 1.15",
      deps: deps()
    ]
  end

  def application, do: [extra_applications: []]

  defp deps do
    [{:req, "0.7.2"}]
  end
end
mix.lock
%{
  "finch": {:hex, :finch, "0.23.0", "e3f9287ac25a8832f848b144c2b57346aac65b205e2e0629a52adfe6507fd837", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.8", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "80e58d3f936f57e3fdf404f83a3642897ae6d9fb642934e46da4d8fe761b99d5"},
  "hpax": {:hex, :hpax, "1.0.4", "777de5d433b0fbdc7c418159c8055910faa8047ffdb3d6b31098d2a46cd7685c", [:mix], [], "hexpm", "afc7cb142ebcc2d01ce7816190b98ce5dd49e799111b24249f3443d730f377ca"},
  "jason": {:hex, :jason, "1.4.5", "2e3a008590b0b8d7388c20293e9dcc9cf3e5d642fd2a114e4cbbb52e595d940a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b0c823996102bcd0239b3c2444eb00409b72f6a140c1950bc8b457d836b30684"},
  "mime": {:hex, :mime, "2.0.7", "b8d739037be7cd402aee1ba0306edfdef982687ee7e9859bee6198c1e7e2f128", [:mix], [], "hexpm", "6171188e399ee16023ffc5b76ce445eb6d9672e2e241d2df6050f3c771e80ccd"},
  "mint": {:hex, :mint, "1.9.3", "3337184d69179695c7a9f1714d92c11e629d36c8c037a21cf490131d3d150554", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1 or ~> 0.2.0 or ~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "5f7c9342480c069dbbc4eeac3490303c9e01870ff01a7f1d29b6107054fc1e74"},
  "nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
  "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"},
  "req": {:hex, :req, "0.7.2", "364eae2e5f5c984f2dac6d71c07f8c8c89ce0bc49c4d746dacb7a306823020de", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:finch, "~> 0.21", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "c9cdfa276b05d8db2a27fda5d233e6858b764d47189d76cbb186e130a871ae0b"},
  "telemetry": {:hex, :telemetry, "1.4.2", "a0cb522801dffb1c49fe6e30561badffc7b6d0e180db1300df759faa22062855", [:rebar3], [], "hexpm", "928f6495066506077862c0d1646609eed891a4326bee3126ba54b60af61febb1"},
}
test/contract_test.exs
defmodule CsxReqRedirect.ContractTest do
  use ExUnit.Case, async: true

  defmodule OfflineAdapter do
    def run(request) do
      body = if is_nil(request.body), do: nil, else: IO.iodata_to_binary(request.body)

      send(Process.get(:redirect_contract_parent), {
        :request_handoff,
        request.method,
        request.url.path,
        body,
        Req.Request.get_header(request, "content-type")
      })

      case {request.method, request.url.path} do
        {:post, "/start"} ->
          response = %Req.Response{
            status: 303,
            headers: %{"location" => ["/final"]},
            body: ""
          }

          {request, response}

        {:get, "/final"} ->
          response = %Req.Response{
            status: 200,
            headers: %{"content-type" => ["text/plain"]},
            body: "ok"
          }

          {request, response}
      end
    end
  end

  test "303 rewrites an encoded JSON POST before the second adapter request" do
    Process.put(:redirect_contract_parent, self())

    response =
      Req.request!(
        method: :post,
        url: "https://example.org/start",
        json: %{kind: "payload"},
        redirect: true,
        adapter: &OfflineAdapter.run/1
      )

    assert response.status == 200
    assert response.body == "ok"

    assert_receive {
      :request_handoff,
      :post,
      "/start",
      ~s({"kind":"payload"}),
      ["application/json"]
    }

    assert_receive {:request_handoff, :get, "/final", nil, []}
    refute_receive {:request_handoff, _, _, _, _}
  end
end
test/test_helper.exs
ExUnit.start()

Seeder de origem

csx-seed