🧚 A practical web framework for Gleam

Update for Gleam v0.32

Changed files
+80 -77
examples
utilities
src
test
+2
CHANGELOG.md
··· 2 2 3 3 ## Unreleased 4 4 5 + - Updated for Gleam v0.32. All references to "bit string" have been changed to 6 + "bit array" to match. 5 7 - The `wisp` module gains the `get_query` function. 6 8 7 9 ## v0.6.0 - 2023-10-19
+6 -6
examples/utilities/tiny_database/manifest.toml
··· 2 2 # You typically do not need to edit this file 3 3 4 4 packages = [ 5 - { name = "gleam_erlang", version = "0.20.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "F216A80C8FDFF774447B494D5E08AE4E9A911E971727B9A78FEBF5F300914584" }, 6 - { name = "gleam_json", version = "0.6.0", build_tools = ["gleam"], requirements = ["thoas", "gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "C6CC5BEECA525117E97D0905013AB3F8836537455645DDDD10FE31A511B195EF" }, 7 - { name = "gleam_otp", version = "0.6.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "E31B158857E3D2AF946FE6E90E0CB21699AF226F4630E93FBEAC5DB4515F8920" }, 8 - { name = "gleam_stdlib", version = "0.30.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "704258528887F95075FFED7AAE1CCF836A9B88E3AADA2F69F9DA15815F94A4F9" }, 5 + { name = "gleam_erlang", version = "0.23.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "DA7A8E5540948DE10EB01B530869F8FF2FF6CAD8CFDA87626CE6EF63EBBF87CB" }, 6 + { name = "gleam_json", version = "0.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "C6CC5BEECA525117E97D0905013AB3F8836537455645DDDD10FE31A511B195EF" }, 7 + { name = "gleam_otp", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang"], otp_app = "gleam_otp", source = "hex", outer_checksum = "ED7381E90636E18F5697FD7956EECCA635A3B65538DC2BE2D91A38E61DCE8903" }, 8 + { name = "gleam_stdlib", version = "0.32.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "07D64C26D014CF570F8ACADCE602761EA2E74C842D26F2FD49B0D61973D9966F" }, 9 9 { name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" }, 10 - { name = "ids", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang", "gleam_otp"], otp_app = "ids", source = "hex", outer_checksum = "7A378014D40E848326FBEE8AC0C9B35EB9C8094DC4414D89F9A5AA99397A6042" }, 11 - { name = "simplifile", version = "0.1.10", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "263B7C7F4B29263555DEA2D30BA918425A27120CDD1E1352744EAB4D56CE01CE" }, 10 + { name = "ids", version = "0.10.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "ids", source = "hex", outer_checksum = "36E0E8005716D0030A598B4F5AFB4C269002C119C9DAB100AD3D715B7159705E" }, 11 + { name = "simplifile", version = "0.1.14", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "10EA0207796F20488A3A166C50A189C9385333F3C9FAC187729DE7B9CE4ADDBC" }, 12 12 { name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" }, 13 13 ] 14 14
+1 -1
examples/utilities/tiny_database/src/tiny_database.gleam
··· 3 3 import ids/nanoid 4 4 import gleam/json 5 5 import gleam/list 6 - import gleam/map.{Map} 6 + import gleam/map.{type Map} 7 7 import simplifile 8 8 9 9 pub opaque type Connection {
+1 -1
gleam.toml
··· 1 1 name = "wisp" 2 2 version = "0.6.0" 3 - gleam = ">= 0.30.0" 3 + gleam = ">= 0.32.0" 4 4 description = "A practical web framework for Gleam" 5 5 licences = ["Apache-2.0"] 6 6
+7 -7
manifest.toml
··· 4 4 packages = [ 5 5 { name = "exception", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "71F00057D38ADB03BBCCD0E3B07AB2C236BD49DBA7E7611A9DADBD1E26C9F53D" }, 6 6 { name = "gleam_bitwise", version = "1.3.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "E2A46EE42E5E9110DAD67E0F71E7358CBE54D5EC22C526DD48CBBA3223025792" }, 7 - { name = "gleam_crypto", version = "0.4.0", build_tools = ["gleam"], requirements = ["gleam_bitwise", "gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "42429CED0F838B40014E1C017B0495C46C311D08035D2C2D43B749B91A4374F6" }, 8 - { name = "gleam_erlang", version = "0.22.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "367D8B41A7A86809928ED1E7E55BFD0D46D7C4CF473440190F324AFA347109B4" }, 9 - { name = "gleam_http", version = "3.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "FAE9AE3EB1CA90C2194615D20FFFD1E28B630E84DACA670B28D959B37BCBB02C" }, 7 + { name = "gleam_crypto", version = "0.4.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_bitwise"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "42429CED0F838B40014E1C017B0495C46C311D08035D2C2D43B749B91A4374F6" }, 8 + { name = "gleam_erlang", version = "0.23.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "DA7A8E5540948DE10EB01B530869F8FF2FF6CAD8CFDA87626CE6EF63EBBF87CB" }, 9 + { name = "gleam_http", version = "3.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "0B09AAE8EB547C4F2F2D3F8917A0A4D2EF75DFF0232389332BAFE19DBBFDB92B" }, 10 10 { name = "gleam_json", version = "0.6.0", build_tools = ["gleam"], requirements = ["thoas", "gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "C6CC5BEECA525117E97D0905013AB3F8836537455645DDDD10FE31A511B195EF" }, 11 - { name = "gleam_otp", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang"], otp_app = "gleam_otp", source = "hex", outer_checksum = "ED7381E90636E18F5697FD7956EECCA635A3B65538DC2BE2D91A38E61DCE8903" }, 12 - { name = "gleam_stdlib", version = "0.31.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "6D1BC5B4D4179B9FEE866B1E69FE180AC2CE485AD90047C0B32B2CA984052736" }, 11 + { name = "gleam_otp", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "ED7381E90636E18F5697FD7956EECCA635A3B65538DC2BE2D91A38E61DCE8903" }, 12 + { name = "gleam_stdlib", version = "0.32.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "07D64C26D014CF570F8ACADCE602761EA2E74C842D26F2FD49B0D61973D9966F" }, 13 13 { name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" }, 14 - { name = "glisten", version = "0.9.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "glisten", source = "hex", outer_checksum = "91809C44C52456D96C8317A19246DE1C06ED494C40D282CD9380565E879A52C4" }, 14 + { name = "glisten", version = "0.9.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_otp", "gleam_erlang"], otp_app = "glisten", source = "hex", outer_checksum = "91809C44C52456D96C8317A19246DE1C06ED494C40D282CD9380565E879A52C4" }, 15 15 { name = "marceau", version = "1.1.0", build_tools = ["gleam"], requirements = [], otp_app = "marceau", source = "hex", outer_checksum = "1AAD727A30BE0F95562C3403BB9B27C823797AD90037714255EEBF617B1CDA81" }, 16 - { name = "mist", version = "0.14.0", build_tools = ["gleam"], requirements = ["glisten", "gleam_erlang", "gleam_http", "gleam_stdlib", "gleam_otp"], otp_app = "mist", source = "hex", outer_checksum = "7CDD0396D9A556F1069D83E9AF2B24388AAC478B9B4846615C6D4797E1D3C6A3" }, 16 + { name = "mist", version = "0.14.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "glisten", "gleam_stdlib", "gleam_otp", "gleam_http"], otp_app = "mist", source = "hex", outer_checksum = "7CDD0396D9A556F1069D83E9AF2B24388AAC478B9B4846615C6D4797E1D3C6A3" }, 17 17 { name = "simplifile", version = "0.1.14", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "10EA0207796F20488A3A166C50A189C9385333F3C9FAC187729DE7B9CE4ADDBC" }, 18 18 { name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" }, 19 19 ]
+43 -42
src/wisp.gleam
··· 1 1 import exception 2 - import gleam/base 3 - import gleam/bit_builder 4 - import gleam/bit_string 2 + import gleam/bytes_builder 3 + import gleam/bit_array 5 4 import gleam/bool 6 5 import gleam/crypto 7 - import gleam/dynamic.{Dynamic} 6 + import gleam/dynamic.{type Dynamic} 8 7 import gleam/erlang 9 - import gleam/http.{Method} 8 + import gleam/http.{type Method} 10 9 import gleam/http/cookie 11 - import gleam/http/request.{Request as HttpRequest} 12 - import gleam/http/response.{Response as HttpResponse} 10 + import gleam/http/request.{type Request as HttpRequest} 11 + import gleam/http/response.{ 12 + type Response as HttpResponse, Response as HttpResponse, 13 + } 13 14 import gleam/int 14 15 import gleam/json 15 16 import gleam/list 16 - import gleam/option.{Option} 17 + import gleam/option.{type Option} 17 18 import gleam/result 18 19 import gleam/string 19 - import gleam/string_builder.{StringBuilder} 20 + import gleam/string_builder.{type StringBuilder} 20 21 import gleam/uri 21 22 import marceau 22 23 import mist ··· 88 89 89 90 fn mist_response(response: Response) -> HttpResponse(mist.ResponseData) { 90 91 let body = case response.body { 91 - Empty -> mist.Bytes(bit_builder.new()) 92 - Text(text) -> mist.Bytes(bit_builder.from_string_builder(text)) 92 + Empty -> mist.Bytes(bytes_builder.new()) 93 + Text(text) -> mist.Bytes(bytes_builder.from_string_builder(text)) 93 94 File(path) -> mist_send_file(path) 94 95 } 95 96 response ··· 102 103 Error(error) -> { 103 104 log_error(string.inspect(error)) 104 105 // TODO: return 500 105 - mist.Bytes(bit_builder.new()) 106 + mist.Bytes(bytes_builder.new()) 106 107 } 107 108 } 108 109 } ··· 538 539 } 539 540 540 541 type BufferedReader { 541 - BufferedReader(reader: Reader, buffer: BitString) 542 + BufferedReader(reader: Reader, buffer: BitArray) 542 543 } 543 544 544 545 type Quotas { ··· 571 572 fn(Int) -> Result(Read, Nil) 572 573 573 574 type Read { 574 - Chunk(BitString, next: Reader) 575 + Chunk(BitArray, next: Reader) 575 576 ReadingFinished 576 577 } 577 578 ··· 799 800 next: fn(String) -> Response, 800 801 ) -> Response { 801 802 case read_body_to_bitstring(request) { 802 - Ok(body) -> or_400(bit_string.to_string(body), next) 803 + Ok(body) -> or_400(bit_array.to_string(body), next) 803 804 Error(_) -> entity_too_large() 804 805 } 805 806 } ··· 827 828 /// } 828 829 /// ``` 829 830 /// 830 - pub fn require_bit_string_body( 831 + pub fn require_bit_array_body( 831 832 request: Request, 832 - next: fn(BitString) -> Response, 833 + next: fn(BitArray) -> Response, 833 834 ) -> Response { 834 835 case read_body_to_bitstring(request) { 835 836 Ok(body) -> next(body) ··· 841 842 // network errors. 842 843 /// Read the entire body of the request as a bit string. 843 844 /// 844 - /// You may instead wish to use the `require_bit_string_body` or the 845 + /// You may instead wish to use the `require_bit_array_body` or the 845 846 /// `require_string_body` middleware functions instead. 846 847 /// 847 848 /// This function does not cache the body in any way, so if you call this ··· 853 854 /// If the body is larger than the `max_body_size` limit then an empty response 854 855 /// with status code 413: Entity too large will be returned to the client. 855 856 /// 856 - pub fn read_body_to_bitstring(request: Request) -> Result(BitString, Nil) { 857 + pub fn read_body_to_bitstring(request: Request) -> Result(BitArray, Nil) { 857 858 let connection = request.body 858 859 read_body_loop( 859 860 connection.reader, ··· 867 868 reader: Reader, 868 869 read_chunk_size: Int, 869 870 max_body_size: Int, 870 - accumulator: BitString, 871 - ) -> Result(BitString, Nil) { 871 + accumulator: BitArray, 872 + ) -> Result(BitArray, Nil) { 872 873 use chunk <- result.try(reader(read_chunk_size)) 873 874 case chunk { 874 875 ReadingFinished -> Ok(accumulator) 875 876 Chunk(chunk, next) -> { 876 - let accumulator = bit_string.append(accumulator, chunk) 877 - case bit_string.byte_size(accumulator) > max_body_size { 877 + let accumulator = bit_array.append(accumulator, chunk) 878 + case bit_array.byte_size(accumulator) > max_body_size { 878 879 True -> Error(Nil) 879 880 False -> 880 881 read_body_loop(next, read_chunk_size, max_body_size, accumulator) ··· 1057 1058 1058 1059 // No file name, this is a regular form value that we hold in memory. 1059 1060 option.None -> { 1060 - let append = fn(data, chunk) { Ok(bit_string.append(data, chunk)) } 1061 + let append = fn(data, chunk) { Ok(bit_array.append(data, chunk)) } 1061 1062 let q = quotas.body 1062 1063 let result = 1063 1064 multipart_body(reader, parse, boundary, read_size, q, append, <<>>) 1064 1065 use #(reader, quota, value) <- result.try(result) 1065 1066 let quotas = Quotas(..quotas, body: quota) 1066 - use value <- result.map(bit_string_to_string(value)) 1067 + use value <- result.map(bit_array_to_string(value)) 1067 1068 let data = FormData(..data, values: [#(name, value), ..data.values]) 1068 1069 #(data, reader, quotas) 1069 1070 } ··· 1078 1079 } 1079 1080 } 1080 1081 1081 - fn bit_string_to_string(bits: BitString) -> Result(String, Response) { 1082 - bit_string.to_string(bits) 1082 + fn bit_array_to_string(bits: BitArray) -> Result(String, Response) { 1083 + bit_array.to_string(bits) 1083 1084 |> result.replace_error(bad_request()) 1084 1085 } 1085 1086 1086 1087 fn multipart_file_append( 1087 1088 path: String, 1088 - chunk: BitString, 1089 + chunk: BitArray, 1089 1090 ) -> Result(String, Response) { 1090 1091 chunk 1091 1092 |> simplifile.append_bits(path) ··· 1105 1106 1106 1107 fn multipart_body( 1107 1108 reader: BufferedReader, 1108 - parse: fn(BitString) -> Result(http.MultipartBody, Response), 1109 + parse: fn(BitArray) -> Result(http.MultipartBody, Response), 1109 1110 boundary: String, 1110 1111 chunk_size: Int, 1111 1112 quota: Int, 1112 - append: fn(t, BitString) -> Result(t, Response), 1113 + append: fn(t, BitArray) -> Result(t, Response), 1113 1114 data: t, 1114 1115 ) -> Result(#(Option(BufferedReader), Int, t), Response) { 1115 1116 use #(chunk, reader) <- result.try(read_chunk(reader, chunk_size)) 1116 - let size_read = bit_string.byte_size(chunk) 1117 + let size_read = bit_array.byte_size(chunk) 1117 1118 use output <- result.try(parse(chunk)) 1118 1119 1119 1120 case output { 1120 1121 http.MultipartBody(parsed, done, remaining) -> { 1121 1122 // Decrement the quota by the number of bytes consumed. 1122 - let used = size_read - bit_string.byte_size(remaining) - 2 1123 + let used = size_read - bit_array.byte_size(remaining) - 2 1123 1124 let used = case done { 1124 1125 // If this is the last chunk, we need to account for the boundary. 1125 1126 True -> used - 4 - string.byte_size(boundary) ··· 1171 1172 fn read_chunk( 1172 1173 reader: BufferedReader, 1173 1174 chunk_size: Int, 1174 - ) -> Result(#(BitString, Reader), Response) { 1175 + ) -> Result(#(BitArray, Reader), Response) { 1175 1176 buffered_read(reader, chunk_size) 1176 1177 |> result.replace_error(bad_request()) 1177 1178 |> result.try(fn(chunk) { ··· 1184 1185 1185 1186 fn multipart_headers( 1186 1187 reader: BufferedReader, 1187 - parse: fn(BitString) -> Result(http.MultipartHeaders, Response), 1188 + parse: fn(BitArray) -> Result(http.MultipartHeaders, Response), 1188 1189 chunk_size: Int, 1189 1190 quotas: Quotas, 1190 1191 ) -> Result(#(List(http.Header), BufferedReader, Quotas), Response) { ··· 1193 1194 1194 1195 case headers { 1195 1196 http.MultipartHeaders(headers, remaining) -> { 1196 - let used = bit_string.byte_size(chunk) - bit_string.byte_size(remaining) 1197 + let used = bit_array.byte_size(chunk) - bit_array.byte_size(remaining) 1197 1198 use quotas <- result.map(decrement_body_quota(quotas, used)) 1198 1199 let reader = BufferedReader(reader, remaining) 1199 1200 #(headers, reader, quotas) ··· 1576 1577 /// 1577 1578 pub fn random_string(length: Int) -> String { 1578 1579 crypto.strong_random_bytes(length) 1579 - |> base.url_encode64(False) 1580 + |> bit_array.base64_url_encode(False) 1580 1581 |> string.slice(0, length) 1581 1582 } 1582 1583 ··· 1591 1592 /// 1592 1593 pub fn sign_message( 1593 1594 request: Request, 1594 - message: BitString, 1595 + message: BitArray, 1595 1596 algorithm: crypto.HashAlgorithm, 1596 1597 ) -> String { 1597 1598 crypto.sign_message(message, <<request.body.secret_key_base:utf8>>, algorithm) ··· 1608 1609 pub fn verify_signed_message( 1609 1610 request: Request, 1610 1611 message: String, 1611 - ) -> Result(BitString, Nil) { 1612 + ) -> Result(BitArray, Nil) { 1612 1613 crypto.verify_signed_message(message, <<request.body.secret_key_base:utf8>>) 1613 1614 } 1614 1615 ··· 1664 1665 max_age: option.Some(max_age), 1665 1666 ) 1666 1667 let value = case security { 1667 - PlainText -> base.encode64(<<value:utf8>>, False) 1668 + PlainText -> bit_array.base64_encode(<<value:utf8>>, False) 1668 1669 Signed -> sign_message(request, <<value:utf8>>, crypto.Sha512) 1669 1670 } 1670 1671 response ··· 1702 1703 |> list.key_find(name), 1703 1704 ) 1704 1705 use value <- result.try(case security { 1705 - PlainText -> base.decode64(value) 1706 + PlainText -> bit_array.base64_decode(value) 1706 1707 Signed -> verify_signed_message(request, value) 1707 1708 }) 1708 - bit_string.to_string(value) 1709 + bit_array.to_string(value) 1709 1710 } 1710 1711 1711 1712 // ··· 1719 1720 /// `wisp/testing` module instead. 1720 1721 /// 1721 1722 pub fn create_canned_connection( 1722 - body: BitString, 1723 + body: BitArray, 1723 1724 secret_key_base: String, 1724 1725 ) -> Connection { 1725 1726 make_connection(
+3 -3
src/wisp/internal/logger.gleam
··· 1 - import gleam/map.{Map} 2 - import gleam/erlang/atom.{Atom} 3 - import gleam/dynamic.{Dynamic} 1 + import gleam/map.{type Map} 2 + import gleam/erlang/atom.{type Atom} 3 + import gleam/dynamic.{type Dynamic} 4 4 5 5 pub type LogLevel { 6 6 Emergency
+8 -8
src/wisp/testing.gleam
··· 1 - import gleam/base 2 - import gleam/bit_builder 1 + import gleam/bit_array 2 + import gleam/bytes_builder 3 3 import gleam/crypto 4 4 import gleam/http 5 5 import gleam/http/request 6 - import gleam/json.{Json} 6 + import gleam/json.{type Json} 7 7 import gleam/option.{None, Some} 8 8 import gleam/string 9 9 import gleam/string_builder 10 10 import gleam/uri 11 11 import simplifile 12 - import wisp.{Empty, File, Request, Response, Text} 12 + import wisp.{type Request, type Response, Empty, File, Text} 13 13 14 14 /// The default secret key base used for test requests. 15 15 /// This should never be used outside of tests. ··· 30 30 method: http.Method, 31 31 path: String, 32 32 headers: List(http.Header), 33 - body: BitString, 33 + body: BitArray, 34 34 ) -> Request { 35 35 let #(path, query) = case string.split(path, "?") { 36 36 [path, query] -> #(path, Some(query)) ··· 242 242 /// This function will panic if the response body is a file and the file cannot 243 243 /// be read. 244 244 /// 245 - pub fn bit_string_body(response: Response) -> BitString { 245 + pub fn bit_array_body(response: Response) -> BitArray { 246 246 case response.body { 247 247 Empty -> <<>> 248 248 Text(builder) -> 249 - bit_builder.to_bit_string(bit_builder.from_string_builder(builder)) 249 + bytes_builder.to_bit_array(bytes_builder.from_string_builder(builder)) 250 250 File(path) -> { 251 251 let assert Ok(contents) = simplifile.read_bits(path) 252 252 contents ··· 276 276 security: wisp.Security, 277 277 ) -> Request { 278 278 let value = case security { 279 - wisp.PlainText -> base.encode64(<<value:utf8>>, False) 279 + wisp.PlainText -> bit_array.base64_encode(<<value:utf8>>, False) 280 280 wisp.Signed -> wisp.sign_message(req, <<value:utf8>>, crypto.Sha512) 281 281 } 282 282 request.set_cookie(req, name, value)
+6 -6
test/wisp/testing_test.gleam
··· 507 507 |> should.equal("Hello, Joe!") 508 508 } 509 509 510 - pub fn bit_string_body_empty_test() { 510 + pub fn bit_array_body_empty_test() { 511 511 wisp.ok() 512 512 |> response.set_body(wisp.Empty) 513 - |> testing.bit_string_body 513 + |> testing.bit_array_body 514 514 |> should.equal(<<>>) 515 515 } 516 516 517 - pub fn bit_string_body_file_test() { 517 + pub fn bit_array_body_file_test() { 518 518 wisp.ok() 519 519 |> response.set_body(wisp.File("test/fixture.txt")) 520 - |> testing.bit_string_body 520 + |> testing.bit_array_body 521 521 |> should.equal(<<"Hello, Joe!\n":utf8>>) 522 522 } 523 523 524 - pub fn bit_string_body_text_test() { 524 + pub fn bit_array_body_text_test() { 525 525 wisp.ok() 526 526 |> response.set_body(wisp.Text(string_builder.from_string("Hello, Joe!"))) 527 - |> testing.bit_string_body 527 + |> testing.bit_array_body 528 528 |> should.equal(<<"Hello, Joe!":utf8>>) 529 529 } 530 530
+3 -3
test/wisp_test.gleam
··· 1 - import gleam/base 1 + import gleam/bit_array 2 2 import gleam/crypto 3 - import gleam/dynamic.{Dynamic} 3 + import gleam/dynamic.{type Dynamic} 4 4 import gleam/erlang 5 5 import gleam/http 6 6 import gleam/http/request ··· 997 997 use _ <- list.each(list.repeat(1, 10_000)) 998 998 let message = 999 999 <<int.to_string(int.random(0, 1_000_000_000_000_000)):utf8>> 1000 - |> base.encode64(True) 1000 + |> bit_array.base64_encode(True) 1001 1001 let req = testing.get("/", []) 1002 1002 let signed = wisp.sign_message(req, <<message:utf8>>, crypto.Sha512) 1003 1003 let req = testing.get("/", [#("cookie", "message=" <> signed)])