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

Support of headers to 'HttpJsonRequest'. Adding 'Connection: close' header while pinging workspace agent #7898

Merged
merged 1 commit into from
Dec 18, 2017

Conversation

ibuziuk
Copy link
Member

@ibuziuk ibuziuk commented Dec 15, 2017

What does this PR do?

Adding support of headers to 'HttpJsonRequest'
Adding 'Connection: close' header while pinging workspace agent
Details in redhat-developer/rh-che#479 (comment)

Image used for verification on osio - ibuziuk/che-server:connection-close

What issues does this PR fix or reference?

redhat-developer/rh-che#479

Adding support of headers to 'HttpJsonRequest'

Release Notes

Adding support of headers to 'HttpJsonRequest'

@codenvy-ci
Copy link

Can one of the admins verify this patch?

@ibuziuk
Copy link
Member Author

ibuziuk commented Dec 15, 2017

ci-test

@codenvy-ci
Copy link

Can one of the admins verify this patch?

Copy link

@garagatyi garagatyi left a comment

Choose a reason for hiding this comment

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

Looks good. Can you take a look at my comments?

@@ -118,6 +121,16 @@ public HttpJsonRequest addQueryParam(@NotNull String name, @NotNull Object value
return this;
}

public HttpJsonRequest addRequestHeader(@NotNull String name, @NotNull String value) {

Choose a reason for hiding this comment

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

Consider renaming to addHeader. We can not add response header to a request.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, lemme do it

requireNonNull(name, "Required non-null header name");
requireNonNull(value, "Required non-null header value");
if (headers == null) {
headers = new ArrayList<>(DEFAULT_HEADERS_LIST_SIZE);

Choose a reason for hiding this comment

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

Can you elaborate on why you have decided to have this 5 as a default value instead of letting default constructor do his job?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have decided not to break existing design of the class (see impl. of query params), I think we can safely remove this param for both lists. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

as I understand it was mainly done in order to reduce the initial capacity and avoid recreating array in most cases. Maybe also typical number of query params used in che = 5 ? Anyway, probably the performance impact seems to be insufficient and we might just opt for using default capacity for both query params / headers?

Choose a reason for hiding this comment

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

Yeah, it was definitely an optimization. And author might add a comment to that value to clarify that.
I opt for leaving it with default settings.

Choose a reason for hiding this comment

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

I mean header related one. Let's leave query params optimisation as is

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds good - PR has been updated

@@ -202,6 +216,15 @@ protected DefaultHttpJsonResponse doRequest(
final HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setConnectTimeout(timeout > 0 ? timeout : 60000);
conn.setReadTimeout(timeout > 0 ? timeout : 60000);

final boolean hasHeaders = headers != null && !headers.isEmpty();

Choose a reason for hiding this comment

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

Can you inline this into if clause?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have decided not to break existing design of the class (see processing of query params above). I can rework both if needed ?

Choose a reason for hiding this comment

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

you are free to use the style of code you want as long as it doesn't make the code inefficient or too complex (probably empirical for maintainers values ;) ).
So my comment about this line is just matter of my taste )
Feel free to do as you want here.
And since I approved the PR in the initial state I was OK to merge it at that stage, my comments were just insignificant details.

Copy link
Contributor

Choose a reason for hiding this comment

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

can we initialise headers = new ArrayList<>() in constructor to not to have if (headers == null) { all other the code.

Copy link
Member Author

@ibuziuk ibuziuk Dec 16, 2017

Choose a reason for hiding this comment

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

@skabashnyuk I'm quite sure that the initial designer of the class who seems to be really keen on performance and even used custom capacity[1] for query list initialization would like this idea. Basically, the rule of thumb for such cases is either do a massive refactoring or follow the design that is already in place e.g [2] (even if you think it is not smth. you would normally do if implementing from scratch)

[1] https://github.com/eclipse/che/pull/7898/files#diff-570b40ab3f5e69b575585ffb160ef3b5L115
[2] https://github.com/eclipse/che/pull/7898/files#diff-570b40ab3f5e69b575585ffb160ef3b5R201

Choose a reason for hiding this comment

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

+1 to what @ibuziuk said

@ibuziuk ibuziuk force-pushed the rh-che-479 branch 2 times, most recently from be23079 to 315652c Compare December 15, 2017 14:45
…eader while pinging workspace agent

Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
@benoitf
Copy link
Contributor

benoitf commented Dec 15, 2017

ci-build

@codenvy-ci
Copy link

@skabashnyuk
Copy link
Contributor

ci-test

@codenvy-ci
Copy link

@skabashnyuk
Copy link
Contributor

@ibuziuk can you make che6 pr aswell?

@ibuziuk
Copy link
Member Author

ibuziuk commented Dec 17, 2017

@skabashnyuk sure I will ;-)

@ibuziuk ibuziuk merged commit 9c52742 into eclipse-che:master Dec 18, 2017
@benoitf benoitf added this to the 5.23.0 milestone Dec 18, 2017
@benoitf benoitf added the kind/bug Outline of a bug - must adhere to the bug report template. label Dec 18, 2017
@ibuziuk
Copy link
Member Author

ibuziuk commented Dec 19, 2017

PR for che6 #7949

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Outline of a bug - must adhere to the bug report template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants