Exemplo n.º 1
0
        public override int ReadEntityBody(byte[] buffer, int size)
        {
            int read = MonoInternal.ReadInputData(_request, buffer, size, _offset);

            _offset += read;
            return(read);
        }
Exemplo n.º 2
0
 public override bool IsEntireEntityBodyIsPreloaded()
 {
     if (_inputDataType == InputDataType.Unknown)
     {
         _inputDataType = (InputDataType)MonoInternal.GetInputDataType(_request);
     }
     return(_inputDataType == InputDataType.Memory);
 }
Exemplo n.º 3
0
        public override string GetRemoteAddress()
        {
            string addr = MonoInternal.GetServerVariable(_request, "REMOTE_ADDR");

            if (!string.IsNullOrEmpty(addr))
            {
                return(addr);
            }
            return("127.0.0.1");
        }
Exemplo n.º 4
0
 public override byte[] GetPreloadedEntityBody()
 {
     if (IsEntireEntityBodyIsPreloaded())
     {
         if (_inputData == null)
         {
             _inputData = MonoInternal.GetInputData(_request);
         }
         return(_inputData);
     }
     return(null);
 }
Exemplo n.º 5
0
        public override int GetRemotePort()
        {
            string port = MonoInternal.GetServerVariable(_request, "REMOTE_PORT");

            if (!string.IsNullOrEmpty(port))
            {
                int ret;
                if (int.TryParse(port, out ret))
                {
                    return(ret);
                }
            }
            return(80);
        }
Exemplo n.º 6
0
 public override void SendKnownResponseHeader(int index, string value)
 {
     switch (index)
     {
     case HeaderCacheControl:
     case HeaderContentType:
     case HeaderContentRange:
     case HeaderExpires:
     case HeaderLastModified:
     case HeaderAcceptRanges:
     case HeaderEtag:
     case HeaderLocation:
     case HeaderSetCookie:
     case HeaderWwwAuthenticate:
         MonoInternal.SetHeader(_request, index, value);
         break;
     }
 }
Exemplo n.º 7
0
        public override string GetLocalAddress()
        {
            string address = MonoInternal.GetServerVariable(_request, "SERVER_ADDR");

            if (!string.IsNullOrEmpty(address))
            {
                return(address);
            }

            address = AddressFromHostName(MonoInternal.GetServerVariable(_request, "HTTP_HOST"));
            if (!string.IsNullOrEmpty(address))
            {
                return(address);
            }

            address = AddressFromHostName(MonoInternal.GetServerVariable(_request, "SERVER_NAME"));
            if (!string.IsNullOrEmpty(address))
            {
                return(address);
            }

            return("localhost");
        }
Exemplo n.º 8
0
        private unsafe void InitRequestHeader()
        {
            string header = MonoInternal.GetRequestHeader(_request);
            List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >(16);

            #region Parse Header
            fixed(char *p = header)
            {
                char *begin = p;
                char *end   = begin + header.Length;

                int   line  = 0;
                char *start = begin;

                for (char *cur = begin; cur < end; ++cur)
                {
                    if (*cur == '\n')
                    {
                        if (line == 0)
                        {
                            #region Parse Method

                            _method = new string(start, 0, (int)(cur - start));

                            #endregion
                        }
                        else if (line == 1)
                        {
                            #region Parse Url

                            _rawUrl = new string(start, 0, (int)(cur - start));

                            char *t = start;
                            for (; t < cur; ++t)
                            {
                                if (*t == '?')
                                {
                                    _pathInfo = new string(start, 0, (int)(t - start));
                                    ++t;
                                    break;
                                }
                            }
                            if (cur > t)
                            {
                                _queryString = new string(t, 0, (int)(cur - t));
                            }
                            else
                            {
                                _pathInfo    = _rawUrl;
                                _queryString = null;
                            }

                            #endregion
                        }
                        else if (line == 2)
                        {
                            #region Parse Version

                            _version = new string(start, 0, (int)(cur - start));

                            #endregion
                        }
                        else
                        {
                            #region Parse Headers

                            string tmp = null;

                            char *t = start;
                            for (; t < cur; ++t)
                            {
                                if (*t == ':')
                                {
                                    tmp = new string(start, 0, (int)(t - start));
                                    ++t;
                                    break;
                                }
                            }
                            if (tmp != null)
                            {
                                if (cur > t)
                                {
                                    list.Add(new KeyValuePair <string, string>(tmp, new string(t, 0, (int)(cur - t))));
                                }
                                else
                                {
                                    list.Add(new KeyValuePair <string, string>(tmp, string.Empty));
                                }
                            }

                            #endregion
                        }

                        ++line;

                        start = cur + 1;
                    }
                }
            }

            #endregion

            #region Format Headers

            _knownRequestHeaders = new string[RequestHeaderMaximum];
            string[][] headers = new string[list.Count][];
            int        count   = 0;
            int        id;
            foreach (KeyValuePair <string, string> pair in list)
            {
                id = GetKnownRequestHeaderIndex(pair.Key);

                if (id >= 0)
                {
                    _knownRequestHeaders[id] = pair.Value;
                    continue;
                }

                headers[count++] = new string[] { pair.Key, pair.Value };
            }

            _unknownRequestHeaders = new string[count][];
            if (count > 0)
            {
                Array.Copy(headers, 0, _unknownRequestHeaders, 0, count);
            }

            #endregion
        }
