-
Notifications
You must be signed in to change notification settings - Fork 355
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
allow empty responses #606
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion needed on support for q-factor in Accept header and empty content in invalid requests.
* chore: upgrade jsf * test: add e2e * chore: switch back to npm version * docs: changelog * test: dry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped some comments. The code flow is still not clear but hopefully it'll be better after addressing these comments.
@XVincentX, I believe the feedback is addressed now, ready for another round |
@lag-of-death Can you rebase when you get a chance? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped some other comments but in general I think we're getting close to the end of this 👍
packages/http/src/mocker/negotiator/__tests__/NegotiatorHelpers.spec.ts
Outdated
Show resolved
Hide resolved
@@ -7,6 +7,8 @@ swagger: "2.0" | |||
paths: | |||
/todos: | |||
get: | |||
produces: | |||
- text/plain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped another bunch of comments. We're getting there but I am already anticipating this is going to require yet another round of review.
Either.fromOption(() => { | ||
logger.warn(warnMsg(mediaTypes)); | ||
|
||
return ProblemJsonError.fromTemplate( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right; this does not feel right but I might be the dude introducing this so I'll look into. Why the cast though? as Error
return Either.left<Error, IHttpNegotiationResult>( | ||
ProblemJsonError.fromTemplate(NOT_ACCEPTABLE, `Unable to find content for ${mediaTypes}`), | ||
return pipe( | ||
optionallyGetPayloadlessResponse(response, headers || [], mediaTypes), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findEmptyResponse
const noAcceptAndNoContentResponses = | ||
!noContentResponses.length && !mediaTypes.filter((mt: string) => !mt.includes('*/*')).length; | ||
|
||
return noAcceptAndNoContentResponses || ['400', '422'].includes(response.code); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you checking for 400 and 422 responses manually? Don't they follow the same flow?
Option.chain(responses => { | ||
return Option.fromPredicate((noContentResponses: { length: number }) => { | ||
const noAcceptAndNoContentResponses = | ||
!noContentResponses.length && !mediaTypes.filter((mt: string) => !mt.includes('*/*')).length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really think we should put a comment on this condition, I still struggle to understand it correctly.
Also, with includes Accept: application/json,*/*
will match. Is this intentional? I guess so (if the client accepts / then an empty response is viable, right?)
packages/http/src/mocker/negotiator/__tests__/NegotiatorHelpers.spec.ts
Outdated
Show resolved
Hide resolved
Co-Authored-By: Vincenzo Chianese <vincenz.chianese@icloud.com>
hi @XVincentX, I think I've addressed the feedback. The logic for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're finally there. Just one final change (pipe for fromPredicate); I'm checking out the tests but quite sure we'll merge this today.
mediaTypes: string[], | ||
): Option.Option<IHttpNegotiationResult> => { | ||
return pipe( | ||
Option.fromPredicate((contentTypes: string[]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pipe(mediaTypes, Option.fromPredicate(…), Option.map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We got this. Excellent test coverage.
Fixes #584
Fixes #592
Checklist
What kind of change does this PR introduce?
Bug fix.
What is the current behavior? What is the new behavior?
No empty responses were allowed.