Created
April 20, 2025 18:12
-
-
Save swbbl/58d59b9dd365f15a2ec3e6aaa883a8d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ParsedUriParameter { | |
| [string]$Key | |
| [string]$Value | |
| [string]$ValueUnescaped | |
| ParsedUriParameter([string]$key, [string]$value) { | |
| $this.Key = $key | |
| $this.Value = $value | |
| $this.ValueUnescaped = [uri]::UnescapeDataString($value) | |
| } | |
| } | |
| class ParsedUri : Uri { | |
| [string]$Scheme | |
| [string]$Host | |
| [string]$Port | |
| [string]$Path | |
| [string]$Query | |
| [System.Collections.Generic.List[ParsedUriParameter]]$QueryParameters | |
| [string]$Fragment | |
| ParsedUri([uri]$Uri) : base($Uri) { | |
| $this.Scheme = $Uri.Scheme | |
| $this.Host = $Uri.Host | |
| $this.Port = $Uri.Port | |
| $this.Path = $Uri.AbsolutePath | |
| $this.Query = $Uri.Query | |
| $this.Fragment = $Uri.Fragment | |
| $this.QueryParameters = [System.Collections.Generic.List[ParsedUriParameter]]::new() | |
| $Uri.Query.TrimStart('?').Split('&') | ForEach-Object { | |
| $key, $value = $_ -split '=', 2 | |
| $this.QueryParameters.Add([ParsedUriParameter]::new($key, $value)) | |
| } | |
| } | |
| } | |
| function Split-Uri { | |
| [cmdletbinding()] | |
| param ( | |
| [Parameter(Mandatory=$true, ValueFromPipeline, ValueFromPipelineByPropertyName)] | |
| [uri]$Uri | |
| ) | |
| process { | |
| if ([string]::IsNullOrWhiteSpace($Uri.Scheme)) { | |
| $Uri = [uri]::new("http://$Uri") | |
| } | |
| [ParsedUri]::new($Uri) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment