       {ct_provided, conn, state} = resource_call(conn, state, :content_types_provided)
       f = Enum.find_value(ct_provided, fn {t,f} -> normalize_mtype(t) == ct && f end)
       {body, conn, state} = resource_call(conn, state, f)
-      conn = set_resp_body(conn, encode_body(conn, state, body))
+      {body, conn, state} = encode_body(conn, state, body)
+      conn = set_resp_body(conn, body)
       v3o18b(conn, state)
     else
       v3o18b(conn, state)

  
  ## "Moved temporarily?"
  decision v3l5(conn, state) do
    {moved, conn, state} = resource_call(conn, state, :moved_temporarily)
    case moved do
      {true, moved_uri} ->
	set_resp_header(conn, "location", moved_uri)
	respond(conn, state, 307)
      false ->
	v3m5(conn, state)
    end
  end


  ## "Service Available"
  decision v3b13(conn, state) do
    case resource_call(conn, state, :ping) do
      {:pong, conn, state} ->
	v3b13b(conn, state);
      {_, conn, state} ->
	respond(conn, state, 503)
    end
  end
  
