private void AckPush(SIF_Ack ack, AdkHttpResponse response) { try { // Set SIF_Ack / SIF_Header fields SIF_Header hdr = ack.Header; hdr.SIF_Timestamp = DateTime.Now; hdr.SIF_MsgId = SifFormatter.GuidToSifRefID(Guid.NewGuid()); hdr.SIF_SourceId = this.Zone.Agent.Id; ack.LogSend(this.Zone.Log); response.ContentType = SifIOFormatter.CONTENTTYPE; // TODO: This code may need to change. The ADKHttpResponse should not automatically set the content length // and other implementations will not do so. SifWriter w = new SifWriter(response.GetResponseStream()); w.Write(ack); w.Flush(); } catch (Exception thr) { Console.Out.WriteLine ("HttpProtocolHandler failed to send SIF_Ack for pushed message (zone=" + this.Zone.ZoneId + "): " + thr); throw new AdkHttpException (AdkHttpStatusCode.ServerError_500_Internal_Server_Error, thr.Message, thr); } }
public AdkHttpRequestContext(AdkHttpConnection connection, AdkHttpRequest request, AdkHttpResponse response, AdkHttpServer server) { fConnection = connection; fRequest = request; fResponse = response; fServer = server; }
public AdkHttpRequestContext( AdkHttpConnection connection, AdkHttpRequest request, AdkHttpResponse response, AdkHttpServer server ) { fConnection = connection; fRequest = request; fResponse = response; fServer = server; }
public static void ProcessRequest( AdkSocketConnection socket, AdkHttpListener listener ) { AdkHttpRequestContext context = socket.UserData as AdkHttpRequestContext; if ( context == null ) { AdkHttpConnection conn = new AdkHttpConnection( socket, listener ); AdkHttpResponse response = new AdkHttpResponse( conn ); AdkHttpRequest request = new AdkHttpRequest( conn ); context = listener.Server.CreateContext( conn, request, response ); } context.Connection.ProcessRequest( context, socket ); }
public static void ProcessRequest(AdkSocketConnection socket, AdkHttpListener listener) { AdkHttpRequestContext context = socket.UserData as AdkHttpRequestContext; if (context == null) { AdkHttpConnection conn = new AdkHttpConnection(socket, listener); AdkHttpResponse response = new AdkHttpResponse(conn); AdkHttpRequest request = new AdkHttpRequest(conn); context = listener.Server.CreateContext(conn, request, response); } context.Connection.ProcessRequest(context, socket); }
public virtual AdkHttpRequestContext CreateContext(AdkHttpConnection connection, AdkHttpRequest request, AdkHttpResponse response) { return(new AdkHttpRequestContext(connection, request, response, this)); }
public virtual AdkHttpRequestContext CreateContext( AdkHttpConnection connection, AdkHttpRequest request, AdkHttpResponse response ) { return new AdkHttpRequestContext( connection, request, response, this ); }
private void ProcessRequest(AdkHttpRequestContext context, AdkSocketConnection socket) { int aStart = Environment.TickCount; bool keepAlive = true; AdkHttpRequest request = context.Request; AdkHttpResponse response = context.Response; try { context.Request.Receive(socket); if (!context.Request.ReceiveComplete) { socket.UserData = context; return; } else { IAdkHttpHandler handler = fListener.GetHandlerForContext(request); handler.ProcessRequest(context); } } catch (AdkHttpException httpEx) { _logError(httpEx); response.Clear(); response.Status = httpEx.HttpExceptionCode; if ((int)httpEx.HttpExceptionCode > 499) { keepAlive = false; } response.AdditionalInfo = httpEx.GetType().FullName + " - " + httpEx.Message + " - " + httpEx.StackTrace; } catch (Exception ex) { keepAlive = false; _logError(ex); // TODO : Implement more verbose error output ( internalexceptions and such ) response.Clear(); response.Status = AdkHttpStatusCode.ServerError_500_Internal_Server_Error; response.AdditionalInfo = ex.GetType().FullName + " - " + ex.Message + " - " + ex.StackTrace; } // Clear out the context state because we are done with this request and the socket // may remain open for the next request socket.UserData = null; if (socket.Connected) { if (keepAlive) { keepAlive = ShouldKeepAlive(context.Request); } context.Response.Headers.Add("X-Powered-By", fListener.Server.Name); // Write the Response context.Response.AsyncFinishRequest(socket, context.Request, keepAlive); if ((Adk.Debug & AdkDebugFlags.Messaging_Detailed) != 0 && fListener.Server.Log.IsDebugEnabled) { fListener.Server.Log.Info (string.Format ("Processed Request for {0}:{1} ( {2} ) in {3} milliseconds", this.ClientEndPoint.Address, this.ClientEndPoint.Port, context.Request.Path, (Environment.TickCount - aStart).ToString())); } if (!keepAlive) { socket.Close(); } } }
private void AckPush( SIF_Ack ack, AdkHttpResponse response ) { try { // Set SIF_Ack / SIF_Header fields SIF_Header hdr = ack.Header; hdr.SIF_Timestamp = DateTime.Now; hdr.SIF_MsgId = SifFormatter.GuidToSifRefID( Guid.NewGuid() ); hdr.SIF_SourceId = this.Zone.Agent.Id; ack.LogSend( this.Zone.Log ); response.ContentType = SifIOFormatter.CONTENTTYPE; // TODO: This code may need to change. The ADKHttpResponse should not automatically set the content length // and other implementations will not do so. SifWriter w = new SifWriter( response.GetResponseStream() ); w.Write( ack ); w.Flush(); } catch ( Exception thr ) { Console.Out.WriteLine ( "HttpProtocolHandler failed to send SIF_Ack for pushed message (zone=" + this.Zone.ZoneId + "): " + thr ); throw new AdkHttpException ( AdkHttpStatusCode.ServerError_500_Internal_Server_Error, thr.Message, thr ); } }