Ejemplo n.º 1
0
        public void Write(string s, int offset, int count)
        {
            bool buffering = response.BufferOutput;

            if (buffering)
            {
                // It does not matter whether we're in ApplyFilter or not
                AppendBuffer(s, offset, count);
            }
            else if (filter == null || filtering)
            {
                response.WriteHeaders(false);
                HttpWorkerRequest wr = response.WorkerRequest;
                // Direct write because not buffering
                wr.SendResponseFromMemory(s, offset, count, response.ContentEncoding);
                wr.FlushResponse(false);
            }
            else
            {
                // Write to the filter, which will call us back, and then Flush
                filtering = true;
                try {
                    byte [] bytesToWrite = response.ContentEncoding.GetBytes(s.ToCharArray(), offset, count);
                    filter.Write(bytesToWrite, 0, bytesToWrite.Length);
                }
                finally {
                    filtering = false;
                }
                Flush(response.WorkerRequest, false);
            }
        }
Ejemplo n.º 2
0
        //
        // This is called from the QueueManager if a request
        // can not be processed (load, no resources, or
        // appdomain unload).
        //
        static internal void FinishUnavailable(HttpWorkerRequest wr)
        {
            wr.SendStatus(503, "Service unavailable");
            wr.SendUnknownResponseHeader("Connection", "close");
            Encoding enc = Encoding.ASCII;

            wr.SendUnknownResponseHeader("Content-Type", "text/html; charset=" + enc.WebName);
            byte [] contentBytes = enc.GetBytes(content503);
            wr.SendUnknownResponseHeader("Content-Length", contentBytes.Length.ToString());
            wr.SendResponseFromMemory(contentBytes, contentBytes.Length);
            wr.FlushResponse(true);
            wr.CloseConnection();
            HttpApplication.requests_total_counter.Increment();
        }
Ejemplo n.º 3
0
        internal void Flush(HttpWorkerRequest wr, bool final_flush)
        {
            if (!dirty && !final_flush)
            {
                return;
            }

            for (Bucket b = first_bucket; b != null; b = b.Next)
            {
                b.Send(wr);
            }

            wr.FlushResponse(final_flush);
            Clear();
        }
Ejemplo n.º 4
0
		static void Redirect (HttpWorkerRequest wr, string location)
		{
			string host = wr.GetKnownRequestHeader (HttpWorkerRequest.HeaderHost);
			wr.SendStatus (301, "Moved Permanently");
			wr.SendUnknownResponseHeader ("Connection", "close");
			wr.SendUnknownResponseHeader ("Date", DateTime.Now.ToUniversalTime ().ToString ("r"));
			wr.SendUnknownResponseHeader ("Location", String.Format ("{0}://{1}{2}", wr.GetProtocol(), host, location));
			Encoding enc = Encoding.ASCII;
			wr.SendUnknownResponseHeader ("Content-Type", "text/html; charset=" + enc.WebName);
			string content = String.Format (CONTENT301, host, location);
			byte [] contentBytes = enc.GetBytes (content);
			wr.SendUnknownResponseHeader ("Content-Length", contentBytes.Length.ToString ());
			wr.SendResponseFromMemory (contentBytes, contentBytes.Length);
			wr.FlushResponse (true);
			wr.CloseConnection ();
		}
Ejemplo n.º 5
0
        static void FinishWithException(HttpWorkerRequest wr, HttpException e)
        {
            int code = e.GetHttpCode();

            wr.SendStatus(code, HttpWorkerRequest.GetStatusDescription(code));
            wr.SendUnknownResponseHeader("Connection", "close");
            Encoding enc = Encoding.ASCII;

            wr.SendUnknownResponseHeader("Content-Type", "text/html; charset=" + enc.WebName);
            string msg = e.GetHtmlErrorMessage();

            byte [] contentBytes = enc.GetBytes(msg);
            wr.SendUnknownResponseHeader("Content-Length", contentBytes.Length.ToString());
            wr.SendResponseFromMemory(contentBytes, contentBytes.Length);
            wr.FlushResponse(true);
            wr.CloseConnection();
            HttpApplication.requests_total_counter.Increment();
        }
Ejemplo n.º 6
0
        public override void Write(byte [] buffer, int offset, int count)
        {
            bool buffering = response.BufferOutput;

            if (buffering)
            {
                // It does not matter whether we're in ApplyFilter or not
                AppendBuffer(buffer, offset, count);
            }
            else if (filter == null || filtering)
            {
                response.WriteHeaders(false);
                HttpWorkerRequest wr = response.WorkerRequest;
                // Direct write because not buffering
                if (offset == 0)
                {
                    wr.SendResponseFromMemory(buffer, count);
                }
                else
                {
                    UnsafeWrite(wr, buffer, offset, count);
                }
                wr.FlushResponse(false);
            }
            else
            {
                // Write to the filter, which will call us back, and then Flush
                filtering = true;
                try {
                    filter.Write(buffer, offset, count);
                }
                finally {
                    filtering = false;
                }
                Flush(response.WorkerRequest, false);
            }
        }
