mjustin 23 Posted July 16, 2021 The Daraja HTTP Server Framework is a free open source library for Object Pascal (Free Pascal 3,1.0 or Delphi 2009+), based on the stand-alone HTTP server component in Internet Direct (Indy). With the 2.5-SNAPSHOT release, most code is now single-source and more readable, there are no "IFDEF FPC" branches anymore to use the Free Pascal fgl generics library. All DUnit / FPCUnit - based tests run successfully. The full 2.5-SNAPSHOT source and demo code is available at GitHub. Demo applications cover - for example - OAuth 2.0 and Twitter Bootstrap. More information - GitHub: https://github.com/michaelJustin/daraja-framework - API documentation: http://michaeljustin.github.io/daraja-framework/ - Wiki: https://github.com/michaelJustin/daraja-framework/wiki - Features and FAQ: https://www.habarisoft.com/daraja_framework.html 2 Share this post Link to post
mjustin 23 Posted April 15, 2023 The Daraja HTTP Server Framework is a free open source library for Object Pascal (Free Pascal 3.2.0 or Delphi 2009+), based on the HTTP server component in Internet Direct (Indy). New: the 2.6-SNAPSHOT includes a first implementation of the Web Filter API, which allows pre- and postprocessing of HTTP requests and responses. Web Filters are useful for example to add logging and auditing, input validation, or authentication. Filters may be composed in filter chains, where the order of filter execution is defined by the order of registration. Web Filter instances may configured through init parameters. Example code In the test example below, the Web Component TExamplePage returns the plain-text response "example", and the filters (TTestFilterA and TTestFilterB) add the texts " (A)" and " (B)" to the response. The client therefore receives the response "example (A) (B)". Code: Pascal [Select][+] procedure TAPIConfigTests.TestTwoFilters; var Server: TdjServer; Context: TdjWebAppContext; begin Server := TdjServer.Create; try Context := TdjWebAppContext.Create('web'); // Context located at http://<server:port>/web/ Context.AddWebComponent(TExamplePage, '*.txt'); // Web Component responds to all requests for txt documents Context.AddWebFilter(TTestFilterA, TExamplePage); // Web Filter A will be processed first and appends " (A)" Context.AddWebFilter(TTestFilterB, TExamplePage); // Web Filter B will be processed second and appends " (B)" Server.Add(Context); Server.Start; CheckGETResponseEquals('example (A) (B)', '/web/test.txt'); finally Server.Free; end; end; Code for the DoFilter method of TTestFilterA: procedure TTestFilterA.DoFilter(Context: TdjServerContext; Request: TdjRequest; Response: TdjResponse; const Chain: IWebFilterChain); begin Chain.DoFilter(Context, Request, Response); // invoke other filters and eventually the Web Component Response.ContentText := Response.ContentText + ' (A)'; end; Full source code, including DUnit and FPCUnit tests, is available at GitHub. The Web Filter API specification is still in development and may still see minor and major changes. More information - GitHub: https://github.com/michaelJustin/daraja-framework - 2.6-SNAPSHOT API documentation: https://michaeljustin.github.io/daraja-framework/2.6-SNAPSHOT/ - Project home page: https://www.habarisoft.com/daraja_framework.html Share this post Link to post