/// <summary> /// Initializes a new instance of the <see cref="HttpContextFactory"/> class. /// </summary> /// <param name="writer">The writer.</param> /// <param name="bufferSize">Amount of bytes to read from the incoming socket stream.</param> /// <param name="factory">Used to create a request parser.</param> /// <param name="rootCA">Root certificate that incoming client certificates were signed with</param> public HttpContextFactory(ILogWriter writer, int bufferSize, IRequestParserFactory factory, X509Certificate rootCA) { _logWriter = writer; _bufferSize = bufferSize; _factory = factory; _rootCA = rootCA; }
/// <summary> /// Initializes a new instance of the <see cref="HttpClientContext"/> class. /// </summary> /// <param name="secured">true if the connection is secured (SSL/TLS)</param> /// <param name="remoteEndPoint">client that connected.</param> /// <param name="stream">Stream used for communication</param> /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param> /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 1024 bytes.</param> /// <param name="sock">Socket to use.</param> /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception> /// <exception cref="ArgumentException">Stream must be writable and readable.</exception> public HttpClientContext( bool secured, IPEndPoint remoteEndPoint, Stream stream, IRequestParserFactory parserFactory, int bufferSize, Socket sock) { Check.Require(remoteEndPoint, "remoteEndPoint"); Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address"); Check.Require(stream, "stream"); Check.Require(parserFactory, "parser"); Check.Min(1024, bufferSize, "bufferSize"); Check.Require(sock, "socket"); if (!stream.CanWrite || !stream.CanRead) { throw new ArgumentException("Stream must be writable and readable."); } _bufferSize = bufferSize; RemoteAddress = remoteEndPoint.Address.ToString(); RemotePort = remoteEndPoint.Port.ToString(); _log = NullLogWriter.Instance; _parser = parserFactory.CreateParser(_log); _parser.RequestCompleted += OnRequestCompleted; _parser.RequestLineReceived += OnRequestLine; _parser.HeaderReceived += OnHeaderReceived; _parser.BodyBytesReceived += OnBodyBytesReceived; _currentRequest = new HttpRequest(); IsSecured = secured; _stream = stream; _buffer = new byte[bufferSize]; }
/// <summary> /// Initializes a new instance of the <see cref="HttpClientContext"/> class. /// </summary> /// <param name="secured">true if the connection is secured (SSL/TLS)</param> /// <param name="remoteEndPoint">client that connected.</param> /// <param name="stream">Stream used for communication</param> /// <param name="clientCertificate">Client security certificate</param> /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param> /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param> /// <param name="socket">Client socket</param> /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception> /// <exception cref="ArgumentException">Stream must be writable and readable.</exception> public HttpClientContext(bool secured, IPEndPoint remoteEndPoint, Stream stream, ClientCertificate clientCertificate, IRequestParserFactory parserFactory, int bufferSize, Socket socket) { Check.Require(remoteEndPoint, "remoteEndPoint"); Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address"); Check.Require(stream, "stream"); Check.Require(parserFactory, "parser"); Check.Min(4096, bufferSize, "bufferSize"); Check.Require(socket, "socket"); if (!stream.CanWrite || !stream.CanRead) throw new ArgumentException("Stream must be writable and readable."); _bufferSize = bufferSize; RemoteAddress = remoteEndPoint.Address.ToString(); RemotePort = remoteEndPoint.Port.ToString(); _log = NullLogWriter.Instance; _parser = parserFactory.CreateParser(_log); _parser.RequestCompleted += OnRequestCompleted; _parser.RequestLineReceived += OnRequestLine; _parser.HeaderReceived += OnHeaderReceived; _parser.BodyBytesReceived += OnBodyBytesReceived; _localEndPoint = (IPEndPoint)socket.LocalEndPoint; HttpRequest request = new HttpRequest(); request._remoteEndPoint = remoteEndPoint; request.Secure = secured; _currentRequest = request; IsSecured = secured; _stream = stream; _clientCertificate = clientCertificate; _buffer = new byte[bufferSize]; }
/// <summary> /// Initializes a new instance of the <see cref="HttpContextFactory"/> class. /// </summary> /// <param name="writer">The writer.</param> /// <param name="bufferSize">Amount of bytes to read from the incoming socket stream.</param> /// <param name="factory">Used to create a request parser.</param> public HttpContextFactory(ILogWriter writer, int bufferSize, IRequestParserFactory factory) { _logWriter = writer; _bufferSize = bufferSize; _factory = factory; _contextTimeoutManager = new ContextTimeoutManager(ContextTimeoutManager.MonitorType.Thread); }
/// <summary> /// Initializes a new instance of the <see cref="HttpClientContext"/> class. /// </summary> /// <param name="secured">true if the connection is secured (SSL/TLS)</param> /// <param name="remoteEndPoint">client that connected.</param> /// <param name="stream">Stream used for communication</param> /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param> /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param> /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception> /// <exception cref="ArgumentException">Stream must be writable and readable.</exception> public HttpClientContext(bool secured, IPEndPoint remoteEndPoint, Stream stream, IRequestParserFactory parserFactory, int bufferSize, Socket sock, ILogWriter log) { Check.Require(remoteEndPoint, "remoteEndPoint"); Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address"); Check.Require(stream, "stream"); Check.Require(parserFactory, "parser"); Check.Min(4096, bufferSize, "bufferSize"); Check.Require(sock, "socket"); if (!stream.CanWrite || !stream.CanRead) throw new ArgumentException("Stream must be writable and readable."); _bufferSize = bufferSize; RemoteAddress = remoteEndPoint.Address.ToString(); RemotePort = remoteEndPoint.Port.ToString(); _log = log; _parser = parserFactory.CreateParser(_log); _parser.RequestCompleted += OnRequestCompleted; _parser.RequestLineReceived += OnRequestLine; _parser.HeaderReceived += OnHeaderReceived; _parser.BodyBytesReceived += OnBodyBytesReceived; _currentRequest = new HttpRequest(); IsSecured = secured; if (stream == null) throw new NullReferenceException ("Null Stream in HttpClientContext"); _stream = stream; _buffer = new byte[bufferSize]; }
/// <summary> /// Initializes a new instance of the <see cref="HttpClientContext"/> class. /// </summary> /// <param name="secured">true if the connection is secured (SSL/TLS)</param> /// <param name="remoteEndPoint">client that connected.</param> /// <param name="stream">Stream used for communication</param> /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param> /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param> /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception> /// <exception cref="ArgumentException">Stream must be writable and readable.</exception> public HttpClientContext(bool secured, IPEndPoint remoteEndPoint, Stream stream, IRequestParserFactory parserFactory, Socket sock) { Check.Require(remoteEndPoint, "remoteEndPoint"); Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address"); Check.Require(stream, "stream"); Check.Require(parserFactory, "parser"); Check.Require(sock, "socket"); if (!stream.CanWrite || !stream.CanRead) { throw new ArgumentException("Stream must be writable and readable."); } RemoteAddress = remoteEndPoint.Address.ToString(); RemotePort = remoteEndPoint.Port.ToString(); _log = NullLogWriter.Instance; m_parser = parserFactory.CreateParser(_log); m_parser.RequestCompleted += OnRequestCompleted; m_parser.RequestLineReceived += OnRequestLine; m_parser.HeaderReceived += OnHeaderReceived; m_parser.BodyBytesReceived += OnBodyBytesReceived; m_currentRequest = new HttpRequest(this); IsSecured = secured; _stream = stream; m_sock = sock; m_bufferSize = 8196; m_ReceiveBuffer = new byte[m_bufferSize]; requestsInServiceIDs = new HashSet <uint>(); SSLCommonName = ""; if (secured) { SslStream _ssl = (SslStream)_stream; X509Certificate _cert1 = _ssl.RemoteCertificate; if (_cert1 != null) { X509Certificate2 _cert2 = new X509Certificate2(_cert1); if (_cert2 != null) { SSLCommonName = _cert2.GetNameInfo(X509NameType.SimpleName, false); } } } ++basecontextID; if (basecontextID <= 0) { basecontextID = 1; } contextID = basecontextID; }
/// <summary> /// Initializes a new instance of the <see cref="HttpContextFactory"/> class. /// </summary> /// <param name="writer">The writer.</param> /// <param name="bufferSize">Amount of bytes to read from the incoming socket stream.</param> /// <param name="factory">Used to create a request parser.</param> public HttpContextFactory(ILogWriter writer, int bufferSize, IRequestParserFactory factory) { _logWriter = writer; _bufferSize = bufferSize; _factory = factory; // by Fumi.Iseki if (ClientCertificateValidationCallback != null) { _clientCallback = ClientCertificateValidationCallback; ClientCertificateValidationCallback = null; } }
/// <summary> /// Initializes a new instance of the <see cref="HttpContextFactory"/> class. /// </summary> /// <param name="writer">The writer.</param> /// <param name="bufferSize">Amount of bytes to read from the incoming socket stream.</param> /// <param name="factory">Used to create a request parser.</param> public HttpContextFactory(ILogWriter writer, int bufferSize, IRequestParserFactory factory) { _logWriter = writer; _bufferSize = bufferSize; _factory = factory; _contextTimeoutManager = new ContextTimeoutManager(ContextTimeoutManager.MonitorType.Thread); // by Fumi.Iseki if (ClientCertificateValidationCallback != null) { _clientCallback = ClientCertificateValidationCallback; ClientCertificateValidationCallback = null; } }
/// <summary> /// Initializes a new instance of the <see cref="HttpClientContext"/> class. /// </summary> /// <param name="secured">true if the connection is secured (SSL/TLS)</param> /// <param name="remoteEndPoint">client that connected.</param> /// <param name="stream">Stream used for communication</param> /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param> /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param> /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception> /// <exception cref="ArgumentException">Stream must be writable and readable.</exception> public HttpClientContext(bool secured, IPEndPoint remoteEndPoint, Stream stream, IRequestParserFactory parserFactory, int bufferSize, Socket sock) { Check.Require(remoteEndPoint, "remoteEndPoint"); Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address"); Check.Require(stream, "stream"); Check.Require(parserFactory, "parser"); Check.Min(4096, bufferSize, "bufferSize"); Check.Require(sock, "socket"); if (!stream.CanWrite || !stream.CanRead) { throw new ArgumentException("Stream must be writable and readable."); } _bufferSize = bufferSize; RemoteAddress = remoteEndPoint.Address.ToString(); RemotePort = remoteEndPoint.Port.ToString(); _log = NullLogWriter.Instance; _parser = parserFactory.CreateParser(_log); _parser.RequestCompleted += OnRequestCompleted; _parser.RequestLineReceived += OnRequestLine; _parser.HeaderReceived += OnHeaderReceived; _parser.BodyBytesReceived += OnBodyBytesReceived; _currentRequest = new HttpRequest(); IsSecured = secured; _stream = stream; _buffer = new byte[bufferSize]; // by Fumi.Iseki SSLCommonName = ""; if (secured) { SslStream _ssl = (SslStream)_stream; X509Certificate _cert1 = _ssl.RemoteCertificate; if (_cert1 != null) { X509Certificate2 _cert2 = new X509Certificate2(_cert1); if (_cert2 != null) { SSLCommonName = _cert2.GetNameInfo(X509NameType.SimpleName, false); } } } }
/// <summary> /// Initializes a new instance of the <see cref="HttpClientContext"/> class. /// </summary> /// <param name="secured">true if the connection is secured (SSL/TLS)</param> /// <param name="remoteEndPoint">client that connected.</param> /// <param name="stream">Stream used for communication</param> /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param> /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param> /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception> /// <exception cref="ArgumentException">Stream must be writable and readable.</exception> public HttpClientContext(bool secured, IPEndPoint remoteEndPoint, Stream stream, IRequestParserFactory parserFactory, int bufferSize, Socket sock) { Check.Require(remoteEndPoint, "remoteEndPoint"); Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address"); Check.Require(stream, "stream"); Check.Require(parserFactory, "parser"); Check.Min(4096, bufferSize, "bufferSize"); Check.Require(sock, "socket"); if (!stream.CanWrite || !stream.CanRead) throw new ArgumentException("Stream must be writable and readable."); _bufferSize = bufferSize; RemoteAddress = remoteEndPoint.Address.ToString(); RemotePort = remoteEndPoint.Port.ToString(); _log = NullLogWriter.Instance; _parser = parserFactory.CreateParser(_log); _parser.RequestCompleted += OnRequestCompleted; _parser.RequestLineReceived += OnRequestLine; _parser.HeaderReceived += OnHeaderReceived; _parser.BodyBytesReceived += OnBodyBytesReceived; _currentRequest = new HttpRequest(); Available = false; IsSecured = secured; _stream = stream; _sock = sock; _buffer = new byte[bufferSize]; // by Fumi.Iseki SSLCommonName = ""; if (secured) { SslStream _ssl = (SslStream)_stream; X509Certificate _cert1 = _ssl.RemoteCertificate; if (_cert1 != null) { X509Certificate2 _cert2 = new X509Certificate2(_cert1); if (_cert2 != null) SSLCommonName = _cert2.GetNameInfo(X509NameType.SimpleName, false); } } }
/// <summary> /// Initializes a new instance of the <see cref="HttpContextFactory"/> class. /// </summary> /// <param name="writer">The writer.</param> /// <param name="bufferSize">Amount of bytes to read from the incoming socket stream.</param> /// <param name="factory">Used to create a request parser.</param> public HttpContextFactory(ILogWriter writer, int bufferSize, IRequestParserFactory factory) { _logWriter = writer; _bufferSize = bufferSize; _factory = factory; }
/// <summary> /// Initializes a new instance of the <see cref="HttpContextFactory"/> class. /// </summary> /// <param name="writer">The writer.</param> /// <param name="bufferSize">Amount of bytes to read from the incoming socket stream.</param> /// <param name="factory">Used to create a request parser.</param> public HttpContextFactory(ILogWriter writer, IRequestParserFactory factory) { _logWriter = writer; _factory = factory; ContextTimeoutManager.Start(); }