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

#70: HTTP Stubbing: URL matcher incorrectly strips port when using "ignore query parameters" option #74

Merged
merged 2 commits into from
Nov 27, 2022

Conversation

malcommac
Copy link
Collaborator

The following PR fixes the HTTPStubber with match(URL:) which specify both the host along with an explicit port. IN this case the host property of URL ignores the port returning only the host.
The result is a failure in matches() function which, incorrectly, return false.

This is an example:

let stub = HTTPStubRequest()
  match(URL: URL(string: "http://localhost:3001/some/path")!)
  .stub(for: .get) { _, _ in
    let response = HTTPStubResponse()
    response.statusCode = .ok
    return response
}
        
let matches = stub.matchers[0].matches(request: URLRequest(url: URL(string: "http://localhost:3001/some/path")!), for: stub)

In order to fix it we added a new a new fullHost property in URL which also consider the URL.
A test case is also added.

@malcommac malcommac added the bug Something isn't working label Nov 27, 2022
@malcommac malcommac added this to the 1.8.0 milestone Nov 27, 2022
@malcommac malcommac self-assigned this Nov 27, 2022
@malcommac malcommac merged commit 51697c0 into main Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant