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

httpserver: add URI matching #37

Merged
merged 1 commit into from
Aug 5, 2020
Merged

httpserver: add URI matching #37

merged 1 commit into from
Aug 5, 2020

Conversation

csernazs
Copy link
Owner

@csernazs csernazs commented Aug 3, 2020

Extend URI matching functionality which now accepts:

  • a URIPattern object, whose match() method will be called
  • a compiled regexp returned by re.compile(). In this case the
    URI will be matched against the regexp.

In both cases the URI will be an absolute path starting with a slash.

Fixes #34 and #36.

Copy link

@daanklijn daanklijn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

pytest_httpserver/httpserver.py Outdated Show resolved Hide resolved
assert requests.get(httpserver.url_for("/foobar")).json() == {"foo": "bar"}
assert requests.get(httpserver.url_for("/foobaz")).json() == {"foo": "bar"}

assert requests.get(httpserver.url_for("/barfoo")).status_code == 500

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this actually be a 404?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that the server has received an unexpected request and when I created the library I thought that it should be 500 and not 4xx as in this case the client did something not correctly and it should be the proper status (the client may handle the 404, but not the 500).

However, I would implement it again, probably 404 would be more correct as you suggested. But I don't want to break the API.

Extend URI matching functionality which now accepts:

* a URIPattern object, whose match() method will be called
* a compiled regexp returned by re.compile(). In this case the
  URI will be matched against the regexp.

In both cases the URI will be an absolute path starting with a slash.

Fixes #34 and #36.
@csernazs csernazs merged commit b63a55f into master Aug 5, 2020
@csernazs csernazs deleted the wip-zsolt-urimatch branch August 5, 2020 06:39
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 this pull request may close these issues.

Idea: add variable or partial match support in urls
2 participants