Esempio n. 1
0
        public void Test3()
        {
            var URI     = "magnet://server:8088/func1/SubFunc1";
            var example = new RequestURI();
            var b       = example.Match(URI).RemainingText();

            Assert.True(example.Match(URI).Success());
        }
Esempio n. 2
0
        public void Test1()
        {
            var URI     = "a";
            var example = new RequestURI();
            var b       = example.Match(URI).RemainingText();

            Assert.True(example.Match(URI).Success());
        }
Esempio n. 3
0
        // METHOD               :   ValidateAndSetRequest
        // DESCRIPTION          :   This method does the initial validation of the
        //                          HTTP request to see if its structure is valid.
        //
        // PARAMETERS           :
        //  string request      :   contains the request line from the client
        //  string serverInfo   :   contains the ip address and port of the server
        //                          to validate against the URI portion of request
        //
        // RETURNS              :
        //  Boolean             :   returns true if request is valid, false otherwise
        //
        public Boolean ValidateAndSetRequest(string request, string serverInfo)
        {
            Boolean isValid = false;

            //Split request string by spaces. GET | HTTP://.... | HTTP/Version
            string[] split = request.Split(' ');

            //Validate request method to ensure GET was used
            if (ValidateRequestMethod(split[0]) != true)
            {
                StatusCode = NOT_IMPLEMENTED;
            }
            else if (ValidateHTTPStructure(split[1], serverInfo) != true)
            {
                StatusCode = BAD_REQUEST;
            }
            else if (ValidateHTTPVersion(split[2]) != true)
            {
                StatusCode = HTTP_VERSION_NOT_SUPPORTED;
            }
            else if (ValidateFileType(split[1]) != true)
            {
                StatusCode = NOT_IMPLEMENTED;
            }
            else if (ValidateFileExists(split[1], serverInfo) != true)
            {
                StatusCode = NOT_FOUND;
            }
            else
            {
                Method      = split[0];
                RequestURI  = split[1];
                HTTPVersion = split[2];
                StatusCode  = ALL_OKAY;
                isValid     = true;
            }

            //Strip host info from request URI
            string resource = RequestURI.Replace("http://", "");

            resource = resource.Replace(serverInfo, "");

            //Log incoming request
            string message = "[REQUEST] " + Method + resource;

            Logger.Log(message);

            //Build Response somewhere?
            return(isValid);
        }
Esempio n. 4
0
        public string CreateResponse()
        {
            string response    = HTTPVersion + StatusCode + "\n";
            string contentPath = RequestURI.Replace(Host, "");

            if (!StatusCode.ToString().StartsWith("4") || !StatusCode.ToString().StartsWith("5"))
            {
                if (ContentType.StartsWith("text"))
                {
                    //string data = File.ReadAllText(ServerRoot + contentPath);
                }
                else
                {
                    //byte[] data = File.ReadAllBytes(ServerRoot + contentPath);
                }

                response += "Content-Type: " + ContentType + "\n";
                response += "Content-Length: ";
            }

            return(response);
        }
Esempio n. 5
0
 public override string ToString()
 {
     return($"{Method.ToString().ToUpper()} {RequestURI.ToString()} {SIPVersion}\r\n");
 }