justcoding121 / titanium-web-proxy

A cross-platform asynchronous HTTP(S) proxy server in C#.
MIT License
1.93k stars 618 forks source link

Can i use library as fake web server ? #751

Closed mbtolou closed 4 years ago

mbtolou commented 4 years ago

Hi,

Can i use library as fake web server (whitout set proxy server)?

for example: can i open port 127.0.0.1:9000 and send all urls to "http://www.example.com" ?

http://127.0.0.1:9000/test -------> http://www.example.com/test

honfika commented 4 years ago

Yes

mbtolou commented 4 years ago

can you write example code ?

honfika commented 4 years ago

Please check the example code: https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs

I think you need a transparent endpoint and change the url in the beforerequest handler.

MattMinke commented 4 years ago

Another Library I have used with success is WireMock.Net. The goal of WireMock is much different than Titanium. Both tools are very good and can solve different problems.

https://www.nuget.org/packages/WireMock.Net/ https://github.com/WireMock-Net/WireMock.Net

using Microsoft.VisualStudio.TestTools.UnitTesting;
using WireMock.Server;

namespace Infrastructure.Http.Test.Unit
{
    // https://www.meziantou.net/2018/02/12/mstest-v2-test-lifecycle-attributes
    // https://blogs.msdn.microsoft.com/nnaderi/2007/02/01/comparing-the-mstest-and-nunit-frameworks/
    [TestClass]
    public class HttpServer
    {
        public static FluentMockServer Instance { get; private set; }

        [AssemblyInitialize]
        public static void AssemblyInitialize(TestContext context)
        {
            // https://github.com/WireMock-Net/WireMock.Net/wiki/Stubbing-and-Request-Matching
            // https://alastaircrabtree.com/stubbing-your-way-to-automated-e2e-testing-api-first-with-wiremock/
            Instance = FluentMockServer.Start();
        }

        [AssemblyCleanup]
        public static void AssemblyCleanup()
        {
            Instance.Stop();
            Instance.Dispose();
            Instance = null;
        }
    }
}
mbtolou commented 4 years ago

Please check the example code: https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs

I think you need a transparent endpoint and change the url in the beforerequest handler.

Thanks.