Running Fiddler as HTTP to HTTPS reverse proxy

2019-05-23 23:22发布

问题:

I have a service running on my machine. This service is published on HTTPS and starting it on HTTP seems a bit complicated. A certain remote machine perform calls to my machine on HTTP (and this is not under my control). I want to perform some non-performance-critical tests with my service, and it looks like the simplest way is to use somewhat like HTTP to HTTPS reverse proxy. Fiddler works great with HTTP to HTTP and HTTPS to HTTPS scenarios, but I'm not able to make it work for my case. Thus what I need:

+----------------+          +--------------------------------+
| Remote machine | -------> | My machine                     |
|                |  HTTP    | Fiddler    -------> My machine |
|                |          |            HTTPS    service    |
+----------------+          +--------------------------------+

Can I achieve this using Fiddler?

回答1:

Sure, Fiddler can convert inbound requests from HTTP to HTTPS.

The simplest way would be to add something inside OnBeforeRequest like:

if (oSession.HostnameIs("myhost") && 
    (oSession.oRequest.pipeClient.LocalPort == 80)) 
{
  oSession.fullUrl = "https://" + oSession.url;
}

This presumes, of course, that Fiddler was configured to run on port 80, the default port for HTTP. You can run it on whatever port you like (e.g. if port 80 were already in use) but you'd need to change the port in the URL that the client requests, and if you could do that, you'd probably be able to change the client to use a HTTPS URL to begin with.