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

Update Elli to work with the newest version of gleam #18

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 8 additions & 8 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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" }
12 changes: 6 additions & 6 deletions src/gleam/http/elli.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 =
Expand All @@ -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
Expand All @@ -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) {
[
Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions test/gleam/http/elli_logging_test.gleam
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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.
Expand Down
Loading