···11import exception
22import gleam/bit_array
33import gleam/bool
44-import gleam/bytes_builder.{type BytesBuilder}
44+import gleam/bytes_tree.{type BytesTree}
55import gleam/crypto
66import gleam/dict.{type Dict}
77import gleam/dynamic.{type Dynamic}
···1919import gleam/option.{type Option}
2020import gleam/result
2121import gleam/string
2222-import gleam/string_builder.{type StringBuilder}
2222+import gleam/string_tree.{type StringTree}
2323import gleam/uri
2424import logging
2525import marceau
···3535pub type Body {
3636 /// A body of unicode text.
3737 ///
3838- /// The body is represented using a `StringBuilder`. If you have a `String`
3939- /// you can use the `string_builder.from_string` function to convert it.
3838+ /// The body is represented using a `StringTree`. If you have a `String`
3939+ /// you can use the `string_tree.from_string` function to convert it.
4040 ///
4141- Text(StringBuilder)
4141+ Text(StringTree)
4242 /// A body of binary data.
4343 ///
4444- /// The body is represented using a `BytesBuilder`. If you have a `BitArray`
4545- /// you can use the `bytes_builder.from_bit_array` function to convert it.
4444+ /// The body is represented using a `BytesTree`. If you have a `BitArray`
4545+ /// you can use the `bytes_tree.from_bit_array` function to convert it.
4646 ///
4747- Bytes(BytesBuilder)
4747+ Bytes(BytesTree)
4848 /// A body of the contents of a file.
4949 ///
5050 /// This will be sent efficiently using the `send_file` function of the
···146146/// # Examples
147147///
148148/// ```gleam
149149+/// let content = bytes_tree.from_string("Hello, Joe!")
149150/// response(200)
150150-/// |> file_download_from_memory(named: "myfile.txt", containing: "Hello, Joe!")
151151+/// |> file_download_from_memory(named: "myfile.txt", containing: content)
151152/// // -> Response(
152153/// // 200,
153154/// // [#("content-disposition", "attachment; filename=\"myfile.txt\"")],
···158159pub fn file_download_from_memory(
159160 response: Response,
160161 named name: String,
161161- containing data: BytesBuilder,
162162+ containing data: BytesTree,
162163) -> Response {
163164 let name = uri.percent_encode(name)
164165 response
···177178/// # Examples
178179///
179180/// ```gleam
180180-/// let body = string_builder.from_string("<h1>Hello, Joe!</h1>")
181181+/// let body = string_tree.from_string("<h1>Hello, Joe!</h1>")
181182/// html_response(body, 200)
182183/// // -> Response(200, [#("content-type", "text/html")], Text(body))
183184/// ```
184185///
185185-pub fn html_response(html: StringBuilder, status: Int) -> Response {
186186+pub fn html_response(html: StringTree, status: Int) -> Response {
186187 HttpResponse(
187188 status,
188189 [#("content-type", "text/html; charset=utf-8")],
···198199/// # Examples
199200///
200201/// ```gleam
201201-/// let body = string_builder.from_string("{\"name\": \"Joe\"}")
202202+/// let body = string_tree.from_string("{\"name\": \"Joe\"}")
202203/// json_response(body, 200)
203204/// // -> Response(200, [#("content-type", "application/json")], Text(body))
204205/// ```
205206///
206206-pub fn json_response(json: StringBuilder, status: Int) -> Response {
207207+pub fn json_response(json: StringTree, status: Int) -> Response {
207208 HttpResponse(
208209 status,
209210 [#("content-type", "application/json; charset=utf-8")],
···219220/// # Examples
220221///
221222/// ```gleam
222222-/// let body = string_builder.from_string("<h1>Hello, Joe!</h1>")
223223+/// let body = string_tree.from_string("<h1>Hello, Joe!</h1>")
223224/// response(201)
224225/// |> html_body(body)
225226/// // -> Response(201, [#("content-type", "text/html; charset=utf-8")], Text(body))
226227/// ```
227228///
228228-pub fn html_body(response: Response, html: StringBuilder) -> Response {
229229+pub fn html_body(response: Response, html: StringTree) -> Response {
229230 response
230231 |> response.set_body(Text(html))
231232 |> response.set_header("content-type", "text/html; charset=utf-8")
···239240/// # Examples
240241///
241242/// ```gleam
242242-/// let body = string_builder.from_string("{\"name\": \"Joe\"}")
243243+/// let body = string_tree.from_string("{\"name\": \"Joe\"}")
243244/// response(201)
244245/// |> json_body(body)
245246/// // -> Response(201, [#("content-type", "application/json; charset=utf-8")], Text(body))
246247/// ```
247248///
248248-pub fn json_body(response: Response, json: StringBuilder) -> Response {
249249+pub fn json_body(response: Response, json: StringTree) -> Response {
249250 response
250251 |> response.set_body(Text(json))
251252 |> response.set_header("content-type", "application/json; charset=utf-8")
252253}
253254254254-/// Set the body of a response to a given string builder.
255255+/// Set the body of a response to a given string tree.
255256///
256257/// You likely want to also set the request `content-type` header to an
257258/// appropriate value for the format of the content.
···259260/// # Examples
260261///
261262/// ```gleam
262262-/// let body = string_builder.from_string("Hello, Joe!")
263263+/// let body = string_tree.from_string("Hello, Joe!")
263264/// response(201)
264264-/// |> string_builder_body(body)
265265+/// |> string_tree_body(body)
265266/// // -> Response(201, [], Text(body))
266267/// ```
267268///
268268-pub fn string_builder_body(
269269- response: Response,
270270- content: StringBuilder,
271271-) -> Response {
269269+pub fn string_tree_body(response: Response, content: StringTree) -> Response {
272270 response
273271 |> response.set_body(Text(content))
274272}
275273276276-/// Set the body of a response to a given string builder.
274274+/// Set the body of a response to a given string.
277275///
278276/// You likely want to also set the request `content-type` header to an
279277/// appropriate value for the format of the content.
···287285/// // -> Response(
288286/// // 201,
289287/// // [],
290290-/// // Text(string_builder.from_string("Hello, Joe"))
288288+/// // Text(string_tree.from_string("Hello, Joe"))
291289/// // )
292290/// ```
293291///
294292pub fn string_body(response: Response, content: String) -> Response {
295293 response
296296- |> response.set_body(Text(string_builder.from_string(content)))
294294+ |> response.set_body(Text(string_tree.from_string(content)))
297295}
298296299297/// Escape a string so that it can be safely included in a HTML document.
···14751473 http.Get, True -> {
14761474 let path =
14771475 path
14781478- |> string.drop_left(string.length(prefix))
14761476+ |> string.drop_start(string.length(prefix))
14791477 |> string.replace(each: "..", with: "")
14801478 |> internal.join_path(directory, _)
14811479