public static Message CreateMessage(string ipAddress, int port)
 {
     Message requestMessage = Message.CreateMessage(MessageVersion.None, null);
      var remoteEndPointProperty = new RemoteEndpointMessageProperty(ipAddress, port);
      requestMessage.Properties.Add(RemoteEndpointMessageProperty.Name, remoteEndPointProperty);
      return requestMessage;
 }
        public void TestGetClientIpAddressFromRemoteEndpointMessage()
        {
            var remoteEndpointMessageProperty = new RemoteEndpointMessageProperty("127.0.0.1", 8050);
            var httpRequestMessage = new HttpRequestMessage();
            httpRequestMessage.Properties.Add(
                "System.ServiceModel.Channels.RemoteEndpointMessageProperty",
                remoteEndpointMessageProperty);

            var result = httpRequestMessage.GetClientIpAddress();

            Assert.That(result, Is.EqualTo("127.0.0.1"));
        }
 protected override void PrepareMessage(Message message)
 {
     base.PrepareMessage(message);
     IPEndPoint remoteIPEndPoint = this.rawConnection.RemoteIPEndPoint;
     if (remoteIPEndPoint != null)
     {
         RemoteEndpointMessageProperty property = new RemoteEndpointMessageProperty(remoteIPEndPoint);
         message.Properties.Add(RemoteEndpointMessageProperty.Name, property);
     }
     if (this.channelBindingToken != null)
     {
         ChannelBindingMessageProperty property2 = new ChannelBindingMessageProperty(this.channelBindingToken, false);
         property2.AddTo(message);
         property2.Dispose();
     }
 }
Ejemplo n.º 4
0
            public override void ConfigureHttpRequestMessage(HttpRequestMessage message)
            {
                message.Method = new HttpMethod(this.hostedHttpContext.result.GetHttpMethod());
                message.RequestUri = this.hostedHttpContext.result.RequestUri;
                foreach (string webHeaderKey in this.hostedHttpContext.result.Application.Context.Request.Headers.Keys)
                {
                    message.AddHeader(webHeaderKey, this.hostedHttpContext.result.Application.Context.Request.Headers[webHeaderKey]);
                }

                HostedRequestContainer requestContainer = new HostedRequestContainer(this.hostedHttpContext.result);
                RemoteEndpointMessageProperty remoteEndpointProperty = new RemoteEndpointMessageProperty(requestContainer);
                message.Properties.Add(RemoteEndpointMessageProperty.Name, remoteEndpointProperty);
            }
Ejemplo n.º 5
0
            protected override void AddProperties(Message message)
            {
                HostedRequestContainer requestContainer = new HostedRequestContainer(this.hostedHttpContext.result);

                HttpRequestMessageProperty requestProperty = new HttpRequestMessageProperty(requestContainer);

                requestProperty.Method = this.hostedHttpContext.HttpMethod;

                // Uri.Query always includes the '?'
                if (this.hostedHttpContext.result.RequestUri.Query.Length > 1)
                {
                    requestProperty.QueryString = this.hostedHttpContext.result.RequestUri.Query.Substring(1);
                }

                message.Properties.Add(HttpRequestMessageProperty.Name, requestProperty);

                message.Properties.Add(HostingMessageProperty.Name, CreateMessagePropertyFromHostedResult(this.hostedHttpContext.result));
                message.Properties.Via = this.hostedHttpContext.result.RequestUri;

                RemoteEndpointMessageProperty remoteEndpointProperty = new RemoteEndpointMessageProperty(requestContainer);
                message.Properties.Add(RemoteEndpointMessageProperty.Name, remoteEndpointProperty);

                this.hostedHttpContext.SetRequestContainer(requestContainer);
            }
Ejemplo n.º 6
0
        void BeforeAcceptWebSocket(HttpResponseMessage response)
        {
            this.SetRequestContainer(new HostedRequestContainer(this.result));
            string address = string.Empty;
            int port = 0;

            if (this.requestContainer.TryGetAddressAndPort(out address, out port))
            {
                this.remoteEndpointMessageProperty = new RemoteEndpointMessageProperty(address, port);
            }

            this.CloseHostedRequestContainer();

            HostedHttpContext.AppendHeaderFromHttpResponseMessageToResponse(response, this.result);
        }
