Changeset 87
- Timestamp:
- Dec 17, 2009, 9:36:15 AM (15 years ago)
- Location:
- branches/DirectWeb
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DirectWeb
- Property svn:ignore
-
old new 3 3 WoWHostingWebServer 4 4 Config.xml 5 Session
-
- Property svn:ignore
-
branches/DirectWeb/UCommon.pas
r82 r87 23 23 function BCDToInt(Value: Byte): Byte; 24 24 function CompareByteArray(Data1, Data2: TArrayOfByte): Boolean; 25 function Explode(Separator: Char; Data: string ): TArrayOfString;25 function Explode(Separator: Char; Data: string; SlicesCount: Integer = -1): TArrayOfString; 26 26 27 27 implementation … … 110 110 end; 111 111 112 function Explode(Separator: char; Data: string ): TArrayOfString;112 function Explode(Separator: char; Data: string; SlicesCount: Integer = -1): TArrayOfString; 113 113 begin 114 114 SetLength(Result, 0); 115 while Pos(Separator, Data) > 0 do begin 115 while (Pos(Separator, Data) > 0) and 116 ((Length(Result) < (SlicesCount - 1)) or (SlicesCount = -1)) do begin 116 117 SetLength(Result, Length(Result) + 1); 117 118 Result[High(Result)] := Copy(Data, 1, Pos(Separator, Data) - 1); -
branches/DirectWeb/UHTTPServer.pas
r86 r87 59 59 procedure Add(AName: string; AHandler: TRequestEvent); 60 60 function IndexOfName(AName: string): TRequestHandler; 61 end; 62 63 { THTTPSession } 64 65 THTTPSession = class 66 Variables: TStringList; 67 procedure Load(Request: THTTPRequest); virtual; 68 procedure Save(Response: THTTPResponse); virtual; 69 constructor Create; virtual; 70 destructor Destroy; override; 61 71 end; 62 72 … … 73 83 MaxConnection: Integer; 74 84 RequestHandlerList: TRequestHandlerList; 85 SessionHandler: THTTPSession; 75 86 procedure FileResponse(Request: THTTPRequest; 76 87 Response: THTTPResponse); … … 103 114 repeat 104 115 Line := RecvString(10000); 105 LineParts := Explode(' ', Line); 106 if (LineIndex = 0) and (Length(LineParts) >= 3) then begin 107 Request.Method := LineParts[0]; 108 if Pos('?', LineParts[1]) > 0 then begin 109 Request.Path := Copy(LineParts[1], 1, Pos('?', LineParts[1]) - 1); 110 Request.Query.Parse(Copy(LineParts[1], Pos('?', LineParts[1]) + 1, Length(LineParts[1]))); 111 end else Request.Path := LineParts[1]; 112 end else 113 if (Length(LineParts) >= 2) and (LineParts[0][Length(LineParts[0])] = ':') then begin 114 LineParts[0] := Copy(LineParts[0], 1, Length(LineParts[0]) - 1); 115 Request.Headers.Values[LineParts[0]] := LineParts[1]; 116 if (LineIndex = 0) then begin 117 LineParts := Explode(' ', Line); 118 if (Length(LineParts) >= 3) then begin 119 Request.Method := LineParts[0]; 120 if Pos('?', LineParts[1]) > 0 then begin 121 Request.Path := Copy(LineParts[1], 1, Pos('?', LineParts[1]) - 1); 122 Request.Query.Parse(Copy(LineParts[1], Pos('?', LineParts[1]) + 1, Length(LineParts[1]))); 123 end else Request.Path := LineParts[1]; 124 end; 125 end else begin 126 LineParts := Explode(' ', Line, 2); 127 if (Length(LineParts) = 2) and (LineParts[0][Length(LineParts[0])] = ':') then begin 128 LineParts[0] := Copy(LineParts[0], 1, Length(LineParts[0]) - 1); 129 Request.Headers.Values[LineParts[0]] := LineParts[1]; 130 WriteLn(Line); 131 end; 116 132 end; 117 133 Inc(LineIndex); 118 134 until Line = ''; 119 135 120 // Parse cookies 121 if Request.Cookies.IndexOfName('Cookie') <> -1 then 122 Request.Cookies.Parse(Request.Headers.Values['Cookie']); 136 // Process cookies 137 if Request.Headers.IndexOfName('Cookie') <> -1 then 138 Request.Cookies.Parse(Request.Headers.Values['Cookie']); 139 140 // Process session 141 if Assigned(SessionHandler) then 142 SessionHandler.Load(Request); 123 143 124 144 Response.Stream.Clear; … … 130 150 if Assigned(RequestHandler) then RequestHandler.Handler(Request, Response) 131 151 else ErrorResponse(Request, Response); 152 153 if Assigned(SessionHandler) then 154 SessionHandler.Save(Response); 132 155 133 156 with Response do begin … … 139 162 // Handle cookies 140 163 for I := 0 to Cookies.Count - 1 do 141 Headers. Values['Set-Cookie'] := Cookies.Names[I] + '=' + Cookies.ValueFromIndex[I];164 Headers.Add('Set-Cookie' + Headers.NameValueSeparator + Cookies.Names[I] + '=' + Cookies.ValueFromIndex[I]); 142 165 // + ';path=/;expires=' + RFC822DateTime(Now); 143 166 144 167 // Send headers 145 for I := 0 to Headers.Count - 1 do 168 for I := 0 to Headers.Count - 1 do begin 169 WriteLn(Headers.Names[I] + ': ' + Headers.ValueFromIndex[I] + #13#10); 146 170 SendString(Headers.Names[I] + ': ' + Headers.ValueFromIndex[I] + #13#10); 171 end; 147 172 SendString(#13#10); 148 173 SendBuffer(Stream.Memory, Stream.Size); … … 304 329 end; 305 330 331 { THTTPSession } 332 333 procedure THTTPSession.Load(Request: THTTPRequest); 334 begin 335 336 end; 337 338 procedure THTTPSession.Save(Response: THTTPResponse); 339 begin 340 341 end; 342 343 constructor THTTPSession.Create; 344 begin 345 Variables := TStringList.Create; 346 end; 347 348 destructor THTTPSession.Destroy; 349 begin 350 Variables.Destroy; 351 inherited Destroy; 352 end; 353 306 354 end. 307 355 -
branches/DirectWeb/UWebServer.pas
r86 r87 6 6 7 7 uses 8 Classes, SysUtils, UHTTPServer, 8 Classes, SysUtils, UHTTPServer, UHTTPSessionFile, 9 9 UTCPServer, 10 10 UCommon, … … 21 21 TWebServer = class 22 22 private 23 HTTPSessionFile: THTTPSessionFile; 23 24 function PagesList(URL: string; Page, TotalCount, CountPerPage: Integer 24 25 ): string; … … 244 245 with Response.Stream do begin 245 246 Response.Cookies.Values['Test'] := 'Halo'; 247 //Response.Cookies.Values['Test2'] := 'Halo2'; 248 249 HTTPServer.SessionHandler.Variables.Values['Session1'] := 'Value1'; 250 //HTTPServer.SessionHandler.Variables.Values['Session2'] := 'Value2'; 246 251 247 252 WriteString('<a href="?ServerInfo">Refresh</a>'); 248 253 249 254 WriteString('<h5>Request HTTP headers</h5>'); 250 251 255 for I := 0 to Request.Headers.Count - 1 do begin; 252 256 WriteString(Request.Headers.Strings[I] + '<br/>'); 257 end; 258 259 WriteString('<h5>Request HTTP cookies</h5>'); 260 for I := 0 to Request.Cookies.Count - 1 do begin; 261 WriteString(Request.Cookies.Strings[I] + '<br/>'); 262 end; 263 264 WriteString('<h5>Session variables</h5>'); 265 for I := 0 to HTTPServer.SessionHandler.Variables.Count - 1 do begin; 266 WriteString(HTTPServer.SessionHandler.Variables.Strings[I] + '<br/>'); 253 267 end; 254 268 … … 310 324 begin 311 325 inherited Create; 326 HTTPSessionFile := THTTPSessionFile.Create; 327 with HTTPSessionFile do begin 328 end; 312 329 HTTPServer := THTTPServer.Create; 313 330 with HTTPServer, Socket do begin 331 SessionHandler := HTTPSessionFile; 314 332 DocumentRoot := 'Data'; 315 333 with RequestHandlerList do begin … … 329 347 begin 330 348 HTTPServer.Destroy; 349 HTTPSessionFile.Destroy; 331 350 inherited Destroy; 332 351 end; -
branches/DirectWeb/WoWHostingWebServer.lpi
r86 r87 13 13 <Icon Value="0"/> 14 14 <UseXPManifest Value="True"/> 15 <ActiveEditorIndexAtStart Value=" 4"/>15 <ActiveEditorIndexAtStart Value="0"/> 16 16 </General> 17 17 <VersionInfo> … … 37 37 </Item1> 38 38 </RequiredPackages> 39 <Units Count="2 5">39 <Units Count="27"> 40 40 <Unit0> 41 41 <Filename Value="WoWHostingWebServer.lpr"/> 42 42 <IsPartOfProject Value="True"/> 43 43 <UnitName Value="WoWHostingWebServer"/> 44 <CursorPos X=" 1" Y="1"/>44 <CursorPos X="26" Y="20"/> 45 45 <TopLine Value="1"/> 46 46 <EditorIndex Value="0"/> … … 76 76 <IsPartOfProject Value="True"/> 77 77 <UnitName Value="UHTTPServer"/> 78 <CursorPos X=" 37" Y="141"/>79 <TopLine Value="1 23"/>80 <EditorIndex Value=" 4"/>78 <CursorPos X="9" Y="169"/> 79 <TopLine Value="146"/> 80 <EditorIndex Value="3"/> 81 81 <UsageCount Value="200"/> 82 82 <Loaded Value="True"/> … … 86 86 <CursorPos X="14" Y="556"/> 87 87 <TopLine Value="539"/> 88 <EditorIndex Value="5"/>89 88 <UsageCount Value="77"/> 90 <Loaded Value="True"/>91 89 </Unit6> 92 90 <Unit7> 93 91 <Filename Value="..\..\..\..\Knihovny\Free Pascal\synapse\blcksock.pas"/> 94 92 <UnitName Value="blcksock"/> 95 <CursorPos X="13" Y="1802"/> 96 <TopLine Value="1797"/> 97 <EditorIndex Value="9"/> 93 <CursorPos X="15" Y="397"/> 94 <TopLine Value="380"/> 98 95 <UsageCount Value="100"/> 99 <Loaded Value="True"/>100 96 </Unit7> 101 97 <Unit8> … … 105 101 <CursorPos X="1" Y="1"/> 106 102 <TopLine Value="1"/> 107 <EditorIndex Value=" 3"/>103 <EditorIndex Value="2"/> 108 104 <UsageCount Value="200"/> 109 105 <Loaded Value="True"/> … … 113 109 <IsPartOfProject Value="True"/> 114 110 <UnitName Value="UCommon"/> 115 <CursorPos X=" 45" Y="15"/>116 <TopLine Value=" 1"/>117 <EditorIndex Value=" 6"/>111 <CursorPos X="23" Y="116"/> 112 <TopLine Value="92"/> 113 <EditorIndex Value="5"/> 118 114 <UsageCount Value="200"/> 119 115 <Loaded Value="True"/> … … 132 128 <CursorPos X="24" Y="61"/> 133 129 <TopLine Value="1"/> 134 <UsageCount Value="7 6"/>130 <UsageCount Value="78"/> 135 131 </Unit11> 136 132 <Unit12> … … 152 148 <CursorPos X="3" Y="130"/> 153 149 <TopLine Value="121"/> 154 <EditorIndex Value=" 8"/>155 <UsageCount Value="7 5"/>150 <EditorIndex Value="7"/> 151 <UsageCount Value="77"/> 156 152 <Loaded Value="True"/> 157 153 </Unit14> … … 160 156 <IsPartOfProject Value="True"/> 161 157 <UnitName Value="UMIMEType"/> 162 <CursorPos X=" 17" Y="41"/>158 <CursorPos X="26" Y="28"/> 163 159 <TopLine Value="25"/> 164 <EditorIndex Value=" 7"/>165 <UsageCount Value="7 5"/>160 <EditorIndex Value="6"/> 161 <UsageCount Value="77"/> 166 162 <Loaded Value="True"/> 167 163 </Unit15> … … 171 167 <CursorPos X="24" Y="345"/> 172 168 <TopLine Value="330"/> 173 <EditorIndex Value="2"/>174 169 <UsageCount Value="36"/> 175 <Loaded Value="True"/>176 170 </Unit16> 177 171 <Unit17> … … 204 198 <IsPartOfProject Value="True"/> 205 199 <UnitName Value="UWebServer"/> 206 <CursorPos X=" 35" Y="245"/>207 <TopLine Value="23 1"/>200 <CursorPos X="7" Y="247"/> 201 <TopLine Value="237"/> 208 202 <EditorIndex Value="1"/> 209 <UsageCount Value="6 5"/>203 <UsageCount Value="67"/> 210 204 <Loaded Value="True"/> 211 205 </Unit21> … … 222 216 <CursorPos X="32" Y="11"/> 223 217 <TopLine Value="1"/> 224 <EditorIndex Value=" 11"/>225 <UsageCount Value="2 3"/>218 <EditorIndex Value="8"/> 219 <UsageCount Value="25"/> 226 220 <Loaded Value="True"/> 227 221 <SyntaxHighlighter Value="XML"/> … … 230 224 <Filename Value="ReadMe.txt"/> 231 225 <IsPartOfProject Value="True"/> 232 <CursorPos X="1" Y="8"/> 233 <TopLine Value="1"/> 234 <EditorIndex Value="10"/> 235 <UsageCount Value="23"/> 236 <Loaded Value="True"/> 226 <CursorPos X="77" Y="4"/> 227 <TopLine Value="1"/> 228 <UsageCount Value="25"/> 237 229 <SyntaxHighlighter Value="None"/> 238 230 </Unit24> 231 <Unit25> 232 <Filename Value="UHTTPSession.pas"/> 233 <UnitName Value="UHTTPSession"/> 234 <CursorPos X="1" Y="19"/> 235 <TopLine Value="1"/> 236 <UsageCount Value="20"/> 237 </Unit25> 238 <Unit26> 239 <Filename Value="UHTTPSessionFile.pas"/> 240 <IsPartOfProject Value="True"/> 241 <UnitName Value="UHTTPSessionFile"/> 242 <CursorPos X="33" Y="31"/> 243 <TopLine Value="19"/> 244 <EditorIndex Value="4"/> 245 <UsageCount Value="22"/> 246 <Loaded Value="True"/> 247 </Unit26> 239 248 </Units> 240 249 <JumpHistory Count="30" HistoryIndex="29"> 241 250 <Position1> 242 251 <Filename Value="UHTTPServer.pas"/> 243 <Caret Line=" 108" Column="1" TopLine="91"/>252 <Caret Line="312" Column="1" TopLine="295"/> 244 253 </Position1> 245 254 <Position2> 246 255 <Filename Value="UHTTPServer.pas"/> 247 <Caret Line=" 109" Column="1" TopLine="92"/>256 <Caret Line="313" Column="1" TopLine="296"/> 248 257 </Position2> 249 258 <Position3> 250 259 <Filename Value="UHTTPServer.pas"/> 251 <Caret Line=" 111" Column="1" TopLine="94"/>260 <Caret Line="314" Column="1" TopLine="297"/> 252 261 </Position3> 253 262 <Position4> 254 263 <Filename Value="UHTTPServer.pas"/> 255 <Caret Line=" 122" Column="13" TopLine="106"/>264 <Caret Line="315" Column="1" TopLine="298"/> 256 265 </Position4> 257 266 <Position5> 258 267 <Filename Value="UHTTPServer.pas"/> 259 <Caret Line=" 85" Column="23" TopLine="68"/>268 <Caret Line="316" Column="1" TopLine="299"/> 260 269 </Position5> 261 270 <Position6> 262 271 <Filename Value="UHTTPServer.pas"/> 263 <Caret Line=" 21" Column="15" TopLine="1"/>272 <Caret Line="317" Column="1" TopLine="300"/> 264 273 </Position6> 265 274 <Position7> 266 275 <Filename Value="UHTTPServer.pas"/> 267 <Caret Line=" 44" Column="26" TopLine="16"/>276 <Caret Line="315" Column="1" TopLine="298"/> 268 277 </Position7> 269 278 <Position8> 270 279 <Filename Value="UHTTPServer.pas"/> 271 <Caret Line=" 282" Column="1" TopLine="259"/>280 <Caret Line="316" Column="1" TopLine="299"/> 272 281 </Position8> 273 282 <Position9> 274 283 <Filename Value="UHTTPServer.pas"/> 275 <Caret Line=" 249" Column="29" TopLine="232"/>284 <Caret Line="317" Column="1" TopLine="300"/> 276 285 </Position9> 277 286 <Position10> 278 <Filename Value="U WebServer.pas"/>279 <Caret Line=" 12" Column="22" TopLine="1"/>287 <Filename Value="UHTTPServer.pas"/> 288 <Caret Line="315" Column="1" TopLine="298"/> 280 289 </Position10> 281 290 <Position11> 282 <Filename Value="U WebServer.pas"/>283 <Caret Line=" 147" Column="33" TopLine="130"/>291 <Filename Value="UHTTPServer.pas"/> 292 <Caret Line="316" Column="1" TopLine="299"/> 284 293 </Position11> 285 294 <Position12> 286 <Filename Value="U WebServer.pas"/>287 <Caret Line=" 168" Column="37" TopLine="151"/>295 <Filename Value="UHTTPServer.pas"/> 296 <Caret Line="317" Column="1" TopLine="300"/> 288 297 </Position12> 289 298 <Position13> 290 299 <Filename Value="UHTTPServer.pas"/> 291 <Caret Line=" 121" Column="24" TopLine="98"/>300 <Caret Line="319" Column="1" TopLine="302"/> 292 301 </Position13> 293 302 <Position14> 294 <Filename Value=" UWebServer.pas"/>295 <Caret Line=" 245" Column="35" TopLine="231"/>303 <Filename Value="WoWHostingWebServer.lpr"/> 304 <Caret Line="1" Column="1" TopLine="1"/> 296 305 </Position14> 297 306 <Position15> 298 <Filename Value=" UHTTPServer.pas"/>299 <Caret Line=" 289" Column="19" TopLine="271"/>307 <Filename Value="WoWHostingWebServer.lpr"/> 308 <Caret Line="19" Column="3" TopLine="1"/> 300 309 </Position15> 301 310 <Position16> 302 <Filename Value="U HTTPServer.pas"/>303 <Caret Line="2 84" Column="1" TopLine="267"/>311 <Filename Value="UWebServer.pas"/> 312 <Caret Line="250" Column="57" TopLine="237"/> 304 313 </Position16> 305 314 <Position17> 306 315 <Filename Value="UHTTPServer.pas"/> 307 <Caret Line=" 285" Column="1" TopLine="268"/>316 <Caret Line="137" Column="1" TopLine="120"/> 308 317 </Position17> 309 318 <Position18> 310 <Filename Value=" UHTTPServer.pas"/>311 <Caret Line=" 286" Column="1" TopLine="269"/>319 <Filename Value="WoWHostingWebServer.lpr"/> 320 <Caret Line="19" Column="1" TopLine="1"/> 312 321 </Position18> 313 322 <Position19> 314 <Filename Value="UHTTPSe rver.pas"/>315 <Caret Line=" 287" Column="1" TopLine="270"/>323 <Filename Value="UHTTPSessionFile.pas"/> 324 <Caret Line="51" Column="1" TopLine="21"/> 316 325 </Position19> 317 326 <Position20> 318 <Filename Value="UHTTPSe rver.pas"/>319 <Caret Line="2 88" Column="1" TopLine="271"/>327 <Filename Value="UHTTPSessionFile.pas"/> 328 <Caret Line="29" Column="1" TopLine="12"/> 320 329 </Position20> 321 330 <Position21> 322 <Filename Value="UHTTPSe rver.pas"/>323 <Caret Line=" 121" Column="29" TopLine="91"/>331 <Filename Value="UHTTPSessionFile.pas"/> 332 <Caret Line="30" Column="1" TopLine="13"/> 324 333 </Position21> 325 334 <Position22> 326 <Filename Value=" UHTTPServer.pas"/>327 <Caret Line="1 19" Column="27" TopLine="121"/>335 <Filename Value="WoWHostingWebServer.lpr"/> 336 <Caret Line="16" Column="59" TopLine="1"/> 328 337 </Position22> 329 338 <Position23> 330 <Filename Value=" UHTTPServer.pas"/>331 <Caret Line="14 0" Column="1" TopLine="123"/>339 <Filename Value="WoWHostingWebServer.lpr"/> 340 <Caret Line="14" Column="17" TopLine="1"/> 332 341 </Position23> 333 342 <Position24> 334 <Filename Value="UHTTPSe rver.pas"/>335 <Caret Line=" 141" Column="1" TopLine="124"/>343 <Filename Value="UHTTPSessionFile.pas"/> 344 <Caret Line="29" Column="1" TopLine="12"/> 336 345 </Position24> 337 346 <Position25> 338 <Filename Value="UHTTPSe rver.pas"/>339 <Caret Line=" 142" Column="30" TopLine="122"/>347 <Filename Value="UHTTPSessionFile.pas"/> 348 <Caret Line="30" Column="1" TopLine="13"/> 340 349 </Position25> 341 350 <Position26> 342 <Filename Value="UHTTPSe rver.pas"/>343 <Caret Line=" 146" Column="1" TopLine="129"/>351 <Filename Value="UHTTPSessionFile.pas"/> 352 <Caret Line="33" Column="1" TopLine="16"/> 344 353 </Position26> 345 354 <Position27> 346 <Filename Value="UHTTPSe rver.pas"/>347 <Caret Line=" 147" Column="1" TopLine="130"/>355 <Filename Value="UHTTPSessionFile.pas"/> 356 <Caret Line="37" Column="1" TopLine="20"/> 348 357 </Position27> 349 358 <Position28> 350 <Filename Value="U HTTPServer.pas"/>351 <Caret Line=" 148" Column="1" TopLine="131"/>359 <Filename Value="UWebServer.pas"/> 360 <Caret Line="247" Column="7" TopLine="237"/> 352 361 </Position28> 353 362 <Position29> 354 <Filename Value=" UHTTPServer.pas"/>355 <Caret Line="14 9" Column="1" TopLine="132"/>363 <Filename Value="WoWHostingWebServer.lpr"/> 364 <Caret Line="14" Column="17" TopLine="1"/> 356 365 </Position29> 357 366 <Position30> 358 <Filename Value=" UHTTPServer.pas"/>359 <Caret Line=" 152" Column="1" TopLine="135"/>367 <Filename Value="WoWHostingWebServer.lpr"/> 368 <Caret Line="22" Column="14" TopLine="1"/> 360 369 </Position30> 361 370 </JumpHistory> … … 376 385 </CompilerOptions> 377 386 <Debugging> 378 <BreakPoints Count="2">379 <Item1>380 <Source Value="UHTTPServer.pas"/>381 <Line Value="286"/>382 </Item1>383 <Item2>384 <Source Value="UHTTPServer.pas"/>385 <Line Value="140"/>386 </Item2>387 </BreakPoints>388 387 <Exceptions Count="3"> 389 388 <Item1> -
branches/DirectWeb/WoWHostingWebServer.lpr
r84 r87 11 11 {$ENDIF} 12 12 Classes, 13 SysUtils, UWebServer ;13 SysUtils, UWebServer, UHTTPSessionFile; 14 14 15 15 {$IFDEF WINDOWS}{$R WoWHostingWebServer.rc}{$ENDIF} … … 17 17 var 18 18 WebServer: TWebServer; 19 Command: string;20 19 begin 21 20 WebServer := TWebServer.Create;
Note:
See TracChangeset
for help on using the changeset viewer.