send 100 continue code the way ms seems to want

master
UbitUmarov 2020-04-16 02:13:03 +01:00
parent 4ab8da01bc
commit e2f84f0c1f
3 changed files with 15 additions and 8 deletions

View File

@ -140,6 +140,7 @@ namespace OSHttpServer
basecontextID = 1;
contextID = basecontextID;
sock.NoDelay = true;
}
public bool CanSend()
@ -175,7 +176,7 @@ namespace OSHttpServer
lock (requestsInServiceIDs)
{
if (requestsInServiceIDs.Count == 0)
Respond("HTTP/1.1", HttpStatusCode.Continue, "Please continue.");
Respond("HTTP/1.1", HttpStatusCode.Continue, null);
}
}
m_currentRequest.AddHeader(e.Name, e.Value);
@ -557,20 +558,21 @@ namespace OSHttpServer
{
LastActivityTimeMS = ContextTimeoutManager.EnvironmentTickCount();
if (string.IsNullOrEmpty(contentType))
contentType = "text/html";
if (string.IsNullOrEmpty(reason))
reason = statusCode.ToString();
byte[] buffer;
if(string.IsNullOrEmpty(body))
buffer = Encoding.ASCII.GetBytes(httpVersion + " " + (int)statusCode + " " + reason ?? statusCode.ToString() + "\r\n\r\n");
buffer = Encoding.ASCII.GetBytes(httpVersion + " " + (int)statusCode + " " + reason + "\r\n\r\n");
else
{
if (string.IsNullOrEmpty(contentType))
contentType = "text/html";
buffer = Encoding.UTF8.GetBytes(
string.Format("{0} {1} {2}\r\nContent-Type: {5}\r\nContent-Length: {3}\r\n\r\n{4}",
httpVersion, (int)statusCode, reason ?? statusCode.ToString(),
body.Length, body, contentType));
}
Send(buffer);
}
@ -582,8 +584,10 @@ namespace OSHttpServer
/// <param name="reason">reason for the status code.</param>
public void Respond(string httpVersion, HttpStatusCode statusCode, string reason)
{
Respond(httpVersion, statusCode, reason, null, null);
if (string.IsNullOrEmpty(reason))
reason = statusCode.ToString();
byte[] buffer = Encoding.ASCII.GetBytes(httpVersion + " " + (int)statusCode + " " + reason + "\r\n\r\n");
Send(buffer);
}
/// <summary>

View File

@ -103,7 +103,6 @@ namespace OSHttpServer
public IHttpClientContext CreateSecureContext(Socket socket, X509Certificate certificate,
SslProtocols protocol, RemoteCertificateValidationCallback _clientCallback = null)
{
socket.NoDelay = true;
var networkStream = new NetworkStream(socket, true);
var remoteEndPoint = (IPEndPoint)socket.RemoteEndPoint;

View File

@ -402,6 +402,7 @@ namespace OSHttpServer
throw new BadRequestException("Unknown 'Connection' header type.");
break;
/*
case "expect":
if (value.Contains("100-continue"))
{
@ -409,7 +410,10 @@ namespace OSHttpServer
}
m_headers.Add(name, value);
break;
*/
case "user-agent":
break;
default:
m_headers.Add(name, value);
break;