Skip to content

#405 reuse http client #417

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

Merged
merged 5 commits into from
Mar 20, 2017

Conversation

jonnybee
Copy link
Contributor

Changed SendGridClient to keep/reuse HttpClient instance
Removed obsolete properties and parameters (that cannot be re-set on the HttpClient)
Modified unit tests to pass custom headers to SendGridClient constructor
Change in Examples to avoid exception when there is no groups and correct text message.

@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Mar 12, 2017
{
HttpResponseMessage response = await client.SendAsync(request, cancellationToken).ConfigureAwait(false);
HttpResponseMessage response = await client.SendAsync(request, cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why drop the .ConfigureAwait(false);? I believe we had async issues before without this call. Please see this thread: #362

@jonnybee
Copy link
Contributor Author

Done. Learned a new thing now about why use ConfigureAwait(false) in libraries.

Copy link
Contributor

@thinkingserious thinkingserious left a comment

Choose a reason for hiding this comment

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

Great work! I just have few more requests. Thank you!

/// <returns>Interface to the SendGrid REST API</returns>
public SendGridClient(IWebProxy webProxy, string apiKey, string host = "https://api.sendgrid.com", Dictionary<string, string> requestHeaders = null, string version = "v3", string urlPath = null)
: this(apiKey, host, requestHeaders, version, urlPath)
public SendGridClient(IWebProxy webProxy, string apiKey, string host = null, Dictionary<string, string> requestHeaders = null, string version = "v3")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please re-add the urlPath parameter so we can avoid a breaking change. It allows for the user to specify a default endpoint path.

/// <returns>Interface to the SendGrid REST API</returns>
public SendGridClient(string apiKey, string host = null, Dictionary<string, string> requestHeaders = null, string version = "v3", string urlPath = null)
public SendGridClient(string apiKey, string host = null, Dictionary<string, string> requestHeaders = null, string version = "v3")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please re-add the urlPath parameter so we can avoid a breaking change. It allows for the user to specify a default endpoint path.

/// The web proxy.
/// </summary>
private IWebProxy webProxy;
private readonly string version;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please include summary comments.

Added summary comments
@jonnybee
Copy link
Contributor Author

Done.

Copy link
Contributor

@thinkingserious thinkingserious left a comment

Choose a reason for hiding this comment

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

Looks like we are almost there. I just have one more question.

@@ -63,10 +52,67 @@ public class SendGridClient
/// <param name="version">API version, override AddVersion to customize</param>
/// <param name="urlPath">Path to endpoint (e.g. /path/to/endpoint)</param>
/// <returns>Interface to the SendGrid REST API</returns>
public SendGridClient(IWebProxy webProxy, string apiKey, string host = "https://api.sendgrid.com", Dictionary<string, string> requestHeaders = null, string version = "v3", string urlPath = null)
: this(apiKey, host, requestHeaders, version, urlPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why this line was removed.

@@ -79,22 +125,8 @@ public SendGridClient(IWebProxy webProxy, string apiKey, string host = "https://
/// <param name="urlPath">Path to endpoint (e.g. /path/to/endpoint)</param>
/// <returns>Interface to the SendGrid REST API</returns>
public SendGridClient(string apiKey, string host = null, Dictionary<string, string> requestHeaders = null, string version = "v3", string urlPath = null)
: this(null, apiKey, host, requestHeaders, version, urlPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

.. and then this line added here.

@jonnybee
Copy link
Contributor Author

New version create the HttpClient in ctor and this is done in the ctor that accepts all parameters (WebProxy).

Previous version of this ctor would call the other ctor (without the webproxy parameter) and then just set the WebPoxy property.

@thinkingserious
Copy link
Contributor

That makes sense, and thanks for responding so quickly. My main concern is that this may cause a breaking change because the function signatures are no longer the same. I will double check the tests and make sure code written against the previous versions of those constructors do not break.

@thinkingserious thinkingserious merged commit 7ea44d6 into sendgrid:master Mar 20, 2017
@thinkingserious
Copy link
Contributor

Thanks again for the awesome PR! Please take a moment to fill out this form so that we can send you some swag :)

@jonnybee jonnybee deleted the #405_Reuse_HttpClient branch March 20, 2017 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: code review request requesting a community code review or review from Twilio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants