Skip to content

Added GET_OR_HEAD method.#2555

Merged
tomakehurst merged 2 commits intowiremock:masterfrom
prithvitewatia:gh-2414
Jan 9, 2024
Merged

Added GET_OR_HEAD method.#2555
tomakehurst merged 2 commits intowiremock:masterfrom
prithvitewatia:gh-2414

Conversation

@prithvitewatia
Copy link
Copy Markdown
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

RequestMethod that = (RequestMethod) o;

if (name.equals("GET_OR_HEAD") && (that.name.equals("GET") || that.name.equals("HEAD"))) {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@tomakehurst
Copy link
Copy Markdown
Member

Thanks!

@prithvitewatia prithvitewatia deleted the gh-2414 branch January 11, 2024 08:07
@leeturner leeturner mentioned this pull request Feb 5, 2024
7 tasks
josetruta pushed a commit to grupo5-ES-2025-1/wiremock that referenced this pull request Aug 31, 2025
* Added GET_OR_HEAD method

* Added validations for Content-Length
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