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

fix: header parsing #31

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
@@ -6,8 +6,6 @@
name: Elixir CI

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

2 changes: 1 addition & 1 deletion lib/binoculo/cross_saver.ex
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ defmodule Binoculo.CrossSaver do
|> save_to_file()
end

defp save_to_file_enabled?(), do: String.trim(System.get_env("SAVE_TO_FILE"))
defp save_to_file_enabled?(), do: true

defp save_to_file(response) when is_binary(response) do
String.to_atom(response)
18 changes: 14 additions & 4 deletions lib/binoculo/util.ex
Original file line number Diff line number Diff line change
@@ -54,9 +54,19 @@ defmodule Binoculo.Util do
[http_code | key_value] = String.split(header_and_body[:header], "\r\n")

resp =
for session <- key_value, into: %{} do
[key, value] = String.split(session, ": ", parts: 2)
{key, value}
if key_value not in [[], [""], nil] do
for session <- key_value, into: %{} do
session = unless String.contains?(session, ": ") do
session <> ": "
else
session
end

[key, value] = String.split(session, ": ", parts: 2)
{key, value}
end
else
%{}
end

Map.put(
@@ -79,7 +89,7 @@ defmodule Binoculo.Util do
"""
end

defp parse_header_and_body(http_response) do
def parse_header_and_body(http_response) do
case String.split(http_response, "\r\n\r\n") do
[header, body] -> %{header: header, body: body}
header -> %{header: Enum.at(header, 0), body: nil}