53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using ln.http.content;
|
|
using ln.type;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace ln.http.client
|
|
{
|
|
public class HttpClientResponse
|
|
{
|
|
public HttpMethod Method { get; }
|
|
public Uri Uri { get; }
|
|
|
|
public HttpStatusCode StatusCode { get; }
|
|
public string Reason { get; }
|
|
|
|
private HeaderContainer _responseHeaders;
|
|
private Stream _contentStream;
|
|
|
|
public HeaderContainer Headers => _responseHeaders;
|
|
public Stream ContentStream => _contentStream;
|
|
|
|
public HttpClientResponse(HttpMethod method, Uri uri, HttpStatusCode statusCode, string reason, HeaderContainer responseHeaders, Stream contentStream)
|
|
{
|
|
Method = method;
|
|
Uri = uri;
|
|
|
|
StatusCode = statusCode;
|
|
Reason = reason;
|
|
|
|
_responseHeaders = responseHeaders;
|
|
_contentStream = contentStream;
|
|
}
|
|
|
|
private string? _bodyText;
|
|
public string Text
|
|
{
|
|
get
|
|
{
|
|
if (_bodyText is null)
|
|
_bodyText = Encoding.UTF8.GetString(ContentStream.ReadToEnd());
|
|
return _bodyText;
|
|
}
|
|
}
|
|
|
|
public T Json<T>() => JsonConvert.DeserializeObject<T>(Text);
|
|
|
|
|
|
public override string ToString() => String.Format("{0} {1}", (int)StatusCode, StatusCode);
|
|
}
|
|
}
|