Skip to content

Instantly share code, notes, and snippets.

@serialseb
Created November 17, 2011 13:45
Show Gist options
  • Save serialseb/1373164 to your computer and use it in GitHub Desktop.
Save serialseb/1373164 to your computer and use it in GitHub Desktop.
Parsing link headers quick and dirty
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