Skip to content

Commit

Permalink
Since http_server PR#74, Content-Length is mandatory unless Chunked.
Browse files Browse the repository at this point in the history
If you don't provide it, http_server uses the value 0, and your data
goes away.
  • Loading branch information
redvers committed Jan 3, 2025
1 parent 0a192aa commit c8ffe1d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion examples/basicauth/main.pony
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ actor Main

let handler =
{(ctx: Context): Context iso^ =>
ctx.respond(StatusResponse(StatusOK), "Hello!".array())
ctx.respond(
StatusResponse(
StatusOK,
[("Content-Length", "6")]
),
"Hello!".array()
)
consume ctx
}

Expand Down
8 changes: 7 additions & 1 deletion examples/params/main.pony
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@ primitive H is RequestHandler
"".join(
[ "Hello"; if name != "" then " " + name else "" end; "!"
].values()).array()
ctx.respond(StatusResponse(StatusOK), body)
ctx.respond(
StatusResponse(
StatusOK,
[("Content-Length", body.size().string())]
),
body
)
consume ctx
16 changes: 14 additions & 2 deletions jennet/fileserver.pony
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ class _FileServer is RequestHandler
bs = bs + consume line
end
end
ctx.respond(StatusResponse(StatusOK), bs)
ctx.respond(
StatusResponse(
StatusOK,
[("Content-Length", bs.size().string())]
),
bs
)
else
ctx.respond(StatusResponse(StatusNotFound))
end
Expand All @@ -37,7 +43,13 @@ class _DirServer is RequestHandler
bs = bs + consume line
end
end
ctx.respond(StatusResponse(StatusOK), bs)
ctx.respond(
StatusResponse(
StatusOK,
[("Content-Length", bs.size().string())]
),
bs
)
else
ctx.respond(StatusResponse(StatusNotFound))
end
Expand Down

0 comments on commit c8ffe1d

Please sign in to comment.