LoginSignup
5
6

More than 3 years have passed since last update.

Fiddlerでレスポンス書き換え(カスタムスクリプト使用)

Posted at

レスポンスヘッダーを書き換える必要がありました。
Fiddlerのカスタムスクリプトを用いればリクエストやレスポンスの内容が改竄可能です。
※デバッグ機能もあり、レスポンスを都度止めて内容を書き換えることも可能です(参考)。

編集方法

  1. Fiddlerにて,メニューバー「Rules」→「Customize Rules..」を選択
  2. FiddlerScript Editorが開かれる
  3. スクリプト内のOnBeforeResponseメソッドを文字列検索

カスタムスクリプト修正

指定したパスのレスポンスヘッダーを変更

画像ファイルに対してCache-Controlに値no-storeを設定。

static function OnBeforeResponse(oSession: Session) {
    if (oSession.PathAndQuery == "/img/something.png") {
        oSession.oResponse["Cache-Control"] = "no-store";
    }
}

指定したドメインからの特定ヘッダーを削除

www.fizzbuzz.com:8080 からのレスポンス全てに対してCache-Controlヘッダーを削除。

static function OnBeforeResponse(oSession: Session) {
    if (oSession.host == "www.fizzbuzz.com:8080") {
        oSession.oResponse.headers.Remove("Cache-Control");
    }
}

指定したURLのレスポンスボディーを変更

外部のWebAPIのレスポンス内容を{"mean": "意味はない"}に変更。

static function OnBeforeResponse(oSession: Session) {
    if (oSession.url== "www.hoge.com/rest/api/get/means") {
        oSession.oResponse["Content-Type"] = "application/json";
        oSession.utilSetResponseBody('{\"mean\": \"意味はない\"}');
    }
}

TBD: JavaScriptオブジェクトからJSON文字列への変換で簡単な方法は調査中

指定した拡張子のファイルのレスポンスコードを変更する

CSSファイルの全レスポンスを404に変更する。

static function OnBeforeResponse(oSession: Session) {
    if (oSession.uriContains(".css")){
        oSession.oResponse.headers.HTTPResponseCode = 404;
        oSession.oResponse.headers.HTTPResponseStatus = "404 Not Found";
    }
}

参考

Modifying a Request or Response
Fiddlerでレスポンスを止める方法

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6