Ejemplo n.º 7
0
		//
		// This is called from the QueueManager if a request
		// can not be processed (load, no resources, or
		// appdomain unload).
		//
		static internal void FinishUnavailable (HttpWorkerRequest wr)
		{
			wr.SendStatus (503, "Service unavailable");
			wr.SendUnknownResponseHeader ("Connection", "close");
			Encoding enc = Encoding.ASCII;
			wr.SendUnknownResponseHeader ("Content-Type", "text/html; charset=" + enc.WebName);
			byte [] contentBytes = enc.GetBytes (content503);
			wr.SendUnknownResponseHeader ("Content-Length", contentBytes.Length.ToString ());
			wr.SendResponseFromMemory (contentBytes, contentBytes.Length);
			wr.FlushResponse (true);
			wr.CloseConnection ();
			HttpApplication.requests_total_counter.Increment ();
		}
Ejemplo n.º 8
0
		static void FinishWithException (HttpWorkerRequest wr, HttpException e)
		{
			int code = e.GetHttpCode ();
			wr.SendStatus (code, HttpWorkerRequest.GetStatusDescription (code));
			wr.SendUnknownResponseHeader ("Connection", "close");
			Encoding enc = Encoding.ASCII;
			wr.SendUnknownResponseHeader ("Content-Type", "text/html; charset=" + enc.WebName);
			string msg = e.GetHtmlErrorMessage ();
			byte [] contentBytes = enc.GetBytes (msg);
			wr.SendUnknownResponseHeader ("Content-Length", contentBytes.Length.ToString ());
			wr.SendResponseFromMemory (contentBytes, contentBytes.Length);
			wr.FlushResponse (true);
			wr.CloseConnection ();
			HttpApplication.requests_total_counter.Increment ();
		}
		internal void Flush (HttpWorkerRequest wr, bool final_flush)
		{
			if (total == 0 && !final_flush)
				return;

			if (response.use_chunked) 
				SendChunkSize (total, false);

			for (Bucket b = first_bucket; b != null; b = b.Next) {
				b.Send (wr);
			}

			if (response.use_chunked) {
				SendChunkSize (-1, false);
				if (final_flush)
					SendChunkSize (0, true);
			}

			wr.FlushResponse (final_flush);

			Clear ();
		}
Ejemplo n.º 10
0
 private void ProcessRequestInternal(HttpWorkerRequest wr)
 {
   Interlocked.Increment(ref this._activeRequestCount);
   if (this._disposingHttpRuntime)
   {
     try
     {
       wr.SendStatus(503, "Server Too Busy");
       wr.SendKnownResponseHeader(12, "text/html; charset=utf-8");
       byte[] bytes = Encoding.ASCII.GetBytes("<html><body>Server Too Busy</body></html>");
       wr.SendResponseFromMemory(bytes, bytes.Length);
       wr.FlushResponse(true);
       wr.EndOfRequest();
     }
     finally
     {
       Interlocked.Decrement(ref this._activeRequestCount);
     }
   }
   else
   {
     HttpContext context;
     try
     {
       context = new HttpContext(wr, false);
     }
     catch
     {
       try
       {
         wr.SendStatus(400, "Bad Request");
         wr.SendKnownResponseHeader(12, "text/html; charset=utf-8");
         byte[] bytes = Encoding.ASCII.GetBytes("<html><body>Bad Request</body></html>");
         wr.SendResponseFromMemory(bytes, bytes.Length);
         wr.FlushResponse(true);
         wr.EndOfRequest();
         return;
       }
       finally
       {
         Interlocked.Decrement(ref this._activeRequestCount);
       }
     }
     wr.SetEndOfSendNotification(this._asyncEndOfSendCallback, (object) context);
     HostingEnvironment.IncrementBusyCount();
     try
     {
       try
       {
         this.EnsureFirstRequestInit(context);
       }
       catch
       {
         if (!context.Request.IsDebuggingRequest)
           throw;
       }
       context.Response.InitResponseWriter();
       IHttpHandler applicationInstance = HttpApplicationFactory.GetApplicationInstance(context);
       if (applicationInstance == null)
         throw new HttpException(System.Web.SR.GetString("Unable_create_app_object"));
       if (EtwTrace.IsTraceEnabled(5, 1))
         EtwTrace.Trace(EtwTraceType.ETW_TYPE_START_HANDLER, context.WorkerRequest, applicationInstance.GetType().FullName, "Start");
       if (applicationInstance is IHttpAsyncHandler)
       {
         IHttpAsyncHandler httpAsyncHandler = (IHttpAsyncHandler) applicationInstance;
         context.AsyncAppHandler = httpAsyncHandler;
         httpAsyncHandler.BeginProcessRequest(context, this._handlerCompletionCallback, (object) context);
       }
       else
       {
         applicationInstance.ProcessRequest(context);
         this.FinishRequest(context.WorkerRequest, context, (Exception) null);
       }
     }
     catch (Exception ex)
     {
       context.Response.InitResponseWriter();
       this.FinishRequest(wr, context, ex);
     }
   }
 }
Ejemplo n.º 11
0
		internal void Flush (HttpWorkerRequest wr, bool final_flush)
		{
			if (!dirty && !final_flush)
				return;

			for (Bucket b = first_bucket; b != null; b = b.Next) {
				b.Send (wr);
			}

			wr.FlushResponse (final_flush);
			Clear ();
		}