remove some dead code

master
UbitUmarov 2020-04-03 03:54:32 +01:00
parent 50b8c90b42
commit 0a4232430b
2 changed files with 1 additions and 248 deletions

View File

@ -154,7 +154,6 @@ namespace OSHttpServer
/// <summary> /// <summary>
/// Size of the body. MUST be specified before sending the header, /// Size of the body. MUST be specified before sending the header,
/// unless property Chunked is set to true.
/// </summary> /// </summary>
public long ContentLength public long ContentLength
{ {
@ -163,7 +162,7 @@ namespace OSHttpServer
} }
/// <summary> /// <summary>
/// Kind of content in the body /// Kind of content
/// </summary> /// </summary>
/// <remarks>Default type is "text/html"</remarks> /// <remarks>Default type is "text/html"</remarks>
public string ContentType public string ContentType
@ -215,217 +214,6 @@ namespace OSHttpServer
m_headers[name] = value; m_headers[name] = value;
} }
/// <summary>
/// Send headers and body to the browser.
/// </summary>
/// <exception cref="InvalidOperationException">If content have already been sent.</exception>
public void SendOri()
{
if (Sent)
throw new InvalidOperationException("Everything have already been sent.");
m_context.ReqResponseAboutToSend(requestID);
if (m_context.MAXRequests == 0 || m_keepAlive == 0)
{
Connection = ConnectionType.Close;
m_context.TimeoutKeepAlive = 0;
}
else
{
if (m_keepAlive > 0)
m_context.TimeoutKeepAlive = m_keepAlive * 1000;
}
if (!HeadersSent)
{
if (!SendHeaders())
{
m_body.Dispose();
Sent = true;
return;
}
}
if(RawBuffer != null)
{
if(RawBufferStart >= 0 && RawBufferLen > 0)
{
if (RawBufferStart > RawBuffer.Length)
RawBufferStart = 0;
if (RawBufferLen + RawBufferStart > RawBuffer.Length)
RawBufferLen = RawBuffer.Length - RawBufferStart;
/*
int curlen;
while(RawBufferLen > 0)
{
curlen = RawBufferLen;
if(curlen > 8192)
curlen = 8192;
if (!_context.Send(RawBuffer, RawBufferStart, curlen))
{
RawBuffer = null;
RawBufferStart = -1;
RawBufferLen = -1;
Body.Dispose();
return;
}
RawBufferLen -= curlen;
RawBufferStart += curlen;
}
*/
if(RawBufferLen > 0)
{
if (!m_context.Send(RawBuffer, RawBufferStart, RawBufferLen))
{
RawBuffer = null;
RawBufferStart = -1;
RawBufferLen = -1;
if(m_body != null)
m_body.Dispose();
Sent = true;
return;
}
}
}
RawBuffer = null;
RawBufferStart = -1;
RawBufferLen = -1;
}
if(m_body != null && m_body.Length > 0)
{
m_body.Seek(0, SeekOrigin.Begin);
var buffer = new byte[8192];
int bytesRead = m_body.Read(buffer, 0, 8192);
while (bytesRead > 0)
{
if (!m_context.Send(buffer, 0, bytesRead))
break;
bytesRead = m_body.Read(buffer, 0, 8192);
}
m_body.Dispose();
}
Sent = true;
m_context.ReqResponseSent(requestID, Connection);
}
/// <summary>
/// Make sure that you have specified <see cref="ContentLength"/> and sent the headers first.
/// </summary>
/// <param name="buffer"></param>
/// <exception cref="InvalidOperationException">If headers have not been sent.</exception>
/// <see cref="SendHeaders"/>
/// <param name="offset">offset of first byte to send</param>
/// <param name="count">number of bytes to send.</param>
/// <seealso cref="Send"/>
/// <seealso cref="SendHeaders"/>
/// <remarks>This method can be used if you want to send body contents without caching them first. This
/// is recommended for larger files to keep the memory usage low.</remarks>
public bool SendBody(byte[] buffer, int offset, int count)
{
if (!HeadersSent)
throw new InvalidOperationException("Send headers, and remember to specify ContentLength first.");
bool sent = m_context.Send(buffer, offset, count);
Sent = true;
if (sent)
m_context.ReqResponseSent(requestID, Connection);
return sent;
}
/// <summary>
/// Make sure that you have specified <see cref="ContentLength"/> and sent the headers first.
/// </summary>
/// <param name="buffer"></param>
/// <exception cref="InvalidOperationException">If headers have not been sent.</exception>
/// <see cref="SendHeaders"/>
/// <seealso cref="Send"/>
/// <seealso cref="SendHeaders"/>
/// <remarks>This method can be used if you want to send body contents without caching them first. This
/// is recommended for larger files to keep the memory usage low.</remarks>
public bool SendBody(byte[] buffer)
{
if (!HeadersSent)
throw new InvalidOperationException("Send headers, and remember to specify ContentLength first.");
bool sent = m_context.Send(buffer);
if (sent)
m_context.ReqResponseSent(requestID, Connection);
Sent = true;
return sent;
}
/// <summary>
/// Send headers to the client.
/// </summary>
/// <exception cref="InvalidOperationException">If headers already been sent.</exception>
/// <seealso cref="AddHeader"/>
/// <seealso cref="Send"/>
/// <seealso cref="SendBody(byte[])"/>
public bool SendHeaders()
{
if (HeadersSent)
throw new InvalidOperationException("Header have already been sent.");
HeadersSent = true;
if (m_headers["Date"] == null)
m_headers["Date"] = DateTime.Now.ToString("r");
if (m_headers["Content-Length"] == null)
{
int len = (int)m_contentLength;
if(len == 0)
{
if(m_body != null)
len = (int)m_body.Length;
if(RawBuffer != null)
len += RawBufferLen;
}
m_headers["Content-Length"] = len.ToString();
}
if (m_headers["Content-Type"] == null)
m_headers["Content-Type"] = m_contentType ?? DefaultContentType;
if (m_headers["Server"] == null)
m_headers["Server"] = "Tiny WebServer";
int keepaliveS = m_context.TimeoutKeepAlive / 1000;
if (Connection == ConnectionType.KeepAlive && keepaliveS > 0 && m_context.MAXRequests > 0)
{
m_headers["Keep-Alive"] = "timeout=" + keepaliveS + ", max=" + m_context.MAXRequests;
m_headers["Connection"] = "Keep-Alive";
}
else
m_headers["Connection"] = "close";
var sb = new StringBuilder();
sb.AppendFormat("{0} {1} {2}\r\n", m_httpVersion, (int)Status,
string.IsNullOrEmpty(Reason) ? Status.ToString() : Reason);
for (int i = 0; i < m_headers.Count; ++i)
{
string headerName = m_headers.AllKeys[i];
string[] values = m_headers.GetValues(i);
if (values == null) continue;
foreach (string value in values)
sb.AppendFormat("{0}: {1}\r\n", headerName, value);
}
foreach (ResponseCookie cookie in Cookies)
sb.AppendFormat("Set-Cookie: {0}\r\n", cookie);
sb.Append("\r\n");
m_headers.Clear();
return m_context.Send(Encoding.GetBytes(sb.ToString()));
}
public byte[] GetHeaders() public byte[] GetHeaders()
{ {
HeadersSent = true; HeadersSent = true;

View File

@ -125,41 +125,6 @@ namespace OSHttpServer
/// </summary> /// </summary>
/// <exception cref="InvalidOperationException">If content have already been sent.</exception> /// <exception cref="InvalidOperationException">If content have already been sent.</exception>
void Send(); void Send();
/// <summary>
/// Make sure that you have specified ContentLength and sent the headers first.
/// </summary>
/// <param name="buffer"></param>
/// <exception cref="InvalidOperationException">If headers have not been sent.</exception>
/// <see cref="IHttpResponse.SendHeaders"/>
/// <param name="offset">offest of first byte to send</param>
/// <param name="count">number of bytes to send.</param>
/// <seealso cref="IHttpResponse.Send"/>
/// <seealso cref="IHttpResponse.SendHeaders"/>
/// <remarks>This method can be used if you want to send body contents without caching them first. This
/// is recommended for larger files to keep the memory usage low.</remarks>
bool SendBody(byte[] buffer, int offset, int count);
/// <summary>
/// Make sure that you have specified ContentLength and sent the headers first.
/// </summary>
/// <param name="buffer"></param>
/// <exception cref="InvalidOperationException">If headers have not been sent.</exception>
/// <see cref="IHttpResponse.SendHeaders"/>
/// <seealso cref="IHttpResponse.Send"/>
/// <seealso cref="IHttpResponse.SendHeaders"/>
/// <remarks>This method can be used if you want to send body contents without caching them first. This
/// is recommended for larger files to keep the memory usage low.</remarks>
bool SendBody(byte[] buffer);
/// <summary>
/// Send headers to the client.
/// </summary>
/// <exception cref="InvalidOperationException">If headers already been sent.</exception>
/// <seealso cref="IHttpResponse.AddHeader"/>
/// <seealso cref="IHttpResponse.Send"/>
/// <seealso cref="IHttpResponse.SendBody(byte[])"/>
bool SendHeaders();
} }
/// <summary> /// <summary>