Charles is a Web Debugging Application which captures all HTTP traffic between the machine and the internet. Unlike a lot of other HTTP monitoring tools available on the net, Charles is actually a Web Proxy by itself. So, essentially any web browser (or Internet application) is configured to access the Internet via Charles. This gives it complete control over the HTTP requests and responses and also opens up endless possibilities. In this article, I’ll be covering a few of the interesting features from a Developer’s perspective.
The Rewrite tool is a very nifty feature which gives you complete flexibility to create rules and modify any of the requests and responses. This feature can be very handy for a lot of scenarios. e.g. Add/Remove the Cookies, modify various headers like User-Agent, Content-Type or add custom content in the response body. It allows you to define multiple rule sets. For each set, the locations and rules can be defined.
Location specifies the URL(s) for which the rule needs to be applied. This is configurable at a granular level of Host, Port, Query etc.. It supports * and ? wildcards as well. If location is left empty, the rules simply get applied to all the requests / responses.
Each Rule can in turn be defined and customized to a really great extent. We can specify the type of rewrite – text to be matched, replaced, added, deleted – applicable for requests/responses. This supports Regular express (regex) and allows us to reference the groups in the Regex as well!
2. DNS Spoofing
While developing applications, there are scenarios where you would want to test it against different Staging, Pre Production environments etc… This is referred to as Spoofing a hostname. Usually, this is done by modifying the hosts file locally. Charles provides a much simpler and easier way for spoofing multiple hostnames. You can simply provide the various host names and the IPs in the Spoofing tool . This does not require a browser restart and the feature can be easily turned on/off completely.
3. Map Local
This tool enables you to use the local files for testing as if they were live. Consider a simple scenario where you are fixing a css error for a website. After fixing the error, rather than uploading the updated css file to a development server, you can simply point the URL to your local file. Now, Charles will fetch the local file and help you ensure that the issue is indeed fixed. This can greatly improve the development and testing time. Here again, this feature gives you various useful customizations.
Note the URL and the Title in the image below
These features are just the tip of an iceberg. With much more brilliant features that are present like No Caching, Blacklist, Repeat, Edit, Bandwidth Throttling, this tool presents itself as a must-have tool for developers and others who work on the HTTP platform. The numerous keyboard shortcuts are an additional plus. If you love Charles too, Please leave a comment and spread the word!
Contributed by Pradeep from Bangalore. Pradeep works with a leading CDN provider and loves to try out and review latest tech stuff.
Follow me on Twitter at @vaibhav1981 Charles, HTTP, Proxy, Web Application Development, Web Performance