
I'd like to make an addition to the WAI protocol: a field in the Request data type to track the request body size. I would like this to be: requestBodyLength :: Maybe Word64 I think the choice of Word64 makes sense without further explanation. The perhaps surprising part is the use of `Maybe`. The reason for this is that in the case of a chunked request body, there's no way to know the size of the request body from the headers alone. So the logic for populating this field would go something like: - If content-length is supplied by the user, parse it and populate the field with Just content-length. - If the request is chunked, populate with Nothing. - Otherwise, there is a zero-sized request body, and populate with Just 0. One other idea would be to create a special datatype such as `data RequestBodyLength = ChunkedBody | KnownLength Word64`, but I don't believe it really adds much above the `Maybe Word64`. Any thoughts on this proposal? Note: This is related to Yesod issue: https://github.com/yesodweb/yesod/issues/468

+1 for the idea.
+2 for using a custom data type: it's *much* easier to read.
Cheers,
On Tue, Feb 12, 2013 at 1:06 PM, Michael Snoyman
I'd like to make an addition to the WAI protocol: a field in the Request data type to track the request body size. I would like this to be:
requestBodyLength :: Maybe Word64
I think the choice of Word64 makes sense without further explanation. The perhaps surprising part is the use of `Maybe`. The reason for this is that in the case of a chunked request body, there's no way to know the size of the request body from the headers alone. So the logic for populating this field would go something like:
If content-length is supplied by the user, parse it and populate the field with Just content-length. If the request is chunked, populate with Nothing. Otherwise, there is a zero-sized request body, and populate with Just 0.
One other idea would be to create a special datatype such as `data RequestBodyLength = ChunkedBody | KnownLength Word64`, but I don't believe it really adds much above the `Maybe Word64`.
Any thoughts on this proposal?
Note: This is related to Yesod issue: https://github.com/yesodweb/yesod/issues/468
-- You received this message because you are subscribed to the Google Groups "Yesod Web Framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to yesodweb+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
-- Felipe.

Felipe Almeida Lessa wrote:
+1 for the idea.
+2 for using a custom data type: it's *much* easier to read.
I'm with Felipe on both counts. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

On Tue, Feb 12, 2013 at 11:33 AM, Erik de Castro Lopo
Felipe Almeida Lessa wrote:
+1 for the idea.
+2 for using a custom data type: it's *much* easier to read.
I'm with Felipe on both counts.
Just a casual observations. Using custom types for documentation purposes has some upsides, as we know, but there are also lots of downsides in that you will have to rewrite lots of standard operations (in this case things like fromMaybe, etc). I don't have a hard-and-fast rule, but I tend to try to create new types when they add type safety (although I don't always follow my own advice).

My default used to be using a standard data type and resorting to a
custom one when it seemed that there would be clear advantages. Now
I've switched my default: write a custom data type and, should you
find a compelling reason, refactor into a standard one.
A custom data type isn't helpful just for documentation purposes.
It's also helpful when reading code, and that's where it shines. When
you're in the middle of an application code and you see
case ... of
ChunkedBody -> ...
KnownLength ... -> ...
then you instantly know what it's talking about.
Other advantages:
- Easier to refactor a new case in: just add a new constructor and
fix all warnings.
- Impossible to use on a wrong function.
- It may have some advantage on a yet-to-be-written IDE that could
give some more helpful information when needing to write the code as
well (wink, wink!). Showing documentation about what Nothing and Just
are doesn't help me, and I'd need to somehow fetch the docs of the
record where this field was in... or is it something returned from a
function?
- It seems to me that most of the time you don't really need all
those convenience functions anyway =).
On Tue, Feb 12, 2013 at 5:36 PM, Johan Tibell
On Tue, Feb 12, 2013 at 11:33 AM, Erik de Castro Lopo
wrote: Felipe Almeida Lessa wrote:
+1 for the idea.
+2 for using a custom data type: it's *much* easier to read.
I'm with Felipe on both counts.
Just a casual observations. Using custom types for documentation purposes has some upsides, as we know, but there are also lots of downsides in that you will have to rewrite lots of standard operations (in this case things like fromMaybe, etc). I don't have a hard-and-fast rule, but I tend to try to create new types when they add type safety (although I don't always follow my own advice).
_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel
-- Felipe.
participants (4)
-
Erik de Castro Lopo
-
Felipe Almeida Lessa
-
Johan Tibell
-
Michael Snoyman