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

THRIFT-4848: Add ability to set Content-Type,Accept headers in HTTP c… #1801

Closed
wants to merge 2 commits into from
Closed

THRIFT-4848: Add ability to set Content-Type,Accept headers in HTTP c… #1801

wants to merge 2 commits into from

Conversation

ksmithdev
Copy link
Contributor

…lient

Client: netstd
Patch: Kyle Smith

I added the RequestHeaders property that exposes the DefaultRequestHeaders property on the HTTP client instance which allows a developer to set request headers that are not otherwise available using the existing CustomHeaders method. The problem with using CustomHeaders is that it does not allow you to set certain properties (namely Accept). I also added the ContentType property that for specifying the Content-Type request header before sending a request to the server. Our use case is for us to set these headers so that our server can use the correct protocols depending on the clients request.

Other cleanup items include removal of the ConnectTimeout write-only property as the the underlying _connectTimeout field is only ever use on creation, so setting this property was a no-op. I also implemented the OpenAsync and IsOpen fields to work more inline with the other transports.

  • Did you create an Apache Jira ticket? (not required for trivial changes)
  • Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"? (not required for trivial changes)
  • Did you squash your changes to a single commit?
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"

@Jens-G
Copy link
Member

Jens-G commented Jun 2, 2019

I generally welcome that patch, I had in on my todo as well. But I am against the others unrelated stuff. If you think we need that please file another ticket for it and let's discuss these changes separtely. If you could do that, I will commit it (unless I find something else), but in the current form it is a clear -1 from me.

{
if (cancellationToken.IsCancellationRequested)
if (_isDisposed)
Copy link
Member

Choose a reason for hiding this comment

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

Could you comment on that change? Why do we need that and how is it related to setting custom HTTP headers?

@@ -134,6 +129,11 @@ public override void Close()

public override async Task WriteAsync(byte[] buffer, int offset, int length, CancellationToken cancellationToken)
{
if (_isDisposed)
Copy link
Member

Choose a reason for hiding this comment

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

I'd recommend to put that into a method. The CheckDisposed() pattern is already used in some other files.

Copy link
Member

@Jens-G Jens-G Jun 7, 2019

Choose a reason for hiding this comment

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

Refactoring code is still a good thing. But not in the same PR/ticket :-)

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'm all for that. I'll look through all the IDisposable classes and and create a ticket to standardize them separately. If there are any other cleanup items that the maintainers want done but don't have time for then feel free to open some thrift tickets and I'll check them out and see how I can help.

@ksmithdev
Copy link
Contributor Author

You're right. Sometimes old habits come back and haunt me. Let me clear out the non-topic specific changes.

catch (HttpRequestException wx)
{
throw new TTransportException(TTransportException.ExceptionType.Unknown,
"Couldn't connect to server: " + wx);
}
Copy link
Member

Choose a reason for hiding this comment

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

I have a general problem with nested exception handlers. There are exceptions to the rule (pun intended) but in most cases they are just badly designed and clutter the code towards unmaintainability. In the particular case we have here we have three different tpyes of exceptions which are handled in a strange manner. Is there a chance we can streamline that a bit and consolidate all catches into one level? Or do I overlook sth important?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Looking through the code and I don't see any benefit to the nested try-catch statements. The duplicate catch for HttpRequestException wouldn't ever be hit as far as I could tell. I moved them all into the same level and removed the other nested try-finally since it too could be put in line. Let me know if I went to far.

@Jens-G Jens-G closed this in 823474e Jun 14, 2019
@ksmithdev ksmithdev deleted the THRIFT-4848 branch June 17, 2019 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants