8000 Support Link Header pagination in WebCmdlets by SteveL-MSFT · Pull Request #3828 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Support Link Header pagination in WebCmdlets #3828

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 3 commits into from
May 24, 2017

Conversation

SteveL-MSFT
Copy link
Member
@SteveL-MSFT SteveL-MSFT commented May 19, 2017

Implements https://github.com/PowerShell/PowerShell-RFC/blob/master/2-Draft-Accepted/RFC0021-Link-header-based-pagination-for-WebCmdlets.md

When the response includes a Link Header (https://tools.ietf.org/html/rfc5988#page-6), for Invoke-WebRequest we create a RelationLink property that is a Dictionary representing the URLs and rel attributes and ensure the URLs are absolute to make it easier for the developer to use. For Invoke-RestMethod, we expose a -FollowRelLink switch to automatically follow 'next' rel links to the end until we hit the optional -MaximumFollowRelLink parameter value.

Since we will eventually remove the FullClr code, I didn't make the effort to add the same changes to the CoreClr sources to the FullClr sources.

Fix #3041

Doc update MicrosoftDocs/PowerShell-Docs#1232

…e end user implementing:

https://github.com/PowerShell/PowerShell-RFC/blob/master/2-Draft-Accepted/RFC0021-Link-header-based-pagination-for-WebCmdlets.md

When the response includes a Link Header (https://tools.ietf.org/html/rfc5988#page-6), for Invoke-WebRequest we
create a RelationLink property that is a Dictionary representing the URLs and rel attributes and ensure the
URLs are absolute to make it easier for the developer to use.  For Invoke-RestMethod, we expose a -FollowRelLink
switch to automatically follow 'next' rel links to the end until we hit the optional -MaxRelLink parameter value.
< 8000 div class="TimelineItem-badge ">
/// </summary>
[Parameter]
[Alias("ML")]
[ValidateRange(0, Int32.MaxValue)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't -FL -ML 0 contradictory? If you agree, I would use 1 for the minimum.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, 1 makes sense

if (followedRelLink > 0)
{
string linkVerboseMsg = string.Format(CultureInfo.CurrentCulture,
"Following rel link {0}",
Copy link
Contributor

Choose a reason for hiding this comment

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

This string should be in a resx for localization.

Copy link
Contributor

Choose a reason for hiding this comment

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

And I see you just followed the pattern in the rest of this method - you should fix all of them at the same time.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since there's only 3 I see in this file, I'll fix them with this PR

/// <summary>
/// gets the RelationLink property
/// </summary>
public Dictionary<string, string> RelationLink { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to have a public setter?

Also note how the Headers property is get only and returns a copy of the internal Headers. This isn't ideal because people write code like:

if (obj.Headers.ContainsKey("Something"))
{
    obj.Headers["Something"] ...
}

And this usage would create 2 copies of the dictionary. It's better to use ReadOnlyDictionary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Created #3842 for the Headers issue

Copy link
Member Author

Choose a reason for hiding this comment

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

Will make the setter internal


// we only support the URL in angle brackets and `rel`, other attributes are ignored
// user can still parse it themselves via the Headers property
Regex regex = new Regex("<(?<url>.*?)>;\\srel=\"(?<rel>.*?)\"");
Copy link
Contributor

Choose a reason for hiding this comment

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

You should not create a new Regex like this, instead you should prefer the static method, see the best practices.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will fix

{
return;
}
Uri = new Uri(_relationLink["next"]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it we be better to use a local variable instead of modifying the cmdlet parameter.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will fix

ThrowTerminatingError(er);
}

ParseLinkHeader(response, Uri);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should you skip parsing the header when we're not following pages?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will fix

@TravisEz13 TravisEz13 added the WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module label May 24, 2017
@TravisEz13
Copy link
Member

Docs update PR?

@SteveL-MSFT
Copy link
Member Author

@TravisEz13 added link to doc PR

@TravisEz13 TravisEz13 merged commit 40446c8 into PowerShell:master May 24, 2017
@SteveL-MSFT SteveL-MSFT deleted the webcmdlets-link-header branch May 24, 2017 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0