[web-devel] Type-safe URL handling

Jeremy Shaw jeremy at n-heptane.com
Fri Mar 19 18:41:55 EDT 2010


On Fri, Mar 19, 2010 at 5:22 PM, Michael Snoyman <michael at snoyman.com>wrote:

> I am not going to have time to look at this again until Saturday or Sunday.
>> There are a few minor details that have been swept under the rug that need
>> to be addressed. For example, when exactly does should url encoding /
>> decoding take place. It's not good if that happens twice or not at all.
>>
>>
>> Just to confuse the topic even more: if we do real URL encoding/decoding,
> I believe we would have to assume a certain character set. I had to deal
> with a site that was encoded in non-UTF8 just a bit ago, and dealing with
> query parameters is not fun.
>
> That said, perhaps we should consider making the type of PathInfo "PathInfo
> ByteString" so we make it clear that we're doing no character encoding.
>

Yeah. I dunno. I just know it needs to be solved :)


> Another issue in the same vein is dealing with leading and trailing
> slashes, though I think this is fairly simple in practice: the web app knows
> what to do about the trailing slashes, and each plugin should always pass a
> leading slash.
>

I am not quite sure what you mean 'each plugin should always pass a leading
slash'. Pass to whom?

If we have:

MySite = MyHome    | MyBlog Blog
MyBlog = BlogHome | BlogPost String

Then I would expect something like this:

formatMySite MyHome = "MyHome"
formatMySite (MyBlog blog) = "MyBlog/" ++ formatMyBlog blog

formatMyBlog BlogHome = "BlogHome"
formatMyBlog (BlogPost title) = "BlogPost/" ++ title

mkAbs = ("http://localhost:3000/" ++)

(ignoring any escaping  that needs to happen in title, and ignoring an
AbsPath / PathInfo stuff).

But we could, of course, do it the other way:


formatMySite MyHome = "/MyHome"
formatMySite (MyBlog blog) = "/MyBlog" ++ formatMyBlog blog

formatMyBlog BlogHome = "/BlogHome"
formatMyBlog (BlogPost title) = "/BlogPost/" ++ title

mkAbs = ("http://localhost:3000" ++)

There definitely needs to be some policy.

- jeremy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/web-devel/attachments/20100319/1594b541/attachment.html


More information about the web-devel mailing list