Skip to content

Commit

Permalink
3.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
rusildo committed Feb 7, 2016
1 parent d42f484 commit 5a34c91
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 195 deletions.
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Ruslan Khuduev")]
[assembly: AssemblyProduct("xNet")]
[assembly: AssemblyCopyright("Copyright © 2012-2015 Ruslan Khuduev <x-rus@list.ru>")]
[assembly: AssemblyCopyright("Copyright © 2012-2016 Ruslan Khuduev <x-rus@list.ru>")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -33,6 +33,6 @@
// Можно задать все значения или принять номер построения и номер редакции по умолчанию,
// используя "*", как показано ниже:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.3.2.0")]
[assembly: AssemblyFileVersion("3.3.2.0")]
[assembly: AssemblyVersion("3.3.3.0")]
[assembly: AssemblyFileVersion("3.3.3.0")]
[assembly: NeutralResourcesLanguageAttribute("ru")]
4 changes: 2 additions & 2 deletions xNet.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xNet", "xNet.csproj", "{5D25D06E-0D35-42EF-BBA2-D5DE6E06CD04}"
EndProject
Expand Down
193 changes: 3 additions & 190 deletions xNet/~Http/HttpResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,139 +295,6 @@ public override void Write(byte[] buffer, int offset, int count)
#endregion
}

// Поток для считывания тела сообщения.
private sealed class HttpResponseStream : Stream
{
#region Поля (закрытые)

private Stream _baseStream;
private ReceiverHelper _receiverHelper;
private Action<Exception> _endWrite;

#endregion


#region Свойства (открытые)

public override bool CanRead
{
get
{
return true;
}
}

public override bool CanSeek
{
get
{
return false;
}
}

public override bool CanTimeout
{
get
{
return false;
}
}

public override bool CanWrite
{
get
{
return false;
}
}

public override long Length
{
get
{
throw new NotSupportedException();
}
}

public override long Position
{
get
{
throw new NotSupportedException();
}
set
{
throw new NotSupportedException();
}
}

#endregion


public HttpResponseStream(Stream baseStream,
ReceiverHelper receiverHelper, Action<Exception> endWrite)
{
_baseStream = baseStream;
_receiverHelper = receiverHelper;
_endWrite = endWrite;
}


#region Методы (открытые)

public override void Flush()
{
_baseStream.Flush();
}

public override void SetLength(long value)
{
throw new NotSupportedException();
}

public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}

public override int Read(byte[] buffer, int offset, int count)
{
int bytesRead;

try
{
if (_receiverHelper.HasData)
{
bytesRead = _receiverHelper.Read(buffer, offset, count);
}
else
{
bytesRead = _baseStream.Read(buffer, offset, count);
}
}
catch (Exception ex)
{
_endWrite(ex);

throw ex;
}

if (bytesRead == 0)
{
_endWrite(null);
}

return bytesRead;
}

public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}

#endregion
}

#endregion


Expand Down Expand Up @@ -877,59 +744,6 @@ public void ToFile(string path)
MessageBodyLoaded = true;
}

/// <summary>
/// Возвращает поток тела сообщения.
/// </summary>
/// <returns>>Если тело сообщения отсутствует, или оно уже было загружено, то будет возвращено значение <see langword="null"/>.</returns>
/// <exception cref="System.InvalidOperationException">Вызов метода из ошибочного ответа.</exception>
/// <exception cref="xNet.Net.HttpException">Ошибка при работе с HTTP-протоколом.</exception>
public Stream ToStream()
{
#region Проверка состояния

if (HasError)
{
throw new InvalidOperationException(
Resources.InvalidOperationException_HttpResponse_HasError);
}

#endregion

if (MessageBodyLoaded)
{
return null;
}

var stream = new HttpResponseStream(_request.ClientStream, _receiverHelper, (ex) =>
{
if (ex != null)
{
HasError = true;
if (ex is IOException || ex is InvalidOperationException)
{
throw NewHttpException(Resources.HttpException_FailedReceiveMessageBody, ex);
}
throw ex;
}
if (ConnectionClosed())
{
_request.Dispose();
}
MessageBodyLoaded = true;
});

if (_headers.ContainsKey("Content-Encoding"))
{
return GetZipStream(stream);
}

return stream;
}

/// <summary>
/// Загружает тело сообщения и возвращает его в виде потока байтов из памяти.
/// </summary>
Expand Down Expand Up @@ -983,7 +797,7 @@ public MemoryStream ToMemoryStream()
}

MessageBodyLoaded = true;

memoryStream.Position = 0;
return memoryStream;
}

Expand Down Expand Up @@ -1177,7 +991,6 @@ internal long LoadResponse(HttpMethod method)
try
{
ReceiveStartingLine();

ReceiveHeaders();

RedirectAddress = GetLocation();
Expand Down Expand Up @@ -1843,9 +1656,9 @@ private Encoding GetCharacterSet()

try
{
return Encoding.GetEncoding(header);
return Encoding.GetEncoding(charset.Value);
}
catch (ArgumentException)
catch (ArgumentException ex)
{
return _request.CharacterSet ?? Encoding.Default;
}
Expand Down

0 comments on commit 5a34c91

Please sign in to comment.