From 814c84c6bb83da9eb3223d6c2b297738785f2a84 Mon Sep 17 00:00:00 2001 From: Jaxon Carelos Date: Mon, 11 Mar 2024 13:08:20 -0600 Subject: [PATCH 1/2] Update Elli to work with the newest version of gleam --- gleam.toml | 2 +- manifest.toml | 16 ++++++++-------- src/gleam/http/elli.gleam | 12 ++++++------ test/gleam/http/elli_logging_test.gleam | 20 ++++++++++---------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/gleam.toml b/gleam.toml index 4b74661..cba574f 100644 --- a/gleam.toml +++ b/gleam.toml @@ -13,7 +13,7 @@ links = [ [dependencies] gleam_erlang = "~> 0.23" -gleam_stdlib = "~> 0.32" +gleam_stdlib = "~> 0.36" gleam_http = "~> 3.0" gleam_otp = "~> 0.3" elli = "~> 3.0" diff --git a/manifest.toml b/manifest.toml index c27d609..22802f9 100644 --- a/manifest.toml +++ b/manifest.toml @@ -4,13 +4,13 @@ packages = [ { name = "certifi", version = "2.12.0", build_tools = ["rebar3"], requirements = [], otp_app = "certifi", source = "hex", outer_checksum = "EE68D85DF22E554040CDB4BE100F33873AC6051387BAF6A8F6CE82272340FF1C" }, { name = "elli", version = "3.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "elli", source = "hex", outer_checksum = "698B13B33D05661DB9FE7EFCBA41B84825A379CCE86E486CF6AFF9285BE0CCF8" }, - { name = "gleam_erlang", version = "0.23.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "DA7A8E5540948DE10EB01B530869F8FF2FF6CAD8CFDA87626CE6EF63EBBF87CB" }, - { name = "gleam_hackney", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_stdlib", "hackney"], otp_app = "gleam_hackney", source = "hex", outer_checksum = "CA69AD9061C4A8775A7BD445DE33ECEFD87379AF8E5B028F3DD0216BECA5DD0B" }, - { name = "gleam_http", version = "3.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "0B09AAE8EB547C4F2F2D3F8917A0A4D2EF75DFF0232389332BAFE19DBBFDB92B" }, - { name = "gleam_otp", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang"], otp_app = "gleam_otp", source = "hex", outer_checksum = "18EF8242A5E54BA92F717C7222F03B3228AEE00D1F286D4C56C3E8C18AA2588E" }, - { name = "gleam_stdlib", version = "0.32.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "07D64C26D014CF570F8ACADCE602761EA2E74C842D26F2FD49B0D61973D9966F" }, - { name = "gleeunit", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D3682ED8C5F9CAE1C928F2506DE91625588CC752495988CBE0F5653A42A6F334" }, - { name = "hackney", version = "1.20.1", build_tools = ["rebar3"], requirements = ["mimerl", "parse_trans", "unicode_util_compat", "idna", "ssl_verify_fun", "certifi", "metrics"], otp_app = "hackney", source = "hex", outer_checksum = "FE9094E5F1A2A2C0A7D10918FEE36BFEC0EC2A979994CFF8CFE8058CD9AF38E3" }, + { name = "gleam_erlang", version = "0.24.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "26BDB52E61889F56A291CB34167315780EE4AA20961917314446542C90D1C1A0" }, + { name = "gleam_hackney", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_stdlib", "hackney"], otp_app = "gleam_hackney", source = "hex", outer_checksum = "066B1A55D37DBD61CC72A1C4EDE43C6015B1797FAF3818C16FE476534C7B6505" }, + { name = "gleam_http", version = "3.5.3", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "C2FC3322203B16F897C1818D9810F5DEFCE347F0751F3B44421E1261277A7373" }, + { name = "gleam_otp", version = "0.10.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "0B04FE915ACECE539B317F9652CAADBBC0F000184D586AAAF2D94C100945D72B" }, + { name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" }, + { name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" }, + { name = "hackney", version = "1.20.1", build_tools = ["rebar3"], requirements = ["certifi", "idna", "metrics", "mimerl", "parse_trans", "ssl_verify_fun", "unicode_util_compat"], otp_app = "hackney", source = "hex", outer_checksum = "FE9094E5F1A2A2C0A7D10918FEE36BFEC0EC2A979994CFF8CFE8058CD9AF38E3" }, { name = "idna", version = "6.1.1", build_tools = ["rebar3"], requirements = ["unicode_util_compat"], otp_app = "idna", source = "hex", outer_checksum = "92376EB7894412ED19AC475E4A86F7B413C1B9FBB5BD16DCCD57934157944CEA" }, { name = "metrics", version = "1.0.1", build_tools = ["rebar3"], requirements = [], otp_app = "metrics", source = "hex", outer_checksum = "69B09ADDDC4F74A40716AE54D140F93BEB0FB8978D8636EADED0C31B6F099F16" }, { name = "mimerl", version = "1.2.0", build_tools = ["rebar3"], requirements = [], otp_app = "mimerl", source = "hex", outer_checksum = "F278585650AA581986264638EBF698F8BB19DF297F66AD91B18910DFC6E19323" }, @@ -25,5 +25,5 @@ gleam_erlang = { version = "~> 0.23" } gleam_hackney = { version = "~> 1.0" } gleam_http = { version = "~> 3.0" } gleam_otp = { version = "~> 0.3" } -gleam_stdlib = { version = "~> 0.32" } +gleam_stdlib = { version = "~> 0.36" } gleeunit = { version = "~> 1.0" } diff --git a/src/gleam/http/elli.gleam b/src/gleam/http/elli.gleam index fc5b3ce..0a87423 100644 --- a/src/gleam/http/elli.gleam +++ b/src/gleam/http/elli.gleam @@ -10,12 +10,12 @@ import gleam/option import gleam/pair import gleam/result import gleam/string -import gleam/bit_builder.{type BitBuilder} +import gleam/bytes_builder.{type BytesBuilder} type ElliRequest type ElliResponse = - #(Int, List(http.Header), BitBuilder) + #(Int, List(http.Header), BytesBuilder) type StartLinkOption { Callback(Atom) @@ -96,7 +96,7 @@ fn convert_header_to_lowercase(header: http.Header) -> http.Header { } fn service_to_elli_handler( - service: Service(BitArray, BitBuilder), + service: Service(BitArray, BytesBuilder), ) -> fn(ElliRequest) -> ElliResponse { fn(req) { let resp = @@ -108,7 +108,7 @@ fn service_to_elli_handler( path: get_path(req), query: option.Some(get_query(req)), headers: get_headers(req) - |> list.map(convert_header_to_lowercase), + |> list.map(convert_header_to_lowercase), body: get_body(req), ) |> service @@ -124,7 +124,7 @@ fn service_to_elli_handler( /// the current process you may want to use the `become` function instead. /// pub fn start( - service: Service(BitArray, BitBuilder), + service: Service(BitArray, BytesBuilder), on_port number: Int, ) -> Result(Pid, Dynamic) { [ @@ -141,7 +141,7 @@ pub fn start( /// shut down after successfully starting. /// pub fn become( - service: Service(BitArray, BitBuilder), + service: Service(BitArray, BytesBuilder), on_port number: Int, ) -> Result(Nil, Dynamic) { service diff --git a/test/gleam/http/elli_logging_test.gleam b/test/gleam/http/elli_logging_test.gleam index 7280328..58e3042 100644 --- a/test/gleam/http/elli_logging_test.gleam +++ b/test/gleam/http/elli_logging_test.gleam @@ -1,4 +1,4 @@ -import gleam/bit_builder.{type BitBuilder} +import gleam/bytes_builder.{type BytesBuilder} import gleam/dynamic.{type DecodeError, type Dynamic} import gleam/erlang/atom.{type Atom} import gleam/hackney @@ -7,13 +7,13 @@ import gleam/http/elli import gleam/http/request.{type Request} import gleam/http/response.{type Response} import gleam/list -import gleam/map.{type Map} +import gleam/dict.{type Dict} import gleam/result import gleeunit/should // Using FFI to make crashing in the request handler easy. @external(erlang, "elli_logging_test_ffi", "bad_service") -fn bad_service(request request: Request(BitArray)) -> Response(BitBuilder) +fn bad_service(request request: Request(BitArray)) -> Response(BytesBuilder) pub fn log_throw_test() { let port = 4712 @@ -98,7 +98,7 @@ type ReportKey { } @external(erlang, "elli_logging_test_ffi", "get_spied_reports") -fn get_spied_reports(id id: String) -> List(#(String, Map(ReportKey, Dynamic))) +fn get_spied_reports(id id: String) -> List(#(String, Dict(ReportKey, Dynamic))) fn make_request(port: Int, method: Method, path: String, message: String) { request.new() @@ -112,29 +112,29 @@ fn make_request(port: Int, method: Method, path: String, message: String) { } fn get_string( - report: Map(a, Dynamic), + report: Dict(a, Dynamic), key: a, ) -> Result(String, List(DecodeError)) { - map.get(report, key) + dict.get(report, key) |> result.map_error(fn(_) { [] }) |> result.then(dynamic.string) } fn list_length( - report: Map(a, Dynamic), + report: Dict(a, Dynamic), key: a, ) -> Result(Int, List(DecodeError)) { - map.get(report, key) + dict.get(report, key) |> result.map_error(fn(_) { [] }) |> result.then(dynamic.shallow_list) |> result.map(list.length) } fn get_method( - report: Map(a, Dynamic), + report: Dict(a, Dynamic), key: a, ) -> Result(Atom, List(DecodeError)) { - map.get(report, key) + dict.get(report, key) |> result.map_error(fn(_) { [] }) // This only covers the methods we use in the tests, // notably not the binaries we get for unknown methods. From 41dd2c42aad7402d22dc8b045d3cdf22c0545128 Mon Sep 17 00:00:00 2001 From: Jaxon Carelos Date: Mon, 11 Mar 2024 13:11:28 -0600 Subject: [PATCH 2/2] Updated readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5ba7648..191d9af 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ A Gleam HTTP service adapter for the Elli web server. import gleam/http/elli import gleam/http/request.{Request} import gleam/http/response.{Response} -import gleam/bit_builder.{BitBuilder} +import gleam/bytes_builder.{BytesBuilder} // Define a HTTP service // -pub fn my_service(req: Request(BitString)) -> Response(BitBuilder) { +pub fn my_service(req: Request(t)) -> Response(BytesBuilder) { let body = bit_builder.from_string("Hello, world!") response.new(200)