Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Charles' rewrite tool only on certain methods?

I'm using Charles' Rewrite Tool to change 200 responses to 400 in order to test failing API calls. However, the rewrite is triggering on the Options request. I'd like to only have it trigger on the Get or Post requests and allow the Options requests through. Is this possible using Charles?

Rewrite Screen

like image 245
garrettmaring Avatar asked Aug 28 '18 01:08

garrettmaring


People also ask

How do I intercept a Charles request?

The simplest way to enable a breakpoint is by selecting the URL and then clicking the breakpoint button in the top toolbar. Enable breakpoints. For more control, open Proxy -> Breakpoint Settings in the menu. Here, we see an overview of all the breakpoints that are set, can edit, remove them or add new ones.


3 Answers

We were able to work around the issue by assuming that OPTIONS would always return an empty body.

The below Regex values will match for GET (because it has a response body) and not match for OPTIONS (because it doesn't have a response body).

\{[\S\s]*\}

or

\[[\S\s]*\]

Rewrite Rule

like image 161
Austin Avatar answered Nov 11 '22 02:11

Austin


I think Charles does not have this option, which is really a pitty, because it seems to be easy to implement and it would open the doors to the API world.

I would suggest you to ask Karl (the author and main developer) for this new feature at the contact section of the site.

like image 33
Lluís Suñol Avatar answered Nov 11 '22 00:11

Lluís Suñol


We have this exact same need to mock API responses. Since the Rewrite tool doesn't support this feature, we have setup Breakpoints on the responses we want to mock, once the breakpoint is hit, we change the response to whatever we want. It works, but is less than ideal.

like image 5
Todd Hansberger Avatar answered Nov 11 '22 01:11

Todd Hansberger