Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert HTTP module into hex_core adapter #990

Merged

Conversation

cgerling
Copy link
Contributor

@cgerling cgerling commented Apr 1, 2023

Part of #738

mix.exs Outdated Show resolved Hide resolved
lib/hex/http.ex Outdated

headers =
headers
|> Enum.map(&normalize_header/1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was required because :hex_core headers are #{binary() => binary()} and :httpc.request/5 only accepts charlists

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to change it to binary inside Hex and only convert to/from charlists when we call the httpc functions.

Copy link
Contributor Author

@cgerling cgerling Apr 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about changing this along the hex_core migration but I think it's easier/better to do it now

lib/hex/http.ex Outdated

headers =
headers
|> Enum.map(&normalize_header/1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to change it to binary inside Hex and only convert to/from charlists when we call the httpc functions.

mix.exs Outdated
]
end

defp deps(_) do
[]
[
{:hex_core, "~> 0.9.0"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't add dependencies other than for testing in Hex. Instead we vendor hex_core using this script https://github.com/hexpm/hex/blob/main/scripts/vendor_hex_core.sh. The hex_core module names will be prefixed with mix_.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I've removed this and renamed the hex_core references

@cgerling cgerling force-pushed the convert-http-module-into-hex-core-adapter branch 2 times, most recently from 1c3d8fe to 14d3a5e Compare April 29, 2023 19:53
@ericmj
Copy link
Member

ericmj commented Apr 30, 2023

Can you rebase against main so we can get CI to run? And let us know when it's ready for review again.

@cgerling cgerling force-pushed the convert-http-module-into-hex-core-adapter branch from 14d3a5e to c794b4b Compare April 30, 2023 13:43
@cgerling cgerling requested a review from ericmj April 30, 2023 13:43
Copy link
Member

@ericmj ericmj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Can you look into why there are timeouts on older Elixir/OTP versions?

lib/hex/http.ex Outdated Show resolved Hide resolved
@ericmj ericmj requested a review from wojtekmach April 30, 2023 14:16
@cgerling cgerling force-pushed the convert-http-module-into-hex-core-adapter branch from c794b4b to 0b1cd66 Compare April 30, 2023 15:48
Copy link
Member

@wojtekmach wojtekmach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@cgerling cgerling force-pushed the convert-http-module-into-hex-core-adapter branch from 0b1cd66 to dc52638 Compare May 3, 2023 00:13
@cgerling
Copy link
Contributor Author

cgerling commented May 3, 2023

I'm not entirely sure why the timeout was occurring but I found out that httpc only supports binaries as header values from OTP/24 and above, so I updated the code to encode header values as charlists to, it seemed to solve the timeout as well, I tested with all versions locally to be sure.

@cgerling cgerling requested a review from ericmj May 3, 2023 00:24
@ericmj
Copy link
Member

ericmj commented May 3, 2023

Thank you @cgerling!

@ericmj ericmj merged commit 0451a11 into hexpm:main May 3, 2023
@cgerling cgerling deleted the convert-http-module-into-hex-core-adapter branch May 3, 2023 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants