Skip to content

Commit ec9e85f

Browse files
committed
Remove RepoIdentifier
1 parent a5cad1b commit ec9e85f

File tree

7 files changed

+52
-156
lines changed

7 files changed

+52
-156
lines changed

lib/hex/application.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ defmodule Hex.Application do
4949
defp children do
5050
[
5151
Hex.Netrc.Cache,
52-
Hex.RepoIdentifier,
5352
Hex.State,
5453
Hex.Server,
5554
{Hex.Parallel, [:hex_fetcher]}
@@ -59,7 +58,6 @@ defmodule Hex.Application do
5958
defp children do
6059
[
6160
Hex.Netrc.Cache,
62-
Hex.RepoIdentifier,
6361
Hex.State,
6462
Hex.Server,
6563
{Hex.Parallel, [:hex_fetcher]},

lib/hex/http.ex

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ defmodule Hex.HTTP do
3838

3939
Hex.Shell.debug("Hex.HTTP.request(#{inspect(method)}, #{inspect(url)})")
4040

41-
headers =
42-
headers
43-
|> add_basic_auth_via_netrc(url)
44-
|> add_repo_identifier_header()
41+
headers = add_basic_auth_via_netrc(headers, url)
4542

4643
timeout =
4744
adapter_config[:timeout] ||
@@ -316,13 +313,6 @@ defmodule Hex.HTTP do
316313
host
317314
end
318315

319-
defp add_repo_identifier_header(headers) do
320-
case Hex.RepoIdentifier.fetch() do
321-
nil -> headers
322-
identifier -> Map.put(headers, "x-hex-repo-id", identifier)
323-
end
324-
end
325-
326316
def handle_hex_message(nil) do
327317
:ok
328318
end

lib/hex/repo_identifier.ex

Lines changed: 0 additions & 75 deletions
This file was deleted.

lib/hex/state.ex

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ defmodule Hex.State do
112112
default: nil,
113113
config: [:cacerts_path]
114114
},
115-
no_repo_identifier: %{
116-
env: ["HEX_NO_REPO_IDENTIFIER"],
117-
default: false,
118-
config: [:no_repo_identifier],
119-
fun: {__MODULE__, :to_boolean}
120-
},
121115
no_short_urls: %{
122116
env: ["HEX_NO_SHORT_URLS"],
123117
config: [:no_short_urls],

lib/mix/tasks/hex.config.ex

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ defmodule Mix.Tasks.Hex.Config do
4646
* `no_proxy` - A comma separated list of hostnames that will not be proxied,
4747
asterisks can be used as wildcards. Can be overridden by setting the
4848
environment variable `no_proxy` or `NO_PROXY`
49-
* `no_repo_identifier` - If set to true Hex will not collect an anonymized
50-
git repository identifier. Can be overridden by setting the environment
51-
variable `HEX_NO_REPO_IDENTIFIER` (Default: `false`)
5249
* `http_concurrency` - Limits the number of concurrent HTTP requests in
5350
flight. Can be overridden by setting the environment variable
5451
`HEX_HTTP_CONCURRENCY` (Default: `8`)

test/hex/http_test.exs

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,60 @@ defmodule Hex.HTTPTest do
116116
end)
117117
end
118118

119-
test "request includes identifier header when available", %{bypass: bypass} do
120-
in_tmp(fn ->
121-
# Initialize a git repository with a commit
122-
System.cmd("git", ["init", "--initial-branch=main"])
123-
System.cmd("git", ["config", "user.email", "test@example.com"])
124-
System.cmd("git", ["config", "user.name", "Test User"])
125-
File.write!("test.txt", "test content")
126-
System.cmd("git", ["add", "test.txt"])
127-
System.cmd("git", ["commit", "-m", "Initial commit"])
119+
test "request with Expect 100-continue receives body after 100 response", %{bypass: bypass} do
120+
# Test that httpc handles 100-continue flow correctly
121+
body_content = "test request body"
128122

129-
Bypass.expect(bypass, fn conn ->
130-
assert [client_id] = Plug.Conn.get_req_header(conn, "x-hex-repo-id")
131-
assert client_id =~ ~r/^[a-f0-9]{64}$/
123+
Bypass.expect(bypass, fn conn ->
124+
# Verify the Expect header is present
125+
assert ["100-continue"] = Plug.Conn.get_req_header(conn, "expect")
132126

133-
Plug.Conn.resp(conn, 200, "")
134-
end)
127+
# Send 100 Continue informational response
128+
conn = Plug.Conn.inform(conn, 100, [])
135129

136-
Hex.RepoIdentifier.clear()
137-
Hex.HTTP.request(:get, "http://localhost:#{bypass.port}", %{}, nil)
130+
{:ok, body, conn} = Plug.Conn.read_body(conn)
131+
assert body == body_content
132+
133+
Plug.Conn.resp(conn, 201, "success")
138134
end)
135+
136+
{:ok, {status, _headers, response_body}} =
137+
Hex.HTTP.request(
138+
:post,
139+
"http://localhost:#{bypass.port}",
140+
%{"expect" => "100-continue"},
141+
{"text/plain", body_content}
142+
)
143+
144+
assert status == 201
145+
assert response_body == "success"
146+
end
147+
148+
test "request with Expect 100-continue stops sending body on error response", %{
149+
bypass: bypass
150+
} do
151+
# Test that when server responds with error before 100, body is not sent
152+
# Note: This is handled by httpc automatically - if server responds with
153+
# error status instead of 100 Continue, httpc won't send the body
154+
155+
Bypass.expect(bypass, fn conn ->
156+
# Verify the Expect header is present
157+
assert ["100-continue"] = Plug.Conn.get_req_header(conn, "expect")
158+
159+
# Immediately respond with 401 Unauthorized without reading body
160+
# httpc should NOT send the body when it receives this error
161+
Plug.Conn.resp(conn, 401, "unauthorized")
162+
end)
163+
164+
{:ok, {status, _headers, response_body}} =
165+
Hex.HTTP.request(
166+
:post,
167+
"http://localhost:#{bypass.port}",
168+
%{"expect" => "100-continue"},
169+
{"text/plain", "this body should not be sent"}
170+
)
171+
172+
assert status == 401
173+
assert response_body == "unauthorized"
139174
end
140175
end

test/hex/repo_identifier_test.exs

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)