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

fixes #468: Dialogue clients send Accept headers #482

Merged
merged 4 commits into from
Mar 4, 2020

Conversation

carterkozak
Copy link
Contributor

Before this PR

  1. Clients violate the conjure specification by excluding Accept headers.
  2. Endpoints which return binary failed to parse errors, instead producing an illegal argument exception "Unsupported Content-Type" (with no response status check).

After this PR

==COMMIT_MSG==
Dialogue clients send Accept headers
==COMMIT_MSG==

Possible downsides?

api churn

@changelog-app
Copy link

changelog-app bot commented Mar 4, 2020

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Dialogue clients send Accept headers

Check the box to generate changelog(s)

  • Generate changelog entry

carterkozak added a commit to palantir/conjure-java that referenced this pull request Mar 4, 2020
@carterkozak carterkozak changed the title Dialogue clients send Accept headers fixes #468: Dialogue clients send Accept headers Mar 4, 2020
*/
InputStream deserializeInputStream(Response response);
@Deprecated
default InputStream deserializeInputStream(Response response) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just get rid of this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

our circular dependency on generated code would break

private static Request accepting(Request original, String acceptValue) {
Preconditions.checkNotNull(acceptValue, "Accept value is required");
Preconditions.checkState(!acceptValue.isEmpty(), "Accept value must not be empty");
if (original.headerParams().containsKey(HttpHeaders.ACCEPT)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we append the acceptValue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, we'd need to deduplicate repeated accept values, and the existing values will be preferred since we're using a list, which isn't what we want here. I considered throwing instead of logging but it's difficult to trace where the value was added (unlike the null/empty inputs) so we would want to return a future.

@@ -177,6 +172,11 @@ public T deserialize(Response response) {
}
}

@Override
public Optional<String> accepts() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of joining the separate accept headers into a single string should we expose a List<String>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this initially, but found that it maps to adding multiple Accept headers each with a single value, but it's most common to use Accept header with multiple values. The optional approach allows us to pre-calculate the value.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems surprising to encode multiple accept values as a header value since in a multimap set up I would expect each value in the map to be a single header value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I completely agree that multiple accept header key/value pairs would be clean, but I don't think I've seen it used that way in practice. I think we'll reduce odd edge case failures by following the principle of least astonishment.

…e/serde/DefaultClientsTest.java

Co-Authored-By: Felipe Orozco <ferozco@users.noreply.github.com>
@ferozco
Copy link
Contributor

ferozco commented Mar 4, 2020

👍

@bulldozer-bot bulldozer-bot bot merged commit c82e44e into develop Mar 4, 2020
@bulldozer-bot bulldozer-bot bot deleted the ckozak/accept branch March 4, 2020 20:00
@svc-autorelease
Copy link
Collaborator

Released 0.13.1

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

Successfully merging this pull request may close these issues.

3 participants