servlets.pp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. {
  2. Basic Servlet Support
  3. Copyright (c) 2003 by
  4. Areca Systems GmbH / Sebastian Guenther, [email protected]
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. }
  11. {$mode objfpc}{$H+}
  12. unit Servlets;
  13. interface
  14. uses SysUtils, Classes;
  15. type
  16. EServlet = class(Exception);
  17. TServletContext = class
  18. public
  19. property Attributes[const AName: String]: TObject; // !!!: Implement this rw
  20. // function GetContext(const URIPath: String): TServletContext; // !!!: How to implement?
  21. // function GetRealPath(const APath: String): String; // !!!: How to implement?
  22. property ServletContextName: String; // !!!: How to implement?
  23. // procedure Log(const AMsg: String); // !!!: Implement this
  24. // procedure RemoveAttribute(const AName: String); // !!!: Implement this
  25. end;
  26. TServletRequest = class
  27. private
  28. FInputStream: TStream;
  29. FScheme: String;
  30. protected
  31. FPathInfo: String;
  32. function GetContentLength: Integer; virtual; abstract;
  33. function GetContentType: String; virtual; abstract;
  34. function GetProtocol: String; virtual; abstract;
  35. public
  36. constructor Create(AInputStream: TStream; const AScheme, APathInfo: String);
  37. property Attributes[const AName: String]: TObject; // !!!: Implement this rw
  38. property CharacterEncoding: String; // !!!: Implement this rw
  39. property ContentLength: Integer read GetContentLength;
  40. property ContentType: String read GetContentType;
  41. property InputStream: TStream read FInputStream;
  42. property Parameters[const AName: String]: String; // !!!: Implement this
  43. property ParameterValues[const AName: String]: TStrings; // !!!: Implement this
  44. property Protocol: String read GetProtocol;
  45. property RemoteAddr: String; // !!!: Implement this
  46. property RemoteHost: String; // !!!: Implement this
  47. property Scheme: String read FScheme;
  48. property ServerName: String; // !!!: How to implement?
  49. property ServerPort: Integer; // !!!: How to implement?
  50. property IsSecure: Boolean; // !!!: Implement this
  51. // procedure RemoveAttribute(const AName: String); // !!!: Implement this
  52. end;
  53. TServletResponse = class
  54. private
  55. FOutputStream: TStream;
  56. protected
  57. procedure SetContentType(const Value: String); virtual; abstract;
  58. procedure SetContentLength(Value: Int64); virtual; abstract;
  59. public
  60. constructor Create(AOutputStream: TStream);
  61. property BufferSize: Integer; // !!!: How to implement? rw
  62. property CharacterEncoding: String; // !!!: Implement this
  63. property ContentLength: Int64 write SetContentLength;
  64. property ContentType: String write SetContentType;
  65. property OutputStream: TStream read FOutputStream;
  66. property IsCommitted: Boolean; // !!!: Implement this
  67. // procedure FlushBuffer; // !!!: Implement this
  68. // procedure Reset; // !!!: Implement this
  69. // procedure ResetBuffer; // !!!: Implement this
  70. end;
  71. TGenericServlet = class(TComponent)
  72. public
  73. procedure Service(Req: TServletRequest; Resp: TServletResponse);
  74. virtual; abstract;
  75. property ServletContext: TServletContext; // !!!: Implement this
  76. end;
  77. implementation
  78. constructor TServletRequest.Create(AInputStream: TStream;
  79. const AScheme, APathInfo: String);
  80. begin
  81. inherited Create;
  82. FInputStream := AInputStream;
  83. FScheme := AScheme;
  84. FPathInfo := APathInfo;
  85. end;
  86. constructor TServletResponse.Create(AOutputStream: TStream);
  87. begin
  88. inherited Create;
  89. FOutputStream := AOutputStream;
  90. end;
  91. end.