Reputation: 9289
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?
Upvotes: 12
Views: 9510
Reputation: 12110
A preflight request normally responds with http status code 204 No Content
, which makes it easy to separate from the GET response with status code 200 OK
. In these cases, you can simply match on the response status in the rewrite rule to replace only the GET response status.
Upvotes: 0
Reputation: 31
In Charles, you can use Breakpoints tools. FYR: https://tanaschita.com/20220307-manipulating-network-requests-and-responses-with-charles/.
Upvotes: 1
Reputation: 189
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]*\]
Upvotes: 8
Reputation: 3594
Unfortunately, Charles doesn't have this feature to filter out which the Request that has certain HTTP Method.
It's not a direct answer, but you can achieve with Scripting tool from Proxyman
function onResponse(context, url, request, response) {
// Update status Code
response.statusCode = 500;
// Done
return response;
}
Here is the Snippet Code that you can do with JS Code.
Disclaimer: I'm a creator of Proxyman. Since there are many people who struggle with this problem, hopefully, the Scripting tool can help you.
Upvotes: 1
Reputation: 487
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.
Upvotes: 6
Reputation: 3651
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.
Upvotes: 6