tangled
alpha
login
or
join now
keii.dev
/
wisp
3
fork
atom
🧚 A practical web framework for Gleam
3
fork
atom
overview
issues
pulls
pipelines
Update comments
Louis Pilfold
2 years ago
f5d31414
275a1102
+18
-12
2 changed files
expand all
collapse all
unified
split
src
wisp.gleam
test
wisp_test.gleam
+6
-10
src/wisp.gleam
···
126
126
HttpResponse(status, [], Empty)
127
127
}
128
128
129
129
+
// TODO: test
130
130
+
// TODO: document
129
131
pub fn set_body(response: Response, body: ResponseBody) -> Response {
130
132
response
131
133
|> response.set_body(body)
···
353
355
// TODO: don't always return entity to large. Other errors are possible, such as
354
356
// network errors.
355
357
// TODO: document
358
358
+
// TODO: note you probably want a `require_` function
359
359
+
// TODO: note it'll hang if you call it twice
360
360
+
// TODO: note it respects the max body size
356
361
pub fn require_string_body(
357
362
request: Request,
358
363
next: fn(String) -> Response,
···
363
368
}
364
369
}
365
370
366
366
-
// TODO: test
367
367
-
// TODO: public?
368
368
-
// TODO: document
369
369
-
// TODO: note you probably want a `require_` function
370
370
-
// TODO: note it'll hang if you call it twice
371
371
-
// TODO: note it respects the max body size
371
371
+
// Should we make this public?
372
372
fn read_entire_body(request: Request) -> Result(BitString, Nil) {
373
373
let connection = request.body
374
374
read_body_loop(
···
802
802
}
803
803
}
804
804
805
805
-
// TODO: test
806
805
// TODO: document
807
807
-
// TODO: remove requirement for preceeding slash on prefix
808
806
pub fn serve_static(
809
807
req: Request,
810
808
under prefix: String,
···
819
817
path
820
818
|> string.drop_left(string.length(prefix))
821
819
|> string.replace(each: "..", with: "")
822
822
-
|> string.replace(each: "//", with: "/")
823
823
-
|> remove_preceeding_slashes
824
820
|> join_path(directory, _)
825
821
826
822
let mime_type =
+12
-2
test/wisp_test.gleam
···
275
275
|> should.equal(wisp.File("./README.md"))
276
276
}
277
277
278
278
-
pub fn serve_static_under_has_no_preceeding_slash_test() {
278
278
+
pub fn serve_static_under_has_no_trailing_slash_test() {
279
279
let request =
280
280
wisp.test_request(<<>>)
281
281
|> request.set_path("/stuff/README.md")
···
317
317
}
318
318
|> should.equal(wisp.ok())
319
319
}
320
320
-
// TODO: More tests for serve_static!
320
320
+
321
321
+
pub fn serve_static_go_up_test() {
322
322
+
let request =
323
323
+
wisp.test_request(<<>>)
324
324
+
|> request.set_path("/../README.md")
325
325
+
{
326
326
+
use <- wisp.serve_static(request, under: "/stuff", from: "./src/")
327
327
+
wisp.ok()
328
328
+
}
329
329
+
|> should.equal(wisp.ok())
330
330
+
}