swhitty/FlyingFox

URLs with spaces do not work

wirrareka opened this issue ยท 6 comments

Hello,

for one of my usecases i need url which uses percent encoded spaces, eg: http://host/some%20folder,
currently such url wont get matched and handled, far from ideal but i got around it for now by editing HTTPDecoder and replacing the "%20" with "+", then i get the route matched and handle it accordingly.


let comps = status
            .trimmingCharacters(in: .whitespacesAndNewlines)
            .replacingOccurrences(of: "%20", with: "+")
            .split(separator: " ", maxSplits: 2, omittingEmptySubsequences: false)

any ideas on how to solve it nicely?

thanks for the great work!

If you include the URL escaping within route it should work.

server.appendRoute("/some%20folder") { _ in
  HTTPResponse(
    statusCode: .ok,
    headers: [.contentType: "text/plain; charset=UTF-8"],
    body: "๐Ÿ“‚".data(using: .utf8)!
  )
}

You can successfully request it via curl:

% curl localhost/some%20folder
๐Ÿ“‚

Are you wanting to include spaces in the route and have it automatically escaped and matched with %20 ? That would be a nice feature.

server.appendRoute("/some folder")

the problem is i'm trying to match the route with wildcard, its a directory with custom handler and path specified as "GET /fonts/*", but the actual requests are /fonts/Font%20Name/whatever. I could add iterating over the subfolders and files and adding the route handlers from there, but that seems like even trickier workaround :)

I see, it's definitely a bug โ€” The scenario I posted above works because both HTTPDecoder and HTTPRoute include the same bug and parse the path as "" so it matches ๐Ÿ™ƒ

I'll take a deeper look

Fixed on main branch by #75

great, thanks a lot for the quick fix!
is there any eta for new pod release ?

0.13.0 was just released. ๐Ÿ™๐Ÿป