minimain.pas 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. unit minimain;
  2. interface
  3. {$mode delphi}{$H+}
  4. uses
  5. SysUtils, Classes, httpd, apr;
  6. procedure RegisterHooks(p: Papr_pool_t); cdecl;
  7. implementation
  8. function DefaultHandler(r: Prequest_rec): Integer; cdecl;
  9. var
  10. RequestedHandler: string;
  11. begin
  12. RequestedHandler := r^.handler;
  13. { We decline to handle a request if hello-handler is not the value of r->handler }
  14. if not SameText(RequestedHandler, 'testapache-handler') then
  15. begin
  16. Result := DECLINED;
  17. Exit;
  18. end;
  19. { The following line just prints a message to the errorlog }
  20. ap_log_error('me',1, APLOG_NOERRNO or APLOG_NOTICE, 0, r^.server,
  21. 'mod_hello: %s', ['Before content is output']);
  22. { We set the content type before doing anything else }
  23. ap_set_content_type(r, 'text/html');
  24. { If the request is for a header only, and not a request for
  25. the whole content, then return OK now. We don't have to do
  26. anything else. }
  27. if (r^.header_only <> 0) then
  28. begin
  29. Result := OK;
  30. Exit;
  31. end;
  32. { Now we just print the contents of the document using the
  33. ap_rputs and ap_rprintf functions. More information about
  34. the use of these can be found in http_protocol.h }
  35. ap_rputs('<HTML>' + LineEnding, r);
  36. ap_rputs('<HEAD>' + LineEnding, r);
  37. ap_rputs('<TITLE>Hello There</TITLE>' + LineEnding, r);
  38. ap_rputs('</HEAD>' + LineEnding, r);
  39. ap_rputs('<BODY BGCOLOR="#FFFFFF">' + LineEnding ,r);
  40. ap_rputs('<H1>Hello world</H1>' + LineEnding, r);
  41. ap_rputs('This is the first Apache Module working with the new binding from Free Pascal' + LineEnding, r);
  42. ap_rprintf(r, '<br>A sample line generated by ap_rprintf<br>\n', []);
  43. ap_rputs('</BODY></HTML>' + LineEnding, r);
  44. { We can either return OK or DECLINED at this point. If we return
  45. * OK, then no other modules will attempt to process this request }
  46. Result := OK;
  47. end;
  48. procedure RegisterHooks(p: Papr_pool_t); cdecl;
  49. begin
  50. ap_hook_handler(DefaultHandler,nil,nil,APR_HOOK_MIDDLE);
  51. end;
  52. end.