コード例 #1
0
        public Tuple <string, string> Decode()
        {
            if (HeaderString == null)
            {
                throw new ArgumentNullException(nameof(HeaderString));
            }

            const string authType = "Basic";

            // TODO: Support other types as well
            if (!HeaderString.StartsWith(authType))
            {
                throw new Exception("The authentication type is not Basic");
            }

            string encoded  = HeaderString.Substring(authType.Length).Trim();
            string combined = Decode(encoded);

            int separatorIndex = combined.IndexOf(':');

            if (separatorIndex < 0)
            {
                throw new Exception("The format of the header is not valid");
            }

            string username = combined.Substring(0, separatorIndex);
            string password = combined.Substring(separatorIndex + 1);

            return(new Tuple <string, string>(username, password));
        }
コード例 #2
0
ファイル: NIF_IO.cs プロジェクト: libcs/game-estates
        //HeaderString
        public static void NifStream(out HeaderString val, IStream s, NifInfo info)
        {
            val = new HeaderString
            {
                header = s.GetLine(Buf, 256)
            };
            // make sure this is a NIF file
            int ver_start = 0;

            if (val.header.Substring(0, 22) == "NetImmerse File Format")
            {
                ver_start = 32;
            }
            else if (val.header.Substring(0, 20) == "Gamebryo File Format")
            {
                ver_start = 30;
            }
            else if (val.header.Substring(0, 6) == "NDSNIF")
            {
                ver_start = 30;
            }
            else
            {
                info.version = VER_INVALID;  //Not a NIF file
            }
            //Parse version string and return result.
            info.version = ParseVersionString(val.header.Substring(ver_start));
        }
コード例 #3
0
ファイル: ExportData.cs プロジェクト: Data-Online/OLR
        virtual protected bool WriteColumnHeader(bool exportRawValues)
        {
            // If the DisplayString is not null then, write the contents of DisplayString as column headers
            if (base.HeaderString != null && base.HeaderString != "")
            {
                Writer.Write(HeaderString.Replace("\"", "\"\""));
                return(true);
            }

            return(false);
        }
コード例 #4
0
        // Sub New(ByVal buffer() As Byte, ByVal server As Server, ByVal client As Socket, ByVal site As Site)
        //     MyBase.new()
        //     _server = server
        //     Me.Site = site
        //     Me.ClientAddress = client.RemoteEndPoint.ToString
        //     ' convert the raw request data into a string and parse it
        //     'Me.RequestString = System.Encoding.Default.GetString(buffer).Replace(Chr(0), "")
        //     Me.RequestString = System.Encoding.ASCII.GetString(buffer).Trim(Chr(0))
        //     ' parse raw data into strings
        //     Me.Parse(Me.RequestString)
        //     ' parse strings into strongly typed properties
        //     Me.ParseRequestString(Me.RequestString)
        // End Sub
        // '' <summary>
        // '' Parses the raw request string received from the client socket
        // '' </summary>
        // '' <param name="requestString"></param>
        // '' <remarks></remarks>
        private void ParseRequestString(string requestString)
        {
            //  parse the requestString to build up the request object
            string[] headerStringParts = HeaderString.Split('\n');
            if (headerStringParts[0].StartsWith("HEAD") || headerStringParts[0].StartsWith("GET") || headerStringParts[0].StartsWith("POST"))
            {
                //  parse the request line
                RequestLine = headerStringParts[0];
                string[] requestLineParts;
                requestLineParts = RequestLine.Split(' ');
                Method           = requestLineParts[0];
                Uri      = requestLineParts[1];
                Protocol = requestLineParts[2];
                //  build the relative and absolute path to the file
                RelPath = Uri.Replace("/", "\\");
                if (Uri.Contains("?"))
                {
                    string[] uriParts = Uri.Split('?');
                    RelPath     = uriParts[0].Replace("/", "\\");
                    QueryString = ("?" + uriParts[1]);
                }

                AbsPath = (Site.RootPath + RelPath);
                //  if the requested path was a directory, use the default document
                if (Directory.Exists(AbsPath))
                {
                    //  if the requested path was a directory, but the Uri was missing a trailing slash, we need to 301 redirect to the correct Uri
                    if (Uri.EndsWith("/"))
                    {
                        FixPath301 = true;
                    }

                    //  build the paths to the requested resource
                    //  TODO: file.exists is one of the slowest operations here, cache it...
                    //    however, we are already caching responses and we should skip this function for cached responses which we are not currently doing since we parse before handling cache...
                    foreach (string doc in _server.DefaultDocuments)
                    {
                        if (File.Exists((Site.RootPath
                                         + (RelPath + ("\\" + doc)))))
                        {
                            FileName = doc;
                            RelPath  = (RelPath + ("\\" + FileName));
                            AbsPath  = (Site.RootPath + RelPath);
                            break;
                        }
                    }

                    // Me.FileName = "index.html"
                    // Me.RelPath = Me.RelPath & "\" & Me.FileName
                    // Me.AbsPath = Me.Site.RootPath & Me.RelPath
                }
                else
                {
                    //  not a directory, get filename from abspath
                    FileName = Path.GetFileName(AbsPath);
                }

                //  TODO: if the directory was empty, Me.FileName will be empty here and we can't proceed with it; serve directory listing or return a 40X status code...
                if (FileName != null)
                {
                    //  build the scriptname
                    if (Uri.Contains(FileName))
                    {
                        ScriptName = Uri;
                    }
                    else
                    {
                        ScriptName = Uri + FileName + QueryString;
                    }

                    //  strip the querystring from the scriptname, causes problems with WP customizer
                    if (QueryString != "")
                    {
                        if (ScriptName.Contains(QueryString))
                        {
                            ScriptName = ScriptName.Replace(QueryString, "");
                        }
                    }

                    //  parse the requested resource's file type (extension) for use determining the mime type
                    FileType = Path.GetExtension(AbsPath).TrimStart('.');
                    //  parse the requested resource's mime type
                    MimeType m = ((MimeType)(_server.MimeTypes[FileType]));
                    if (m == null)
                    {
                        m = (MimeType)_server.MimeTypes[""];
                    }

                    MimeType = m;
                    //  set content length
                    ContentLength = ContentStringLength;
                    //  set the content bytes
                    Content = Encoding.ASCII.GetBytes(ContentString);
                }
            }
        }
コード例 #5
0
ファイル: NIF_IO.cs プロジェクト: libcs/game-estates
 public static void NifStream(HeaderString val, OStream s, NifInfo info)
 {
     s += (info.version <= VER_10_0_1_0 ? "NetImmerse File Format, Version " : "Gamebryo File Format, Version ");
     s += FormatVersionString(info.version);
     s += "\n";
 }