VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsHttpRequest"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'
' Xceed Winsock Library Sample: HTTP Server
' Copyright (c) 2000 Xceed Software Inc.
'
' [Http request class - see frmMain.frm code for main module]
'
' This class contains an http request, or a portion of an http
' request. It is required because when an HTTP connection is made,
' the complete HTTP request may not yet have completely been
' received. Therefore, the received portion(s) of each
' connection are stored in the 'sRequest' variable of this class
' until the complete request is received and processed.
'
' This file is part of the Xceed Winsock Library Samples.
' The source code in this file is only intended as a supplement
' to Xceed Winsock Library's documentation, and is provided "as is",
' without warranty of any kind, either expressed or implied.

Option Explicit

' Class variables
'
Public xSocket As Object     ' The socket with the connection this request came from
Public sRequest As String    ' The partial or complete HTTP request.

' This procedure adds a newly received request portion to the current request.
'
Public Sub AppendRequestString(sRequestString As String)
  sRequest = sRequest & sRequestString
End Sub

' This function returns True if the request portions received so far
' make up a complete request. HTTP requests are terminated by a double
' CR+LF character combination, which is what this function tests for.
'
Public Function IsRequestComplete() As Boolean
  If (Right(sRequest, 4) = (vbCrLf & vbCrLf)) Then
    IsRequestComplete = True
  Else
    IsRequestComplete = False
  End If
End Function

' This function extracts a path and filename from the HTTP request
' which will be used by the caller to locate the file to send
' relative to the root files directory.
'
Public Function GetRelativeFilename() As String

  GetRelativeFilename = ""
  
  If (IsRequestComplete() = False) Then ' If request is incomplete, don't continue
    Exit Function
  End If
  
  If (Left(sRequest, 4) <> "GET ") Then ' If request is not a GET, don't continue
    Exit Function
  End If
  
  Dim nGetEnd As Integer
  
  nGetEnd = InStr(5, sRequest, " ")
  
  Dim sRelativeName As String
  sRelativeName = Mid(sRequest, 5, nGetEnd - 5)
  
  If (sRelativeName = "/") Then
    sRelativeName = "/index.html"
  End If
  
  Do
    Dim nSlashPos As Integer
    nSlashPos = InStr(sRelativeName, "/")
    
    If (nSlashPos = 0) Then
      Exit Do
    End If
    
    Mid(sRelativeName, nSlashPos) = "\"
  Loop
  
  GetRelativeFilename = sRelativeName

End Function

' This function returns the local path and filename of the file
' requested. It works by combining the path and filename from the
' HTTP request (provided by the GetRelativeFilename function) with
' the root files directory specified in the "Files root:" field
' on the main form.
'
Public Function GetAbsoluteFilename() As String
  
  GetAbsoluteFilename = ""
  
  Dim sRelativeName As String
  sRelativeName = GetRelativeFilename
  
  If (sRelativeName = "") Then
    Exit Function
  End If
  
  GetAbsoluteFilename = Trim$(frmMain.txtFilesRoot.Text) & sRelativeName
  
End Function
