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

View File

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

View File

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