update components

This commit is contained in:
Luke Pulverenti 2016-11-12 20:53:51 -05:00
parent 38c216a61a
commit 3e06bda46b
3 changed files with 8 additions and 37 deletions

View File

@ -161,10 +161,8 @@ namespace ServiceStack
var responseText = result as string; var responseText = result as string;
if (responseText != null) if (responseText != null)
{ {
if (response.ContentType == null || response.ContentType == "text/html")
response.ContentType = defaultContentType;
var bytes = Encoding.UTF8.GetBytes(responseText); var bytes = Encoding.UTF8.GetBytes(responseText);
response.SetContentLength(bytes.Length);
await response.OutputStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false); await response.OutputStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
return; return;
} }

View File

@ -209,7 +209,7 @@ namespace SocketHttpListener.Net
// TODO: can we get this stream before reading the input? // TODO: can we get this stream before reading the input?
if (o_stream == null) if (o_stream == null)
{ {
if (context.Response.SendChunked || isExpect100Continue) if (context.Response.SendChunked || isExpect100Continue || context.Response.ContentLength64 <= 0)
{ {
o_stream = new ResponseStream(stream, context.Response, _memoryStreamFactory, _textEncoding); o_stream = new ResponseStream(stream, context.Response, _memoryStreamFactory, _textEncoding);
} }
@ -438,7 +438,9 @@ namespace SocketHttpListener.Net
str = String.Format("<h1>{0}</h1>", description); str = String.Format("<h1>{0}</h1>", description);
byte[] error = context.Response.ContentEncoding.GetBytes(str); byte[] error = context.Response.ContentEncoding.GetBytes(str);
response.Close(error, false); response.ContentLength64 = error.Length;
response.OutputStream.Write(error, 0, (int)error.Length);
response.Close();
} }
catch catch
{ {
@ -492,7 +494,9 @@ namespace SocketHttpListener.Net
{ {
Stream st = GetResponseStream(); Stream st = GetResponseStream();
if (st != null) if (st != null)
{
st.Dispose(); st.Dispose();
}
o_stream = null; o_stream = null;
} }
@ -514,16 +518,6 @@ namespace SocketHttpListener.Net
if (!force_close && context.Request.FlushInput()) if (!force_close && context.Request.FlushInput())
{ {
if (chunked && context.Response.ForceCloseChunked == false)
{
// Don't close. Keep working.
reuses++;
Unbind();
Init();
BeginReadRequest();
return;
}
reuses++; reuses++;
Unbind(); Unbind();
Init(); Init();

View File

@ -30,8 +30,6 @@ namespace SocketHttpListener.Net
internal bool HeadersSent; internal bool HeadersSent;
internal object headers_lock = new object(); internal object headers_lock = new object();
bool force_close_chunked;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ITextEncoding _textEncoding; private readonly ITextEncoding _textEncoding;
@ -50,11 +48,6 @@ namespace SocketHttpListener.Net
} }
} }
internal bool ForceCloseChunked
{
get { return force_close_chunked; }
}
public Encoding ContentEncoding public Encoding ContentEncoding
{ {
get get
@ -327,7 +320,7 @@ namespace SocketHttpListener.Net
headers.Add(name, value); headers.Add(name, value);
} }
void Close(bool force) private void Close(bool force)
{ {
if (force) if (force)
{ {
@ -345,20 +338,6 @@ namespace SocketHttpListener.Net
Close(false); Close(false);
} }
public void Close(byte[] responseEntity, bool willBlock)
{
if (disposed)
return;
if (responseEntity == null)
throw new ArgumentNullException("responseEntity");
//TODO: if willBlock -> BeginWrite + Close ?
ContentLength64 = responseEntity.Length;
OutputStream.Write(responseEntity, 0, (int)content_length);
Close(false);
}
public void Redirect(string url) public void Redirect(string url)
{ {
StatusCode = 302; // Found StatusCode = 302; // Found