servlets.pp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. unit Servlets;
  12. interface
  13. uses SysUtils, Classes;
  14. type
  15. EServlet = class(Exception);
  16. TServletContext = class
  17. public
  18. property Attributes[const AName: String]: TObject; // !!!: Implement this rw
  19. // function GetContext(const URIPath: String): TServletContext; // !!!: How to implement?
  20. // function GetRealPath(const APath: String): String; // !!!: How to implement?
  21. property ServletContextName: String; // !!!: How to implement?
  22. // procedure Log(const AMsg: String); // !!!: Implement this
  23. // procedure RemoveAttribute(const AName: String); // !!!: Implement this
  24. end;
  25. TServletRequest = class
  26. private
  27. FInputStream: TStream;
  28. FScheme, FPathInfo: String;
  29. protected
  30. function GetContentLength: Integer; virtual; abstract;
  31. function GetContentType: String; virtual; abstract;
  32. function GetProtocol: String; virtual; abstract;
  33. public
  34. constructor Create(AInputStream: TStream; const AScheme, APathInfo: String);
  35. property Attributes[const AName: String]: TObject; // !!!: Implement this rw
  36. property CharacterEncoding: String; // !!!: Implement this rw
  37. property ContentLength: Integer read GetContentLength;
  38. property ContentType: String read GetContentType;
  39. property InputStream: TStream read FInputStream;
  40. property Parameters[const AName: String]: String; // !!!: Implement this
  41. property ParameterValues[const AName: String]: TStrings; // !!!: Implement this
  42. property Protocol: String read GetProtocol;
  43. property RemoteAddr: String; // !!!: Implement this
  44. property RemoteHost: String; // !!!: Implement this
  45. property Scheme: String read FScheme;
  46. property ServerName: String; // !!!: How to implement?
  47. property ServerPort: Integer; // !!!: How to implement?
  48. property IsSecure: Boolean; // !!!: Implement this
  49. // procedure RemoveAttribute(const AName: String); // !!!: Implement this
  50. end;
  51. TServletResponse = class
  52. private
  53. FOutputStream: TStream;
  54. protected
  55. procedure SetContentType(const Value: String); virtual; abstract;
  56. procedure SetContentLength(Value: Int64); virtual; abstract;
  57. public
  58. constructor Create(AOutputStream: TStream);
  59. property BufferSize: Integer; // !!!: How to implement? rw
  60. property CharacterEncoding: String; // !!!: Implement this
  61. property ContentLength: Int64 write SetContentLength;
  62. property ContentType: String write SetContentType;
  63. property OutputStream: TStream read FOutputStream;
  64. property IsCommitted: Boolean; // !!!: Implement this
  65. // procedure FlushBuffer; // !!!: Implement this
  66. // procedure Reset; // !!!: Implement this
  67. // procedure ResetBuffer; // !!!: Implement this
  68. end;
  69. TGenericServlet = class(TComponent)
  70. public
  71. procedure Service(Req: TServletRequest; Resp: TServletResponse);
  72. virtual; abstract;
  73. property ServletContext: TServletContext; // !!!: Implement this
  74. end;
  75. implementation
  76. constructor TServletRequest.Create(AInputStream: TStream;
  77. const AScheme, APathInfo: String);
  78. begin
  79. inherited Create;
  80. FInputStream := AInputStream;
  81. FScheme := AScheme;
  82. FPathInfo := APathInfo;
  83. end;
  84. constructor TServletResponse.Create(AOutputStream: TStream);
  85. begin
  86. inherited Create;
  87. FOutputStream := AOutputStream;
  88. end;
  89. end.