Ejemplo n.º 7
0
		public static string FormatEP(RemoteEndpointMessageProperty ep)
		{
			return ep.Address + ":" + ep.Port;
		}
                protected override void AddProperties(Message message)
                {
                    HttpRequestMessageProperty requestProperty = new HttpRequestMessageProperty(this.listenerHttpContext);
                    requestProperty.Method = this.listenerHttpContext.listenerContext.Request.HttpMethod;

                    // Uri.Query always includes the '?'
                    if (this.listenerHttpContext.listenerContext.Request.Url.Query.Length > 1)
                    {
                        requestProperty.QueryString = this.listenerHttpContext.listenerContext.Request.Url.Query.Substring(1);
                    }

                    message.Properties.Add(HttpRequestMessageProperty.Name, requestProperty);
                    message.Properties.Via = this.listenerHttpContext.listenerContext.Request.Url;

                    RemoteEndpointMessageProperty remoteEndpointProperty = new RemoteEndpointMessageProperty(this.listenerHttpContext.listenerContext.Request.RemoteEndPoint);
                    message.Properties.Add(RemoteEndpointMessageProperty.Name, remoteEndpointProperty);
                }
            protected override void OnAcceptWebSocketSuccess(WebSocketContext context, HttpRequestMessage requestMessage)
            {
                RemoteEndpointMessageProperty remoteEndpointMessageProperty = null;
                if (this.listenerContext.Request.RemoteEndPoint != null)
                {
                    remoteEndpointMessageProperty = new RemoteEndpointMessageProperty(this.listenerContext.Request.RemoteEndPoint);
                }

                base.OnAcceptWebSocketSuccess(context, remoteEndpointMessageProperty, this.webSocketInternalBuffer, true, requestMessage);
            }
 protected void OnAcceptWebSocketSuccess(
     WebSocketContext context, 
     RemoteEndpointMessageProperty remoteEndpointMessageProperty, 
     byte[] webSocketInternalBuffer, 
     bool shouldDisposeWebSocketAfterClose, 
     HttpRequestMessage requestMessage)
 {
     this.webSocketChannel.SetWebSocketInfo(
         context, 
         remoteEndpointMessageProperty, 
         this.securityProperty, 
         webSocketInternalBuffer,
         shouldDisposeWebSocketAfterClose, 
         requestMessage);
 }
 protected override void AddProperties(Message message)
 {
     HostedHttpContext.HostedRequestContainer httpHeaderProvider = new HostedHttpContext.HostedRequestContainer(this.hostedHttpContext.result);
     HttpRequestMessageProperty property = new HttpRequestMessageProperty(httpHeaderProvider) {
         Method = this.hostedHttpContext.HttpMethod
     };
     if (this.hostedHttpContext.result.RequestUri.Query.Length > 1)
     {
         property.QueryString = this.hostedHttpContext.result.RequestUri.Query.Substring(1);
     }
     message.Properties.Add(HttpRequestMessageProperty.Name, property);
     message.Properties.Add(HostingMessageProperty.Name, CreateMessagePropertyFromHostedResult(this.hostedHttpContext.result));
     message.Properties.Via = this.hostedHttpContext.result.RequestUri;
     RemoteEndpointMessageProperty property2 = new RemoteEndpointMessageProperty(httpHeaderProvider);
     message.Properties.Add(RemoteEndpointMessageProperty.Name, property2);
     this.hostedHttpContext.SetRequestContainer(httpHeaderProvider);
 }
Ejemplo n.º 12
0
        protected override Message DecodeMessage(ArraySegment<byte> data)
        {
            Message result = base.DecodeMessage(data);
            if (result != null)
            {
                result.Headers.To = this.localAddress;
                IPEndPoint remoteEndpoint = (IPEndPoint)this.socket.RemoteEndPoint;
                RemoteEndpointMessageProperty property = new RemoteEndpointMessageProperty(remoteEndpoint.Address.ToString(), remoteEndpoint.Port);
                result.Properties.Add(RemoteEndpointMessageProperty.Name, property);
            }

            return result;
        }
 protected override void AddProperties(Message message)
 {
     HttpRequestMessageProperty property = new HttpRequestMessageProperty(this.listenerHttpContext) {
         Method = this.listenerHttpContext.listenerContext.Request.HttpMethod
     };
     if (this.listenerHttpContext.listenerContext.Request.Url.Query.Length > 1)
     {
         property.QueryString = this.listenerHttpContext.listenerContext.Request.Url.Query.Substring(1);
     }
     message.Properties.Add(HttpRequestMessageProperty.Name, property);
     message.Properties.Via = this.listenerHttpContext.listenerContext.Request.Url;
     RemoteEndpointMessageProperty property2 = new RemoteEndpointMessageProperty(this.listenerHttpContext.listenerContext.Request.RemoteEndPoint);
     message.Properties.Add(RemoteEndpointMessageProperty.Name, property2);
 }