public override void CloseConnection() { if (requestBroker != null) { // We check for headersSent as broken user code might call // CloseConnection at an early stage. requestBroker.Close(requestId, (headersSent ? keepAlive : false)); requestBroker = null; } }
public override void CloseConnection() { if (requestBroker == null) { return; } // We check for headersSent as broken user code might call // CloseConnection at an early stage. requestBroker.Close(requestId, headersSent && keepAlive); requestBroker = null; }
void RunInternal(object state) { RequestData rdata = initial.RequestData; initial.FreeBuffer(); string vhost = null; // TODO: read the headers in InitialWorkerRequest int port = ((IPEndPoint)localEP).Port; VPathToHost vapp = server.GetApplicationForPath(vhost, port, rdata.Path, true); XSPApplicationHost host = null; if (vapp != null) { host = (XSPApplicationHost)vapp.AppHost; } if (host == null) { byte [] nf = HttpErrors.NotFound(rdata.Path); Write(nf, 0, nf.Length); Close(); return; } broker = (XSPRequestBroker)vapp.RequestBroker; requestId = broker.RegisterRequest(this); #if MONO if (ssl != null) { SslServerStream s = (stream as SslServerStream); ssl.KeySize = s.CipherStrength; ssl.SecretKeySize = s.KeyExchangeStrength; } #endif try { string redirect; vapp.Redirect(rdata.Path, out redirect); host.ProcessRequest(requestId, localEP.Address.Address, localEP.Port, remoteEP.Address.Address, remoteEP.Port, rdata.Verb, rdata.Path, rdata.QueryString, rdata.Protocol, rdata.InputBuffer, redirect, sock.Handle, ssl); } catch (FileNotFoundException fnf) { // We print this one, as it might be a sign of a bad deployment // once we require the .exe and Mono.WebServer in bin or the GAC. Console.Error.WriteLine(fnf); } catch (IOException) { // This is ok (including EndOfStreamException) } catch (Exception e) { Console.Error.WriteLine(e); } }
public override void CloseConnection() { if (requestBroker == null) return; // We check for headersSent as broken user code might call // CloseConnection at an early stage. requestBroker.Close (requestId, headersSent && keepAlive); requestBroker = null; }
public XSPWorkerRequest(int requestId, XSPRequestBroker requestBroker, IApplicationHost appHost, EndPoint localEP, EndPoint remoteEP, string verb, string path, string queryString, string protocol, byte[] inputBuffer, IntPtr socket, bool secure) : base(appHost) { this.socket = socket; this.requestId = requestId; this.requestBroker = requestBroker; this.remoteEP = remoteEP; this.verb = verb; rawUrl = path; if (!String.IsNullOrEmpty (queryString)) rawUrl += "?" + queryString; try { Paths.GetPathsFromUri (appHost, verb, path, out this.path, out pathInfo); } catch { CloseConnection (); throw; } this.protocol = protocol; if (protocol == "HTTP/1.1") { if (!running_tests) this.protocol = "HTTP/1.0"; keepAlive = true; } this.queryString = queryString; this.inputBuffer = inputBuffer; inputLength = inputBuffer.Length; position = 0; this.secure = secure; try { GetRequestHeaders (); } catch { CloseConnection (); throw; } var cncHeader = (string) headers ["Connection"]; if (cncHeader != null) { cncHeader = cncHeader.ToLower (); if (cncHeader.IndexOf ("keep-alive") != -1) keepAlive = true; if (cncHeader.IndexOf ("close") != -1) keepAlive = false; } if (secure) keepAlive = false; //FIXME: until the NetworkStream don't own the socket for ssl streams. responseHeaders = new StringBuilder (); statusCode = 200; statusDescription = "OK"; localPort = ((IPEndPoint) localEP).Port; localAddress = ((IPEndPoint) localEP).Address.ToString(); }
void RunInternal(object state) { RequestData rdata = initial.RequestData; initial.FreeBuffer (); string vhost = null; // TODO: read the headers in InitialWorkerRequest int port = ((IPEndPoint) localEP).Port; VPathToHost vapp; try { vapp = server.GetApplicationForPath (vhost, port, rdata.Path, true); } catch (Exception e){ // // This happens if the assembly is not in the GAC, so we report this // error here. // Console.Error.WriteLine (e); return; } XSPApplicationHost host = null; if (vapp != null) host = (XSPApplicationHost) vapp.AppHost; if (host == null) { byte [] nf = HttpErrors.NotFound (rdata.Path); Write (nf, 0, nf.Length); Close (); return; } broker = (XSPRequestBroker) vapp.RequestBroker; requestId = broker.RegisterRequest (this); if (ssl != null) { SslServerStream s = (stream as SslServerStream); ssl.KeySize = s.CipherStrength; ssl.SecretKeySize = s.KeyExchangeStrength; } try { string redirect; vapp.Redirect (rdata.Path, out redirect); host.ProcessRequest (requestId, localEP, remoteEP, rdata.Verb, rdata.Path, rdata.QueryString, rdata.Protocol, rdata.InputBuffer, redirect, sock.Handle, ssl); } catch (FileNotFoundException fnf) { // We print this one, as it might be a sign of a bad deployment // once we require the .exe and Mono.WebServer in bin or the GAC. Console.Error.WriteLine (fnf); } catch (IOException) { // This is ok (including EndOfStreamException) } catch (Exception e) { Console.Error.WriteLine (e); } }
public XSPWorkerRequest(int requestId, XSPRequestBroker requestBroker, IApplicationHost appHost, EndPoint localEP, EndPoint remoteEP, string verb, string path, string queryString, string protocol, byte[] inputBuffer, IntPtr socket, bool secure) : base(appHost) { this.socket = socket; this.requestId = requestId; this.requestBroker = requestBroker; this.remoteEP = remoteEP; this.verb = verb; rawUrl = path; if (!String.IsNullOrEmpty(queryString)) { rawUrl += "?" + queryString; } try { Paths.GetPathsFromUri(appHost, verb, path, out this.path, out pathInfo); } catch { CloseConnection(); throw; } this.protocol = protocol; if (protocol == "HTTP/1.1") { if (!running_tests) { this.protocol = "HTTP/1.0"; } keepAlive = true; } this.queryString = queryString; this.inputBuffer = inputBuffer; inputLength = inputBuffer.Length; position = 0; this.secure = secure; try { GetRequestHeaders(); } catch { CloseConnection(); throw; } var cncHeader = (string)headers ["Connection"]; if (cncHeader != null) { cncHeader = cncHeader.ToLower(); if (cncHeader.IndexOf("keep-alive") != -1) { keepAlive = true; } if (cncHeader.IndexOf("close") != -1) { keepAlive = false; } } if (secure) { keepAlive = false; //FIXME: until the NetworkStream don't own the socket for ssl streams. } responseHeaders = new StringBuilder(); statusCode = 200; statusDescription = "OK"; localPort = ((IPEndPoint)localEP).Port; localAddress = ((IPEndPoint)localEP).Address.ToString(); }
public void ProcessRequest(int reqId, IPEndPoint localEP, IPEndPoint remoteEP, string verb, string path, string queryString, string protocol, byte [] inputBuffer, string redirect, IntPtr socket, SslInformation ssl) { XSPRequestBroker broker = (XSPRequestBroker)RequestBroker; bool secure = (ssl != null); XSPWorkerRequest mwr = new XSPWorkerRequest(reqId, broker, this, localEP, remoteEP, verb, path, queryString, protocol, inputBuffer, socket, secure); if (secure) { // note: we're only setting what we use (and not the whole lot) mwr.AddServerVariable("CERT_KEYSIZE", ssl.KeySize.ToString(CultureInfo.InvariantCulture)); mwr.AddServerVariable("CERT_SECRETKEYSIZE", ssl.SecretKeySize.ToString(CultureInfo.InvariantCulture)); if (ssl.RawClientCertificate != null) { // the worker need to be able to return it (if asked politely) mwr.SetClientCertificate(ssl.RawClientCertificate); // XSPWorkerRequest will answer, as required, for CERT_COOKIE, CERT_ISSUER, // CERT_SERIALNUMBER and CERT_SUBJECT (as anyway it requires the client // certificate - if it was provided) if (ssl.ClientCertificateValid) { // client cert present (bit0 = 1) and valid (bit1 = 0) mwr.AddServerVariable("CERT_FLAGS", "1"); } else { // client cert present (bit0 = 1) but invalid (bit1 = 1) mwr.AddServerVariable("CERT_FLAGS", "3"); } } else { // no client certificate (bit0 = 0) ? does bit1 matter ? mwr.AddServerVariable("CERT_FLAGS", "0"); } if (ssl.RawServerCertificate != null) { X509Certificate server = ssl.GetServerCertificate(); mwr.AddServerVariable("CERT_SERVER_ISSUER", server.GetIssuerName()); mwr.AddServerVariable("CERT_SERVER_SUBJECT", server.GetName()); } } string translated = mwr.GetFilePathTranslated(); if (path [path.Length - 1] != '/' && Directory.Exists(translated)) { redirect = path + '/'; } if (redirect != null) { Redirect(mwr, redirect); broker.UnregisterRequest(reqId); return; } ProcessRequest(mwr); }
public override void CloseConnection() { if (requestBroker != null) { // We check for headersSent as broken user code might call // CloseConnection at an early stage. requestBroker.Close (requestId, (headersSent ? keepAlive : false)); requestBroker = null; } }