home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / vbasic / Data / Utils / XZipComp.exe / XceedWinsock.Cab / F112720_clsHttpRequest.cls < prev    next >
Encoding:
Visual Basic class definition  |  2000-04-17  |  3.5 KB  |  119 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsHttpRequest"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. '
  15. ' Xceed Winsock Library Sample: HTTP Server
  16. ' Copyright (c) 2000 Xceed Software Inc.
  17. '
  18. ' [Http request class - see frmMain.frm code for main module]
  19. '
  20. ' This class contains an http request, or a portion of an http
  21. ' request. It is required because when an HTTP connection is made,
  22. ' the complete HTTP request may not yet have completely been
  23. ' received. Therefore, the received portion(s) of each
  24. ' connection are stored in the 'sRequest' variable of this class
  25. ' until the complete request is received and processed.
  26. '
  27. ' This file is part of the Xceed Winsock Library Samples.
  28. ' The source code in this file is only intended as a supplement
  29. ' to Xceed Winsock Library's documentation, and is provided "as is",
  30. ' without warranty of any kind, either expressed or implied.
  31.  
  32. Option Explicit
  33.  
  34. ' Class variables
  35. '
  36. Public xSocket As Object     ' The socket with the connection this request came from
  37. Public sRequest As String    ' The partial or complete HTTP request.
  38.  
  39. ' This procedure adds a newly received request portion to the current request.
  40. '
  41. Public Sub AppendRequestString(sRequestString As String)
  42.   sRequest = sRequest & sRequestString
  43. End Sub
  44.  
  45. ' This function returns True if the request portions received so far
  46. ' make up a complete request. HTTP requests are terminated by a double
  47. ' CR+LF character combination, which is what this function tests for.
  48. '
  49. Public Function IsRequestComplete() As Boolean
  50.   If (Right(sRequest, 4) = (vbCrLf & vbCrLf)) Then
  51.     IsRequestComplete = True
  52.   Else
  53.     IsRequestComplete = False
  54.   End If
  55. End Function
  56.  
  57. ' This function extracts a path and filename from the HTTP request
  58. ' which will be used by the caller to locate the file to send
  59. ' relative to the root files directory.
  60. '
  61. Public Function GetRelativeFilename() As String
  62.  
  63.   GetRelativeFilename = ""
  64.   
  65.   If (IsRequestComplete() = False) Then ' If request is incomplete, don't continue
  66.     Exit Function
  67.   End If
  68.   
  69.   If (Left(sRequest, 4) <> "GET ") Then ' If request is not a GET, don't continue
  70.     Exit Function
  71.   End If
  72.   
  73.   Dim nGetEnd As Integer
  74.   
  75.   nGetEnd = InStr(5, sRequest, " ")
  76.   
  77.   Dim sRelativeName As String
  78.   sRelativeName = Mid(sRequest, 5, nGetEnd - 5)
  79.   
  80.   If (sRelativeName = "/") Then
  81.     sRelativeName = "/index.html"
  82.   End If
  83.   
  84.   Do
  85.     Dim nSlashPos As Integer
  86.     nSlashPos = InStr(sRelativeName, "/")
  87.     
  88.     If (nSlashPos = 0) Then
  89.       Exit Do
  90.     End If
  91.     
  92.     Mid(sRelativeName, nSlashPos) = "\"
  93.   Loop
  94.   
  95.   GetRelativeFilename = sRelativeName
  96.  
  97. End Function
  98.  
  99. ' This function returns the local path and filename of the file
  100. ' requested. It works by combining the path and filename from the
  101. ' HTTP request (provided by the GetRelativeFilename function) with
  102. ' the root files directory specified in the "Files root:" field
  103. ' on the main form.
  104. '
  105. Public Function GetAbsoluteFilename() As String
  106.   
  107.   GetAbsoluteFilename = ""
  108.   
  109.   Dim sRelativeName As String
  110.   sRelativeName = GetRelativeFilename
  111.   
  112.   If (sRelativeName = "") Then
  113.     Exit Function
  114.   End If
  115.   
  116.   GetAbsoluteFilename = Trim$(frmMain.txtFilesRoot.Text) & sRelativeName
  117.   
  118. End Function
  119.