public static HttpPipeline CreateHttpPipeline(HttpRequestContext httpRequestContext, TransportIntegrationHandler transportIntegrationHandler, bool isWebSocketTransport) { if (transportIntegrationHandler == null) { Fx.Assert(!isWebSocketTransport, "isWebSocketTransport should be false if there's no HTTP message handler existing."); if (httpRequestContext.HttpMessagesSupported) { return new HttpMessageSupportedHttpPipeline(httpRequestContext); } return new EmptyHttpPipeline(httpRequestContext); } return NormalHttpPipeline.CreatePipeline(httpRequestContext, transportIntegrationHandler, isWebSocketTransport); }
public HttpPipeline(HttpRequestContext httpRequestContext) { this.httpRequestContext = httpRequestContext; }
public EmptyHttpPipeline(HttpRequestContext httpRequestContext) : base(httpRequestContext) { if (this.httpRequestContext.Listener.RequestInitializationTimeout != HttpTransportDefaults.RequestInitializationTimeout) { this.requestInitializationTimer = new IOThreadTimer(onRequestInitializationTimeout, this, false); this.requestInitializationTimer.Set(this.httpRequestContext.Listener.RequestInitializationTimeout); } }
public override bool TryReceiveRequest(TimeSpan timeout, out RequestContext context) { context = null; if (waiting.Count == 0 && !WaitForRequest(timeout)) { return(false); } HttpListenerContext ctx = null; lock (waiting) { if (waiting.Count > 0) { ctx = waiting [0]; waiting.RemoveAt(0); } } if (ctx == null) { // Though as long as this instance is used // synchronously, it should not happen. return(false); } if (ctx.Response.StatusCode != 200) { ctx.Response.Close(); return(false); } // FIXME: supply maxSizeOfHeaders. int maxSizeOfHeaders = 0x10000; Message msg = null; if (ctx.Request.HttpMethod == "POST") { if (!Encoder.IsContentTypeSupported(ctx.Request.ContentType)) { ctx.Response.StatusCode = (int)HttpStatusCode.UnsupportedMediaType; ctx.Response.StatusDescription = String.Format( "Expected content-type '{0}' but got '{1}'", Encoder.ContentType, ctx.Request.ContentType); ctx.Response.Close(); return(false); } msg = Encoder.ReadMessage( ctx.Request.InputStream, maxSizeOfHeaders); if (MessageVersion.Envelope.Equals(EnvelopeVersion.Soap11) || MessageVersion.Addressing.Equals(AddressingVersion.None)) { string action = GetHeaderItem(ctx.Request.Headers ["SOAPAction"]); if (action != null) { if (action.Length > 2 && action [0] == '"' && action [action.Length] == '"') { action = action.Substring(1, action.Length - 2); } msg.Headers.Action = action; } } } else if (ctx.Request.HttpMethod == "GET") { msg = Message.CreateMessage(MessageVersion.None, null); } if (msg.Headers.To == null) { msg.Headers.To = ctx.Request.Url; } msg.Properties.Add("Via", LocalAddress.Uri); msg.Properties.Add(HttpRequestMessageProperty.Name, CreateRequestProperty(ctx.Request.HttpMethod, ctx.Request.Url.Query, ctx.Request.Headers)); /* * MessageBuffer buf = msg.CreateBufferedCopy (0x10000); * msg = buf.CreateMessage (); * Console.WriteLine (buf.CreateMessage ()); */ context = new HttpRequestContext(this, msg, ctx); reqctx = context; return(true); }
public ActivityHolder(ServiceModelActivity activity, HttpRequestContext requestContext) { Fx.Assert(requestContext != null, "requestContext cannot be null."); this.activity = activity; this.context = requestContext; }
public AcceptWebSocketAsyncResult(HttpRequestContext context, HttpResponseMessage response, string protocol, AsyncCallback callback, object state) : base(callback, state) { Fx.Assert(context != null, "context should not be null."); Fx.Assert(response != null, "response should not be null."); this.context = context; this.response = response; IAsyncResult result = this.context.AcceptWebSocketCore(response, protocol).AsAsyncResult<WebSocketContext>(onHandleAcceptWebSocketResult, this); if (this.gate.Unlock()) { this.CompleteAcceptWebSocket(result); base.Complete(true); } }
public WebSocketHttpPipeline(HttpRequestContext httpRequestContext, TransportIntegrationHandler transportIntegrationHandler) : base(httpRequestContext, transportIntegrationHandler) { }
public static HttpPipeline CreatePipeline(HttpRequestContext httpRequestContext, TransportIntegrationHandler transportIntegrationHandler, bool isWebSocketTransport) { NormalHttpPipeline pipeline = isWebSocketTransport ? new WebSocketHttpPipeline(httpRequestContext, transportIntegrationHandler) : new NormalHttpPipeline(httpRequestContext, transportIntegrationHandler); pipeline.SetPipelineIncomingTimeout(); return pipeline; }
public HttpMessageSupportedHttpPipeline(HttpRequestContext httpRequestContext) : base(httpRequestContext) { }
public HttpPipeline(HttpRequestContext httpRequestContext) { this.httpRequestContext = httpRequestContext; }
public HttpPipelineCancellationTokenSource(HttpRequestContext httpRequestContext) { Fx.Assert(httpRequestContext != null, "httpRequestContext should not be null."); this.httpRequestContext = httpRequestContext; this.Token.Register(onCancelled, this); }
public ListenerContextInputStream(HttpRequestContext.ListenerHttpContext listenerHttpContext, byte[] preReadBuffer) : base(new PreReadStream(listenerHttpContext.listenerContext.Request.InputStream, preReadBuffer)) { }
public ListenerContextInputStream(HttpRequestContext.ListenerHttpContext listenerHttpContext) : base(listenerHttpContext.listenerContext.Request.InputStream) { }
public ListenerContextHttpInput(HttpRequestContext.ListenerHttpContext listenerHttpContext) : base(listenerHttpContext.Listener, true, listenerHttpContext.listener.IsChannelBindingSupportEnabled) { this.listenerHttpContext = listenerHttpContext; if (this.listenerHttpContext.listenerContext.Request.ContentLength64 == -1L) { this.preReadBuffer = new byte[1]; if (this.listenerHttpContext.listenerContext.Request.InputStream.Read(this.preReadBuffer, 0, 1) == 0) { this.preReadBuffer = null; } } }
internal bool HttpContextReceived(HttpRequestContext context, Action callback) { bool flag = false; bool flag2 = false; try { if (!context.ProcessAuthentication()) { if (DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceEvent(TraceEventType.Information, 0x40027, System.ServiceModel.SR.GetString("TraceCodeHttpAuthFailed"), this); } flag2 = true; return(false); } try { context.CreateMessage(); } catch (ProtocolException exception) { HttpStatusCode badRequest = HttpStatusCode.BadRequest; string statusDescription = string.Empty; if (exception.Data.Contains("System.ServiceModel.Channels.HttpInput.HttpStatusCode")) { badRequest = (HttpStatusCode)exception.Data["System.ServiceModel.Channels.HttpInput.HttpStatusCode"]; exception.Data.Remove("System.ServiceModel.Channels.HttpInput.HttpStatusCode"); } if (exception.Data.Contains("System.ServiceModel.Channels.HttpInput.HttpStatusDescription")) { statusDescription = (string)exception.Data["System.ServiceModel.Channels.HttpInput.HttpStatusDescription"]; exception.Data.Remove("System.ServiceModel.Channels.HttpInput.HttpStatusDescription"); } context.SendResponseAndClose(badRequest, statusDescription); throw; } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } try { context.SendResponseAndClose(HttpStatusCode.BadRequest); } catch (Exception exception3) { if (Fx.IsFatal(exception3)) { throw; } if (DiagnosticUtility.ShouldTraceError) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Error); } } throw; } flag = true; this.acceptor.Enqueue(context, callback); flag2 = true; } catch (CommunicationException exception4) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception4, TraceEventType.Information); } } catch (XmlException exception5) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception5, TraceEventType.Information); } } catch (IOException exception6) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception6, TraceEventType.Information); } } catch (TimeoutException exception7) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception7, TraceEventType.Information); } } catch (Exception exception8) { if (Fx.IsFatal(exception8)) { throw; } if (!System.ServiceModel.Dispatcher.ExceptionHandler.HandleTransportExceptionHelper(exception8)) { throw; } } finally { if (!flag2) { context.Abort(); } } return(flag); }
public HttpMessageSupportedHttpPipeline(HttpRequestContext httpRequestContext) : base(httpRequestContext) { }
public NormalHttpPipeline(HttpRequestContext httpRequestContext, TransportIntegrationHandler transportIntegrationHandler) : base(httpRequestContext) { this.defaultSendTimeout = httpRequestContext.DefaultSendTimeout; this.cancellationTokenSource = new HttpPipelineCancellationTokenSource(httpRequestContext); Fx.Assert(transportIntegrationHandler != null, "transportIntegrationHandler should not be null."); this.transportIntegrationHandler = transportIntegrationHandler; }
public WebSocketHttpPipeline(HttpRequestContext httpRequestContext, TransportIntegrationHandler transportIntegrationHandler) : base(httpRequestContext, transportIntegrationHandler) { }
public ActivityHolder(ServiceModelActivity activity, HttpRequestContext requestContext) { Fx.Assert(requestContext != null, "requestContext cannot be null."); this.activity = activity; this.context = requestContext; }
bool EnqueueContext(IAsyncResult listenerContextResult) { EventTraceActivity eventTraceActivity = null; HttpListenerContext listenerContext; bool enqueued = false; if (FxTrace.Trace.IsEnd2EndActivityTracingEnabled) { eventTraceActivity = (EventTraceActivity)listenerContextResult.AsyncState; if (eventTraceActivity == null) { eventTraceActivity = EventTraceActivity.GetFromThreadOrCreate(true); } } using (LockHelper.TakeReaderLock(this.listenerRWLock)) { if (this.listener == null) { return(true); } listenerContext = this.listener.EndGetContext(listenerContextResult); } // Grab the activity from the context and set that as the surrounding activity. // If a message appears, we will transfer to the message's activity next using (DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.BoundOperation(this.Activity) : null) { ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivityWithTransferInOnly(listenerContext.Request.RequestTraceIdentifier) : null; try { if (activity != null) { StartReceiveBytesActivity(activity, listenerContext.Request.Url); } if (DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceHttpConnectionInformation(listenerContext.Request.LocalEndPoint.ToString(), listenerContext.Request.RemoteEndPoint.ToString(), this); } base.TraceMessageReceived(eventTraceActivity, this.ListenUri); HttpChannelListener channelListener; if (base.TryLookupUri(listenerContext.Request.Url, listenerContext.Request.HttpMethod, this.HostNameComparisonMode, listenerContext.Request.IsWebSocketRequest, out channelListener)) { HttpRequestContext context = HttpRequestContext.CreateContext(channelListener, listenerContext, eventTraceActivity); IAsyncResult httpContextReceivedResult = channelListener.BeginHttpContextReceived(context, onMessageDequeued, onContextReceived, DiagnosticUtility.ShouldUseActivity ? (object)new ActivityHolder(activity, context) : (object)context); if (httpContextReceivedResult.CompletedSynchronously) { enqueued = EndHttpContextReceived(httpContextReceivedResult); } else { // The callback has been enqueued. enqueued = true; } } else { HandleMessageReceiveFailed(listenerContext); } } finally { if (DiagnosticUtility.ShouldUseActivity && activity != null) { if (!enqueued) { // Error during enqueuing activity.Dispose(); } } } } return(enqueued); }
public HttpPipelineCancellationTokenSource(HttpRequestContext httpRequestContext) { Fx.Assert(httpRequestContext != null, "httpRequestContext should not be null."); this.httpRequestContext = httpRequestContext; this.Token.Register(onCancelled, this); }
public override bool TryReceiveRequest (TimeSpan timeout, out RequestContext context) { context = null; if (waiting.Count == 0 && !WaitForRequest (timeout)) return false; HttpListenerContext ctx = null; lock (waiting) { if (waiting.Count > 0) { ctx = waiting [0]; waiting.RemoveAt (0); } } if (ctx == null) // Though as long as this instance is used // synchronously, it should not happen. return false; // FIXME: supply maxSizeOfHeaders. int maxSizeOfHeaders = 0x10000; Message msg = null; // FIXME: our HttpConnection (under HttpListener) // somehow breaks when the underlying connection is // reused. Remove it when it gets fixed. ctx.Response.KeepAlive = false; if (ctx.Request.HttpMethod == "POST") { if (!Encoder.IsContentTypeSupported (ctx.Request.ContentType)) { ctx.Response.StatusCode = (int) HttpStatusCode.UnsupportedMediaType; ctx.Response.StatusDescription = String.Format ( "Expected content-type '{0}' but got '{1}'", Encoder.ContentType, ctx.Request.ContentType); ctx.Response.Close (); return false; } msg = Encoder.ReadMessage ( ctx.Request.InputStream, maxSizeOfHeaders); if (MessageVersion.Envelope.Equals (EnvelopeVersion.Soap11) || MessageVersion.Addressing.Equals (AddressingVersion.None)) { string action = GetHeaderItem (ctx.Request.Headers ["SOAPAction"]); if (action != null) { if (action.Length > 2 && action [0] == '"' && action [action.Length] == '"') action = action.Substring (1, action.Length - 2); msg.Headers.Action = action; } } } else if (ctx.Request.HttpMethod == "GET") { msg = Message.CreateMessage (MessageVersion, null); } msg.Headers.To = ctx.Request.Url; msg.Properties.Add ("Via", LocalAddress.Uri); msg.Properties.Add (HttpRequestMessageProperty.Name, CreateRequestProperty (ctx.Request.HttpMethod, ctx.Request.Url.Query, ctx.Request.Headers)); /* MessageBuffer buf = msg.CreateBufferedCopy (0x10000); msg = buf.CreateMessage (); System.Xml.XmlTextWriter w = new System.Xml.XmlTextWriter (Console.Out); w.Formatting = System.Xml.Formatting.Indented; buf.CreateMessage ().WriteMessage (w); w.Close (); */ context = new HttpRequestContext (this, msg, ctx); reqctx = context; return true; }
public ReplyAsyncResult(HttpRequestContext context, Message message, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { this.context = context; this.message = message; this.responseMessage = null; this.timeoutHelper = new TimeoutHelper(timeout); ThreadTrace.Trace("Begin sending http reply"); this.responseMessage = this.message; if (this.SendResponse()) { base.Complete(true); } }
private void OnGetContextCore(IAsyncResult result) { bool flag = false; while (!flag) { Exception exception = null; try { try { HttpListenerContext listenerContext = null; lock (base.ThisLock) { if (this.listener == null) { break; } listenerContext = this.listener.EndGetContext(result); } HttpChannelListener listener = null; using (DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.BoundOperation(base.Activity) : null) { using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivityWithTransferInOnly(listenerContext.Request.RequestTraceIdentifier) : null) { if (activity != null) { base.StartReceiveBytesActivity(activity, listenerContext.Request.Url); } if (DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceHttpConnectionInformation(listenerContext.Request.LocalEndPoint.ToString(), listenerContext.Request.RemoteEndPoint.ToString(), this); } base.TraceMessageReceived(base.ListenUri); if (base.TryLookupUri(listenerContext.Request.Url, listenerContext.Request.HttpMethod, base.HostNameComparisonMode, out listener)) { flag = listener.HttpContextReceived(HttpRequestContext.CreateContext(listener, listenerContext), this.onMessageDequeued); } else { if (DiagnosticUtility.ShouldTraceWarning) { TraceUtility.TraceEvent(TraceEventType.Warning, 0x4000b, System.ServiceModel.SR.GetString("TraceCodeHttpChannelMessageReceiveFailed"), null); } if (string.Compare(listenerContext.Request.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase) != 0) { listenerContext.Response.StatusCode = 0x195; listenerContext.Response.Headers.Add(HttpResponseHeader.Allow, "POST"); } else { listenerContext.Response.StatusCode = 0x194; } listenerContext.Response.ContentLength64 = 0L; listenerContext.Response.Close(); } } } } catch (HttpListenerException exception2) { switch (exception2.ErrorCode) { case 8: case 14: case 0x5aa: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InsufficientMemoryException(System.ServiceModel.SR.GetString("InsufficentMemory"), exception2)); } if (!System.ServiceModel.Dispatcher.ExceptionHandler.HandleTransportExceptionHelper(exception2)) { throw; } } } catch (Exception exception3) { if (Fx.IsFatal(exception3)) { throw; } exception = exception3; } if (exception != null) { base.Fault(exception); } if (!flag) { lock (base.ThisLock) { if (this.listener == null) { continue; } result = this.BeginGetContext(false); if ((result != null) && result.CompletedSynchronously) { continue; } break; } } } }