public IsapiClientStream(IntPtr connId, int bytesAvailable, int bytesDeclared, IntPtr data, Delegates.ReadClientDelegate readClient) { _connId = connId; _bytesAvailable = bytesAvailable; _readClient = readClient; Length = bytesDeclared; Position = 0; _remaining = bytesAvailable; _initialBytes = new byte[bytesAvailable]; Marshal.Copy(data, _initialBytes, 0, bytesAvailable); }
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); }
// 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()); }
// 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(); }
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); } }