Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URLs with spaces do not work #74

Closed
wirrareka opened this issue Nov 22, 2023 · 6 comments · Fixed by #75
Closed

URLs with spaces do not work #74

wirrareka opened this issue Nov 22, 2023 · 6 comments · Fixed by #75

Comments

@wirrareka
Copy link

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!

@swhitty
Copy link
Owner

swhitty commented Nov 22, 2023

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")

@wirrareka
Copy link
Author

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 :)

@swhitty
Copy link
Owner

swhitty commented Nov 22, 2023

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

@swhitty
Copy link
Owner

swhitty commented Nov 23, 2023

Fixed on main branch by #75

@wirrareka
Copy link
Author

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

@swhitty
Copy link
Owner

swhitty commented Nov 24, 2023

0.13.0 was just released. 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants