Is it possible to rewrite a status code with Charles Proxy?

让人想犯罪 __ 提交于 2019-12-02 16:31:28

An Update: Version 3.8 of Charles Proxy was just released, with the ability to rewrite the status. From the release notes:

  • Rewrite tool: allow rewriting of response status

This version's rewrite UI adds a new "Response Status" rule type:

Using Charles 3.8+, you can rewrite the status code.

In the rewrite tool, select "Type: response status". In the match fields and replace fields, be aware that Charles expects the incoming and rewritten statuses to match the format "\d{3} .*". This means that your rewritten status must have a message portion in addition to the numeric status code.

For example:

Match value: 201 .*

Replace value: 502 Bad Gateway

Omitting the message from the replace value will result in no rewrite of the status line. You can see Charles' rewrite tool output messages in the Notes section of each call's summary.

Marc Liyanage

This is not a direct answer to your question, but as noted in my comment above I was in the same situation and I found a solution using a different tool that works well for me.

Instead of Charles, I run mitmproxy, specifically mitmdump, with this short Python rewriting script:

#!/usr/bin/env python

def response(context, flow):
    if '/somePath' not in flow.request.path:
        return

    flow.response.status_code = 404

To hook it into the proxy, I run mitmdump like this:

mitmdump -s /path/to/rewriting-script.py

and it works great.

I'm on OS X and I configured the network interface's web proxy to 127.0.0.1 port 8080.

Final Edit: Marc Liyanage's answer is the most correct for this question now.

No, you're not, I don't think it is possible to rewrite a status code.

I cannot add this as a comment (new user) but one workaround is:

  1. Create resources on a server that will return the codes you need, or find ones that do.
  2. Use the Map Remote feature, mapping to the resource that returns the code.

I've tried using Map Local, which would be perfect for this, but Charles adds it's own 200 OK status code to all files returned.

Edit: Also you can use breakpoints on individual responses and modify the code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!