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

DYN-2239 Set the UserAgent for HttpWebRequest #11293

Merged
merged 3 commits into from
Dec 4, 2020

Conversation

StudioLE
Copy link
Contributor

Purpose

JIRA: DYN-2239

Set the UserAgent for HTTPWebRequest which is required by some APIs including GitHub: https://developer.github.com/v3/#user-agent-required

Behaviour before:
DYN-2239-WebRequest-UserAgent-Before

Behaviour after:
DYN-2239-WebRequest-UserAgent-Completed

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated

Reviewers

@mjkkirschner @QilongTang @mmisol

FYIs

@Amoursol

@@ -28,6 +28,9 @@ public static string WebRequestByUrl(string url)
// Initialize the WebRequest.
var myRequest = System.Net.WebRequest.Create(uriResult);

if (myRequest is System.Net.HttpWebRequest httpRequest)
httpRequest.UserAgent = "Dynamo";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a comment describing why this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 190a1e7

{
string url = "https://api.github.com/repos/DynamoDS/Dynamo/issues?page=0&state=closed&per_page=10";
string result = Web.WebRequestByUrl(url);
Assert.IsNotNullOrEmpty(result);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please consider replacing the first test in this file, since this is a better version of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please consider replacing the first test in this file, since this is a better version of it.

@mmisol It looks like the GitHub API has a rate limit of 60 requests per hour per originating IP for unauthenticated
requests (https://developer.github.com/v3/#rate-limiting). If this is exceeded then the test will likely fail due to a 403 response. I'm not familiar with how your test infrastructure is setup so is this likely to cause an issue?

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've addressed this in commit 190a1e7. Removed the WebRequest_ValidArgs test and revised the GitHub API request to /rate_limit as requests to this endpoint do not count against your API rate limits.

Copy link
Collaborator

@mmisol mmisol left a comment

Choose a reason for hiding this comment

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

Thanks @StudioLE . This looks good to me

@QilongTang QilongTang merged commit 8f6a42b into DynamoDS:master Dec 4, 2020
QilongTang pushed a commit that referenced this pull request Dec 4, 2020
* Set the UserAgent for HttpWebRequest

* Added WebRequest_GitHubAPI test

* Replaced WebRequest_ValidArgs test. Added comment. Revised GitHub API endpoint.
QilongTang added a commit that referenced this pull request Dec 4, 2020
* Set the UserAgent for HttpWebRequest

* Added WebRequest_GitHubAPI test

* Replaced WebRequest_ValidArgs test. Added comment. Revised GitHub API endpoint.

Co-authored-by: Laurence Elsdon <laurence.elsdon@matterlab.co>
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