Пример #1
0
        public IsapiContext(
            IntPtr conn,
            [MarshalAs(UnmanagedType.LPStr)] string verb,
            [MarshalAs(UnmanagedType.LPStr)] string query,
            [MarshalAs(UnmanagedType.LPStr)] string pathInfo,
            [MarshalAs(UnmanagedType.LPStr)] string pathTranslated,
            [MarshalAs(UnmanagedType.LPStr)] string contentType,

            Int32 bytesDeclared,
            Int32 bytesAvailable, // if available < declared, you need to run `readClient` to get more
            IntPtr data,          // first blush of data, if any

            Delegates.GetServerVariableDelegate getServerVariable, Delegates.WriteClientDelegate writeClient, Delegates.ReadClientDelegate readClient, IntPtr serverSupport)
        {
            _conn              = conn;
            _verb              = verb;
            _pathInfo          = pathInfo;
            _getServerVariable = getServerVariable;

            Request = new IsapiRequest(conn, verb, query, pathInfo, pathTranslated, contentType,
                                       bytesDeclared, bytesAvailable, data, getServerVariable,
                                       writeClient, readClient, serverSupport);

            Response = new IsapiResponse(conn, verb, query, pathInfo, pathTranslated, contentType,
                                         bytesDeclared, bytesAvailable, data, getServerVariable,
                                         writeClient, readClient, serverSupport);
        }
Пример #2
0
        // ReSharper disable UnusedParameter.Local
        public IsapiRequest(IntPtr conn, string verb, string query, string pathInfo, string pathTranslated, string contentType, int bytesDeclared, int bytesAvailable, IntPtr data, Delegates.GetServerVariableDelegate getServerVariable, Delegates.WriteClientDelegate writeClient, Delegates.ReadClientDelegate readClient, IntPtr serverSupport)
        // ReSharper restore UnusedParameter.Local
        {
            _conn = conn;
            _getServerVariable = getServerVariable;

            HttpMethod = verb;

            // TODO: make these lazy?

            if (bytesDeclared > 0)
            {
                InputStream = new IsapiClientStream(_conn, bytesAvailable, bytesDeclared, data, readClient);
            }
            else
            {
                InputStream = new MemoryStream();
            }

            QueryString        = query.ParseQueryString();
            Headers            = new DictionaryHeaderWrapper(SplitToDict(GetServerUnicodeVariable("UNICODE_ALL_RAW")));
            IsSecureConnection = GetServerAnsiVariable("HTTPS") == "ON";

            RawUrl = GetFullRawUrl();

            ProtocolVersion   = ParseVersion(GetServerAnsiVariable("SERVER_PROTOCOL"));
            HasAcceptEncoding = Headers.Get("Accept-Encoding") != null;

            RemoteEndPoint = new IPEndPoint(IPAddress.Parse(GetServerAnsiVariable("REMOTE_ADDR")), 0);

            ContentEncoding = GuessContentEncoding();
        }
Пример #3
0
        public static void HandleHttpRequestCallback(
            #region params
            IntPtr conn,
            [MarshalAs(UnmanagedType.LPStr)] string verb,
            [MarshalAs(UnmanagedType.LPStr)] string query,
            [MarshalAs(UnmanagedType.LPStr)] string pathInfo,
            [MarshalAs(UnmanagedType.LPStr)] string pathTranslated,
            [MarshalAs(UnmanagedType.LPStr)] string contentType, // not really useful.

            Int32 bytesDeclared,
            Int32 bytesAvailable, // if available < declared, you need to run `readClient` to get more
            IntPtr data,          // first blush of data, if any

            Delegates.GetServerVariableDelegate getServerVariable, Delegates.WriteClientDelegate writeClient, Delegates.ReadClientDelegate readClient, IntPtr serverSupport)
        #endregion
        {
            try
            {
                _core?.Handle(
                    new IsapiContext(
                        conn, verb, query, pathInfo, pathTranslated, contentType,
                        bytesDeclared, bytesAvailable, data, getServerVariable,
                        writeClient, readClient, serverSupport)
                    );
            }
            catch (Exception ex)
            {
                var ms    = new MemoryStream();
                var bytes = Encoding.UTF8.GetBytes("<pre>" + ex + "</pre>");
                ms.Write(bytes, 0, bytes.Length);
                ms.WriteByte(0);
                ms.Seek(0, SeekOrigin.Begin);
                var msg = ms.ToArray();
                int len = msg.Length;

                WriteErrorHeaders(conn, serverSupport);
                writeClient(conn, msg, ref len, 0);
            }
        }
Пример #4
0
 // ReSharper disable UnusedParameter.Local
 public IsapiResponse(IntPtr conn, string verb, string query, string pathInfo, string pathTranslated, string contentType, int bytesDeclared, int bytesAvailable, IntPtr data, Delegates.GetServerVariableDelegate getServerVariable, Delegates.WriteClientDelegate writeClient, Delegates.ReadClientDelegate readClient, IntPtr serverSupport)
 // ReSharper restore UnusedParameter.Local
 {
     _conn          = conn;
     _writeClient   = writeClient;
     _serverSupport = serverSupport;
     OutputStream   = new MemoryStream();
     Headers        = new NameValueCollectionHeaderWrapper(new NameValueCollection());
 }