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 another newResponse method to address issue 32. #59

Merged
merged 8 commits into from
Dec 28, 2017

Conversation

lducharme
Copy link
Contributor

New method takes a map of strings that allows the caller to specify custom headers.

Also, please feel free to let me know if I've misunderstood anything about this fix or the PR process. Thanks!

…s a map of strings that allows the caller to specify custom headers.
@jkinkead jkinkead self-assigned this Dec 27, 2017
Copy link
Contributor

@jkinkead jkinkead left a comment

Choose a reason for hiding this comment

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

A couple style suggestions.

I think this is great for adding custom headers, but I'd approach CORS in a more direct way.

@@ -107,6 +107,27 @@ public static FullHttpResponse newResponse(
return response;
}

/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be javadoc formatted (/** at start).

* "access-control-allow-origin", "*"
*/
public static FullHttpResponse newResponse(
HttpResponseStatus status, ByteBuf buffer, ContentType contentType, Map<String, String> customHeaders) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a mix of the request content argument being named buffer and being named payload in this file. Would you mind renaming all of them to payload, for consistency & clarity?

*
* Headers should be specified as a map of strings. For example, to allow CORS, add the
* following key and value:
* "access-control-allow-origin", "*"
Copy link
Contributor

Choose a reason for hiding this comment

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

We never want an allowed origin of *.

A better method to handle CORS is to have a configured set of allowed origins (possibly with wildcards), and echo back the request's Origin header as the allowed origin when it matches the configuration.

HttpResponseStatus status, ByteBuf buffer, ContentType contentType, Map<String, String> customHeaders) {
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, buffer);

response.headers().set(CONTENT_TYPE, contentType.value);
Copy link
Contributor

Choose a reason for hiding this comment

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

These should probably go after the header iteration.

Either way, you should document the behavior (customHeaders overrides provided content type + length, or customHeaders content type + length are ignored).

Lauren DuCharme added 3 commits December 27, 2017 11:05
…ayload, to be consistent across all methods
…th could be passed in, leading to confusing behavior. Added an explanatory comment.
@lducharme
Copy link
Contributor Author

Jesse, thanks for the comments! I think I've addressed most of them with the last few commits.

Hmm, that's a good point about there being a better way to handle CORS- this change really is for custom headers, not CORS specifically. I will take a look at implementing that today.

Copy link
Contributor

@jkinkead jkinkead left a comment

Choose a reason for hiding this comment

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

LGTM, one suggestion!

HttpResponseStatus status, ByteBuf buffer, ContentType contentType) {
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, buffer);
HttpResponseStatus status, ByteBuf payload, ContentType contentType) {
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, payload);
Copy link
Contributor

Choose a reason for hiding this comment

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

Update this to use your new method?

// java.util.Maps below.
return newResponse(status, payload, contentType, Maps.emptyMap());

Lauren DuCharme and others added 4 commits December 27, 2017 16:20
… newResponse method with an empty map.

Also added check in case the map parameter is null.
# Conflicts:
#	src/main/java/com/nordstrom/xrpc/server/http/Recipes.java
@lducharme
Copy link
Contributor Author

I fixed the conflict that this request had- what is the next step to merge? @jkinkead

@jkinkead
Copy link
Contributor

I will merge now. :)

@jkinkead jkinkead merged commit 23b1309 into Nordstrom:master Dec 28, 2017
@lducharme lducharme deleted the issue_32 branch January 2, 2018 20:11
@lducharme
Copy link
Contributor Author

I think this change needs to be released before I can pull it in as a dependency in another project, right? If I follow the instructions in CONTRIBUTING.md, can I go ahead and do this?

@jkinkead
Copy link
Contributor

jkinkead commented Jan 2, 2018

If you'd like, yes. Else, either @spenserpothier or myself can run a release.

xjdr added a commit that referenced this pull request Jan 3, 2018
* 'master' of github.com:nordstrom/xrpc:
  Added another newResponse method to address issue 32.  (#59)
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.

2 participants