Created
November 17, 2011 13:45
-
-
Save serialseb/1373164 to your computer and use it in GitHub Desktop.
Parsing link headers quick and dirty
This file contains 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
static internal class ResponseExtensions | |
{ | |
public static string GetLinkValue(this WebResponse response, string rel) | |
{ | |
return (from header in response.Headers["Link"].Split(',') | |
let components = header.Split(';') | |
let uri = components[0] | |
where components.Any( | |
component => | |
Regex.IsMatch(component, | |
@"rel\s*=\s*" + Regex.Escape(rel))) | |
select uri.Substring(1, uri.Length - 2)) | |
.FirstOrDefault(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment