hellobrowser.pp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. (* Feel free to use this example code in any way
  2. you see fit (Public Domain) *)
  3. // Original example: https://gnunet.org/svn/libmicrohttpd/doc/examples/hellobrowser.c
  4. program hellobrowser;
  5. {$mode objfpc}{$H+}
  6. uses
  7. libmicrohttpd;
  8. const
  9. PORT = 8888;
  10. function AnswerToConnection(ACls: Pointer; AConnection: PMHD_Connection;
  11. AUrl: Pcchar; AMethod: Pcchar; AVersion: Pcchar; AUploadData: Pcchar;
  12. AUploadDataSize: Psize_t; AConCls: PPointer): cint; cdecl;
  13. const
  14. PAGE: Pcchar = 'Hello world';
  15. var
  16. VReturn: cint;
  17. VResponse: PMHD_Response;
  18. begin
  19. VResponse := MHD_create_response_from_buffer(Length(PAGE), Pointer(PAGE),
  20. MHD_RESPMEM_PERSISTENT);
  21. VReturn := MHD_queue_response(AConnection, MHD_HTTP_OK, VResponse);
  22. MHD_destroy_response(VResponse);
  23. Result := VReturn;
  24. end;
  25. var
  26. VDaemon: PMHD_Daemon;
  27. begin
  28. VDaemon := MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, PORT, nil, nil,
  29. @AnswerToConnection, nil, MHD_OPTION_END);
  30. if not Assigned(VDaemon) then
  31. Halt(1);
  32. ReadLn;
  33. MHD_stop_daemon(VDaemon)
  34. end.