Exemplo n.º 9
0
 public void Error(int status, string message)
 => MonoInternal.SetError(_request, _response, status, message);
Exemplo n.º 10
0
 public override void SendUnknownResponseHeader(string name, string value)
 {
     MonoInternal.SetUnknownHeader(_request, name, value);
 }
Exemplo n.º 11
0
 public override void SendStatus(int statusCode, string statusDescription)
 {
     MonoInternal.SetStatus(_request, statusCode);
 }
Exemplo n.º 12
0
 public override void SendResponseFromMemory(byte[] data, int length)
 {
     MonoInternal.SendContent(_request, _response, data, length);
 }
Exemplo n.º 13
0
 public override void SendResponseFromFile(string filename, long offset, long length)
 {
     MonoInternal.SendFile(_request, _response, filename, offset, length);
 }
Exemplo n.º 14
0
 public override bool IsSecure()
 {
     return(MonoInternal.GetServerVariable(_request, "HTTPS") == "on");
 }
Exemplo n.º 15
0
        public override string GetServerVariable(string name)
        {
            string value = MonoInternal.GetServerVariable(_request, name);

            if (value != null)
            {
                return(value);
            }

            if (IsSecure())
            {
                X509Certificate client = ClientCertificate;
                switch (name)
                {
                case "CERT_COOKIE":
                    if (_certCookie == null)
                    {
                        if (client == null)
                        {
                            _certCookie = string.Empty;
                        }
                        else
                        {
                            _certCookie = client.GetCertHashString();
                        }
                    }
                    return(_certCookie);

                case "CERT_ISSUER":
                    if (_certIssuer == null)
                    {
                        if (client == null)
                        {
                            _certIssuer = string.Empty;
                        }
                        else
                        {
                            _certIssuer = client.Issuer;
                        }
                    }
                    return(_certIssuer);

                case "CERT_SERIALNUMBER":
                    if (_certSerial == null)
                    {
                        if (client == null)
                        {
                            _certSerial = string.Empty;
                        }
                        else
                        {
                            _certSerial = client.GetSerialNumberString();
                        }
                    }
                    return(_certSerial);

                case "CERT_SUBJECT":
                    if (_certSubject == null)
                    {
                        if (client == null)
                        {
                            _certSubject = string.Empty;
                        }
                        else
                        {
                            _certSubject = client.Subject;
                        }
                    }
                    return(_certSubject);
                }
            }

            return(base.GetServerVariable(name));
        }
Exemplo n.º 16
0
 public override string GetServerName()
 {
     return((HostNameFromString(MonoInternal.GetServerVariable(_request, "SERVER_NAME"))
             ?? HostNameFromString(MonoInternal.GetServerVariable(_request, "HTTP_HOST")))
            ?? GetLocalAddress());
 }