servlets.pp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. {
  2. $Id$
  3. Basic Servlet Support
  4. Copyright (c) 2003 by
  5. Areca Systems GmbH / Sebastian Guenther, [email protected]
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. }
  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, FPathInfo: String;
  30. protected
  31. function GetContentLength: Integer; virtual; abstract;
  32. function GetContentType: String; virtual; abstract;
  33. function GetProtocol: String; virtual; abstract;
  34. public
  35. constructor Create(AInputStream: TStream; const AScheme, APathInfo: String);
  36. property Attributes[const AName: String]: TObject; // !!!: Implement this rw
  37. property CharacterEncoding: String; // !!!: Implement this rw
  38. property ContentLength: Integer read GetContentLength;
  39. property ContentType: String read GetContentType;
  40. property InputStream: TStream read FInputStream;
  41. property Parameters[const AName: String]: String; // !!!: Implement this
  42. property ParameterValues[const AName: String]: TStrings; // !!!: Implement this
  43. property Protocol: String read GetProtocol;
  44. property RemoteAddr: String; // !!!: Implement this
  45. property RemoteHost: String; // !!!: Implement this
  46. property Scheme: String read FScheme;
  47. property ServerName: String; // !!!: How to implement?
  48. property ServerPort: Integer; // !!!: How to implement?
  49. property IsSecure: Boolean; // !!!: Implement this
  50. // procedure RemoveAttribute(const AName: String); // !!!: Implement this
  51. end;
  52. TServletResponse = class
  53. private
  54. FOutputStream: TStream;
  55. protected
  56. procedure SetContentType(const Value: String); virtual; abstract;
  57. procedure SetContentLength(Value: Int64); virtual; abstract;
  58. public
  59. constructor Create(AOutputStream: TStream);
  60. property BufferSize: Integer; // !!!: How to implement? rw
  61. property CharacterEncoding: String; // !!!: Implement this
  62. property ContentLength: Int64 write SetContentLength;
  63. property ContentType: String write SetContentType;
  64. property OutputStream: TStream read FOutputStream;
  65. property IsCommitted: Boolean; // !!!: Implement this
  66. // procedure FlushBuffer; // !!!: Implement this
  67. // procedure Reset; // !!!: Implement this
  68. // procedure ResetBuffer; // !!!: Implement this
  69. end;
  70. TGenericServlet = class(TComponent)
  71. public
  72. procedure Service(Req: TServletRequest; Resp: TServletResponse);
  73. virtual; abstract;
  74. property ServletContext: TServletContext; // !!!: Implement this
  75. end;
  76. implementation
  77. constructor TServletRequest.Create(AInputStream: TStream;
  78. const AScheme, APathInfo: String);
  79. begin
  80. inherited Create;
  81. FInputStream := AInputStream;
  82. FScheme := AScheme;
  83. FPathInfo := APathInfo;
  84. end;
  85. constructor TServletResponse.Create(AOutputStream: TStream);
  86. begin
  87. inherited Create;
  88. FOutputStream := AOutputStream;
  89. end;
  90. end.
  91. {
  92. $Log$
  93. Revision 1.1 2002-04-25 19:30:29 sg
  94. * First version (with exception of the HTTP unit: This is an improved version
  95. of the old asyncio HTTP unit, now adapted to fpAsync)
  96. }