Coder Social home page Coder Social logo

purify's Introduction

PUrify - Your Uris have been PUrified!

Why do I need my Uris purified?

The Uri classes in .NET prior to 4.5 and Mono scrub through your Uris and modify them in order to prevent vulnerabilities, for example escaped slashes are unescaped. This scrubbing however prevents Uris that are inline with [RFC 3986] (http://tools.ietf.org/html/rfc3986). Beyond that it prevents using .NET's HTTP clients (HttpClient and WebClient) to talk to APIs that require accessing resources using escaped slashes unless you are using .NET 4.5.

How can PUrify help?

PUrify will ensure that the Uri remains untouched. How does it do that? Well it hacks into the Uri internals and ensures that the original Uri is preserved.

Hello PUrify

To use PUrify, create a Uri which you want to Purify. Then call the Purify extension method! It will do the rest!

static void Main(string[] args)
{
  var uriString = "http://www.myapi.com/%2F?Foo=Bar%2F#frag";
  var uri = new Uri(uriString);
  Console.WriteLine("Uri String\n\t" + uriString);
  Console.WriteLine("\nBefore PUrify:");
  ShowUriDetails(uri);           
  uri.Purify();
  Console.WriteLine("\nAfter PUrify:");
  ShowUriDetails(uri);
  Console.ReadLine();
}

public static void ShowUriDetails(Uri uri)
{
  Console.WriteLine("\turi.ToString() - " + uri.ToString());
  Console.WriteLine("\turi.AbsoluteUri - " + uri.AbsoluteUri);
  Console.WriteLine("\turi.Host - " + uri.Host);
  Console.WriteLine("\turi.Query - " + uri.Query);
  Console.WriteLine("\turi.PathAndQuery - " + uri.PathAndQuery);
  Console.WriteLine("\turi.AbsolutePath - " + uri.AbsolutePath);
  Console.WriteLine("\turi.Fragment - " + uri.Fragment);
}

Running this code will output the following:

In .NET

![dotnet] (https://dl.dropboxusercontent.com/u/6860088/Purify%20Windows.PNG)

and in Mono

![mono] (https://dl.dropboxusercontent.com/u/6860088/Purify%20Mono.png)

As you can see, the Uri has been PUrified! Now you can take that Uri and use it with your favorite .NET Http client.

Platforms

.NET 3.5, 4.0, and Mono > 1.x

Acknowledgements

Credits to the following folks:

purify's People

Contributors

glennblock avatar mpdreamz avatar jweber avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.