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

fix: add 201 Created to status codes #297

Merged
merged 3 commits into from
Dec 17, 2022

Conversation

mtiller
Copy link
Contributor

@mtiller mtiller commented Feb 8, 2022

The Location header is also used by the 201 Created status code. But the currently logic filters out the information provided in ctx.meta.$location if I return ctx.meta.$statusCode = 201. This should not happen. The Location header is essential in a 201 Created response. I've changed to logic so that 201 is included in the status codes that passthrough ctx.meta.$location to the Location header.

The `Location` header is _also_ used by the `201 Created` status code.  But the currently logic filters out the information provided in `ctx.meta.$location` if I return `ctx.meta.$statusCode = 201`.  This should not happen.  The `Location` header is essential in a `201 Created` response.  I've changed to logic so that `201` is included in the status codes that passthrough `ctx.meta.$location` to the `Location` header.
Copy link
Member

@icebob icebob left a comment

Choose a reason for hiding this comment

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

Great, please add relevant tests, as well.

A `201 Created` response should include the location of the new resource.
Ensure the `$location` value is properly handled for a `201 Created` response.
@icebob icebob merged commit cd4b63c into moleculerjs:master Dec 17, 2022
@icebob
Copy link
Member

icebob commented Dec 17, 2022

@mtiller sorry for being late but I don't get emails about new commits, just comments.

@thib3113
Copy link
Contributor

thib3113 commented Dec 1, 2023

Hello @mtiller / @icebob .

Some questions about this change .

Actually, the spec doesn't restrict the use of the Location header . So every status code can use it .

Also, about the 201 code, the specification says :

The primary resource created by the request is identified by either a Location header field in the response or, if no Location header field is received, by the target URI

so the warning on https://github.com/moleculerjs/moleculer-web/pull/297/files#diff-bfe9874d239014961b1ae4e89875a6155667db834a410aaaa2ebe3cf89820556R707 is not relevant in this case (nor in others because of the specification, but I can understand that can be interesting for some peoples)

@icebob
Copy link
Member

icebob commented Dec 17, 2023

@thib3113 nice catch, could you create a PR with ignoring the warning in case of 201?

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.

3 participants