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

Added GET_OR_HEAD method. #2555

Merged
merged 2 commits into from
Jan 9, 2024
Merged

Conversation

prithvitewatia
Copy link
Contributor

Closes #2414 . This PR adds a GET_OR_HEAD method. This stub method could be used for both get as well as head Http method. The response and http header information is returned accordingly

Submitter checklist

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected
  • For new features, there's necessary documentation in this pull request or in a subsequent PR to wiremock.org

@prithvitewatia prithvitewatia requested a review from a team as a code owner January 2, 2024 14:16
@@ -75,7 +75,9 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;

RequestMethod that = (RequestMethod) o;

if (name.equals("GET_OR_HEAD") && (that.name.equals("GET") || that.name.equals("HEAD"))) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure doing the equals behaviour this way is a good idea. If we ever needed to put this e.g. as a map key I suspect this would prevent that from working properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tomakehurst Thanks for the feedback. Requested changes have been made.


assertThat(response.statusCode(), is(200));
assertThat(response.firstHeader("Content-Type"), is("application/json"));
assertThat(response.content(), is(emptyOrNullString()));
Copy link
Member

Choose a reason for hiding this comment

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

Would be great to see an assertion about Content-Length matching the length of the response body.

@Mahoney
Copy link
Collaborator

Mahoney commented Jan 2, 2024

I was wondering if it would be worth just getting HEAD requests to match GET mappings by default, if no HEAD mapping matches? Obviously without returning the body...

@tomakehurst
Copy link
Member

I was wondering if it would be worth just getting HEAD requests to match GET mappings by default, if no HEAD mapping matches? Obviously without returning the body...

I did wonder about this, but the GET_OR_HEAD approach felt a bit safer as it's something you're explicitly opting into rather than a subtle change to default behaviour (even if that change is in line with what a lot of web servers will do by default).

@tomakehurst tomakehurst merged commit 5932d3c into wiremock:master Jan 9, 2024
7 checks passed
@tomakehurst
Copy link
Member

Thanks!

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.

GET_OR_HEAD method
3 participants