Skip to content
Permalink
Browse files
Fix RandomHttpTest by only checking IsValidStart for HTTP requests wh…
…en their URI is not empty.
  • Loading branch information
bricknerb committed May 26, 2018
1 parent 57a21ac commit e1cfa913429de61676820d39da92c8af0603b6ea
Showing 1 changed file with 2 additions and 1 deletion.
@@ -108,7 +108,8 @@ public void RandomHttpTest()
if (httpLayer.Header != null)
{
Assert.AreEqual(httpLayer.Header.GetHashCode(), httpDatagram.Header.GetHashCode());
Assert.IsTrue(httpDatagram.IsValidStart, "IsValidStart");
if (!httpDatagram.IsRequest || ((HttpRequestDatagram)httpDatagram).Uri != "")
Assert.IsTrue(httpDatagram.IsValidStart, "IsValidStart");

foreach (var field in httpLayer.Header)
Assert.IsFalse(field.Equals("abc"));

3 comments on commit e1cfa91

@Parthasarathi-mail3sarathee
Copy link

@Parthasarathi-mail3sarathee Parthasarathi-mail3sarathee commented on e1cfa91 Aug 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bricknerb ,@vbBerni , I have seen your code ant try to utilize it,

I have written the basic socket programming, where I have receive the request

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace SocketServer
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Server");
            SocketServer();
        }

        static void SocketServer()
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            IPHostEntry host = Dns.GetHostEntry("localhost");
            IPAddress ipAddress = host.AddressList[0];
            IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 44362);
            try
            {
                Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                listener.Bind(localEndPoint);
                listener.Listen(10);
                int count = 1;
                string data = null;
                byte[] bytes = new byte[2048];
                while (true)
                {
                    Socket handler = listener.Accept();
                    int bytesRec = handler.Receive(bytes);
                    data = Encoding.ASCII.GetString(bytes, 0, bytesRec);
                    Console.WriteLine("data received {0}, count {1}", data, count);
                    string ackMsg = string.Format("Ack:data received successfully: {0}, count {1}", data, count);
                    byte[] msg = Encoding.ASCII.GetBytes(ackMsg);
                    int bytesSent = handler.Send(msg);
                    Console.WriteLine("data sent successfully: {0}, count {1}", ackMsg, count++);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

        }
    }
}

espcially I try to get the data data = Encoding.ASCII.GetString(bytes, 0, bytesRec);

it is a simple request


POST /api/token HTTP/1.1
Host: localhost:44362
Content-Type: text/plain
Content-Length: 45

{
    "test":"test",
    "first":"first"
}


But I am not get this string insead I got other than ascii character whether your code work for html parser, Please let me know thanks in advance

@Parthasarathi-mail3sarathee
Copy link

@Parthasarathi-mail3sarathee Parthasarathi-mail3sarathee commented on e1cfa91 Aug 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

data = Encoding.ASCII.GetString(bytes, 0, bytesRec);

the data as

"\u0016\u0003\u0003\0?\u0001\0\0?\u0003\u0003c\u0003\n?;?%4???8W9??\u001a\u0014??1\u000e*?\u000f\v???\u000e?9\0\0(?,?+?0?/\0?\0??$?#?(?'?\n?\t?\u0014?\u0013\0?\0?\0=\0<\05\0/\u0001\0\0O\0\0\0\u000e\0\f\0\0\tlocalhost\0\n\0\b\0\u0006\0\u001d\0\u0017\0\u0018\0\v\0\u0002\u0001\0\0\r\0\u001a\0\u0018\b\u0004\b\u0005\b\u0006\u0004\u0001\u0005\u0001\u0002\u0001\u0004\u0003\u0005\u0003\u0002\u0003\u0002\u0002\u0006\u0001\u0006\u0003\0#\0\0\0\u0017\0\0?\u0001\0\u0001\0"

@vbBerni
Copy link

@vbBerni vbBerni commented on e1cfa91 Aug 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Parthasarathi-mail3sarathee I have no idea how this question is related to this commit but anyway.
This looks like a TLS handshake to me. One indicator is port 44362.
Also the content matches.
16 = Handshake
3 3 = TLS v1.2
0 ? = Length = 63
1 = Client Hello
0 0 ? = Length = 63
3 3 = TLS v1.2
And so on. I assume “localhost” will be SNI.
You need to use SslStream (https://docs.microsoft.com/en-us/dotnet/api/system.net.security.sslstream?view=net-6.0) or use the regular Kestrel and implement your own controller.

Please sign in to comment.