chromelyapps / Chromely

Build Cross Platform HTML Desktop Apps on .NET using native GUI, HTML5, JavaScript, CSS, Owin, AspNetCore (MVC, RazorPages, Blazor)
MIT License
2.98k stars 279 forks source link

how to intercept a request and modify the entire response #291

Closed liesauer closed 3 years ago

mattkol commented 3 years ago

@liesauer If you are creating the Controllers yourself, I won't see the need for intercepting the request to change the response. Just return the responses you want.

But if it is a third-party Controller class, then I will suggest creating a custom RequestTaskHandler and register it.. https://github.com/chromelyapps/Chromely/blob/94aeae7ffa621558c96ee4ee965c3bc65ba8f7cf/src/Chromely.Core/Defaults/DefaultRequestTaskRunner.cs#L49

    public class DemoApp : ChromelyBasicApp
    {
        public override void ConfigureServices(IServiceCollection services)
        {
            base.ConfigureServices(services);
            services.AddSingleton<IChromelyRequestTaskRunner, CustomRequestTaskRunner>();
        }
    }

    public class CustomRequestTaskRunner : DefaultRequestTaskRunner
    {
        public CustomRequestTaskRunner(IChromelyRouteProvider routeProvider, IChromelyInfo chromelyInfo) 
            : base(routeProvider, chromelyInfo)
        {
        }
    }
liesauer commented 3 years ago

i am trying to craete a hybrid framework, and i want to intercept all the requests sent by the website, and modify the response if i need/want, i already implemented partial functions of this feature by creating a custom SchemeHandlerFactory and SchemeHandler, but currently the response is completely new by myself. now i have no idea about how to intercept the original response and modify it then return to the wesite, let's say i just want to replace all the hello words into helo or decrypt the images(was encrypted by the server) then return it to the website so can display the images properly.

mattkol commented 3 years ago

It may not be that easy for someone else to clearly understand that. Are you requesting data from an external website? If yes, where in Chromely are you doing that? Via a Controller action or you are talking directly to the website bypassing Chromely?