Changeset 67 for trunk/Components/CoolWeb
- Timestamp:
- Dec 25, 2011, 9:40:28 PM (13 years ago)
- Location:
- trunk/Components/CoolWeb
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Components/CoolWeb/Common/UHtmlClasses.pas
r66 r67 155 155 InputType: THtmlInputType; 156 156 Value: Variant; 157 ItemName: string; 157 158 procedure Assign(Source: THtmlElement); override; 158 159 constructor Create; … … 397 398 Attributes.Add('type', InputTypeString); 398 399 Attributes.Add('value', Value); 399 if Self. Name <> '' then400 Attributes.Add('name', Self. Name);400 if Self.ItemName <> '' then 401 Attributes.Add('name', Self.ItemName); 401 402 end; 402 403 end; … … 407 408 InputType := THtmlInput(Source).InputType; 408 409 Value := THtmlInput(Source).Value; 410 ItemName := THtmlInput(Source).ItemName; 409 411 end; 410 412 -
trunk/Components/CoolWeb/WebServer/UHTTPServer.pas
r61 r67 28 28 29 29 THTTPRequest = class 30 ContentType: string; 31 Content: TMemoryStreamEx; 30 32 Query: TQueryParameterList; 31 33 QueryParts: TListString; … … 34 36 Headers: TStringList; 35 37 Cookies: TCookieList; 38 Post: TQueryParameterList; 36 39 constructor Create; 37 40 destructor Destroy; override; … … 42 45 THTTPResponse = class 43 46 ContentType: string; 44 Stream: TMemoryStreamEx;47 Content: TMemoryStreamEx; 45 48 Headers: TStringList; 46 49 Cookies: TCookieList; … … 126 129 I: Integer; 127 130 begin 128 with HandlerData, Response. Streamdo begin131 with HandlerData, Response.Content do begin 129 132 //Response.Cookies.Values['Test'] := 'Halo'; 130 133 //Response.Cookies.Values['Test2'] := 'Halo2'; … … 134 137 135 138 WriteString('<a href="?ServerInfo">Refresh</a>'); 139 140 WriteString('<h5>Request HTTP content:</h5>'); 141 WriteStream(Request.Content, Request.Content.Size); 136 142 137 143 WriteString('<h5>Request HTTP headers</h5>'); … … 151 157 end; 152 158 159 WriteString('<h5>Request HTTP POST</h5>'); 160 for I := 0 to Request.Post.Count - 1 do begin; 161 WriteString(Request.Post.Strings[I] + '<br/>'); 162 end; 163 164 165 WriteString('<h5>Response HTTP content:</h5>'); 166 WriteStream(Response.Content, Response.Content.Size); 167 153 168 WriteString('<h5>Response HTTP headers</h5>'); 154 with Response. Streamdo169 with Response.Content do 155 170 for I := 0 to Response.Headers.Count - 1 do begin; 156 171 WriteString(Response.Headers.Strings[I] + '<br/>'); … … 166 181 procedure THTTPServer.ErrorResponse(HandlerData: THTTPHandlerData); 167 182 begin 168 with HandlerData, Response. Streamdo begin183 with HandlerData, Response.Content do begin 169 184 WriteString('<html><body>' + Format(SPageNotFound, [Request.Path]) + '</body></html>'); 170 185 end; … … 193 208 Response.Headers.Values['Content-Type'] := GetMIMEType(Copy(ExtractFileExt(FileName), 2, 255)); 194 209 BinaryFile := TFileStream.Create(FileName, fmOpenRead); 195 Response. Stream.WriteStream(BinaryFile, BinaryFile.Size);210 Response.Content.WriteStream(BinaryFile, BinaryFile.Size); 196 211 BinaryFile.Destroy; 197 212 end else 198 with Response. Streamdo begin213 with Response.Content do begin 199 214 WriteLn(Format(SFileNotFound, [Request.Path])); 200 215 WriteString('<html><body>' + Format(SFileNotFound, [Request.Path]) + '</body></html>'); … … 219 234 constructor THTTPResponse.Create; 220 235 begin 221 Stream:= TMemoryStreamEx.Create;236 Content := TMemoryStreamEx.Create; 222 237 Cookies := TCookieList.Create; 223 238 Headers := TStringList.Create; … … 226 241 destructor THTTPResponse.Destroy; 227 242 begin 228 Stream.Free;243 Content.Free; 229 244 Headers.Free; 230 245 Cookies.Free; … … 255 270 constructor THTTPRequest.Create; 256 271 begin 272 Post := TQueryParameterList.Create; 257 273 Query := TQueryParameterList.Create; 258 274 QueryParts := TListString.Create; 259 275 Headers := TStringList.Create; 260 276 Cookies := TCookieList.Create; 277 Content := TMemoryStreamEx.Create; 261 278 end; 262 279 263 280 destructor THTTPRequest.Destroy; 264 281 begin 282 Content.Free; 283 Post.Free; 265 284 Query.Free; 266 285 QueryParts.Free; -
trunk/Components/CoolWeb/WebServer/UHTTPServerCGI.pas
r61 r67 6 6 7 7 uses 8 Classes, SysUtils, UHTTPServer, SpecializedList ;8 Classes, SysUtils, UHTTPServer, SpecializedList, IOStream; 9 9 10 10 type … … 53 53 I: Integer; 54 54 HandlerData: THTTPHandlerData; 55 InputStream: TIOStream; 56 Line: string; 57 Buffer: string; 58 Count: Integer; 55 59 begin 56 60 HandlerData := THTTPHandlerData.Create; 57 61 with HandlerData do try 62 // Load headers 63 try 64 InputStream := TIOStream.Create(iosInput); 65 SetLength(Buffer, 1000); 66 repeat 67 Count := InputStream.Read(Buffer[1], Length(Buffer)); 68 Request.Content.Write(Buffer[1], Count); 69 until Count = 0; 70 finally 71 InputStream.Free; 72 end; 73 74 //repeat 75 // ReadLn(Line); 76 //until Line = ''; 77 78 // Load data 79 if Request.Headers.IndexOfName('Content-length') <> -1 then 80 try 81 InputStream := TIOStream.Create(iosInput); 82 Request.Content.CopyFrom(InputStream, StrToInt(Request.Headers.Values['Content-length'])); 83 finally 84 InputStream.Free; 85 end; 86 58 87 // Load environment variables 59 88 for I := 0 to GetEnvironmentVariableCount - 1 do begin … … 80 109 SessionStorage.Load(HandlerData); 81 110 82 Response.Stream.Clear; 111 // Load post data 112 if EnvVars.IndexOfName('REQUEST_METHOD') <> -1 then begin 113 if EnvVars.Values['REQUEST_METHOD'] = 'POST' then begin 114 Request.Content.Position := 0; 115 Buffer := Request.Content.ReadString; 116 Request.Post.Parse(Buffer); 117 end; 118 end; 119 120 Response.Content.Clear; 83 121 Response.Headers.Values['Content-type'] := 'text/html'; 84 122 … … 105 143 106 144 // Emit page content 107 Stream.Position := 0;108 WriteLn( Stream.ReadString);145 Content.Position := 0; 146 WriteLn(Content.ReadString); 109 147 end; 110 148 finally … … 118 156 begin 119 157 inherited; 120 with HandlerData, Response. Streamdo begin158 with HandlerData, Response.Content do begin 121 159 WriteString('<h5>' + SEnvironmentVariables + '</h5>'); 122 160 WriteString('<table border="1">'); -
trunk/Components/CoolWeb/WebServer/UHTTPServerTCP.pas
r61 r67 88 88 SessionStorage.Load(HandlerData); 89 89 90 Response. Stream.Clear;90 Response.Content.Clear; 91 91 Response.Headers.Values['Content-Type'] := 'text/html'; 92 92 … … 100 100 with Response do begin 101 101 SendString('HTTP/1.0 200 OK'#13#10); 102 Headers.Values['Content-Length'] := IntToStr( Stream.Size);102 Headers.Values['Content-Length'] := IntToStr(Content.Size); 103 103 Headers.Values['Connection'] := 'close'; 104 104 Headers.Values['Date'] := RFC822DateTime(Now); … … 115 115 end; 116 116 SendString(#13#10); 117 SendBuffer( Stream.Memory, Stream.Size);117 SendBuffer(Content.Memory, Content.Size); 118 118 SendString(#13#10); 119 119 end; -
trunk/Components/CoolWeb/WebServer/UWebApp.pas
r61 r67 131 131 if Assigned(Page) then begin 132 132 Page.Page.OnProduce(HandlerData); 133 end else Response. Stream.WriteString(SPageNotFound);133 end else Response.Content.WriteString(SPageNotFound); 134 134 end; 135 135 end;
Note:
See TracChangeset
for help on using the changeset viewer.