Commit 181bb352 authored by Shani Elharrar's avatar Shani Elharrar

Created ListHttpHeaders with list underlying

parent 1c4dfbe1
......@@ -3,11 +3,54 @@ using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace uhttpsharp.Headers
{
[DebuggerDisplay("{Count} Headers")]
[DebuggerTypeProxy(typeof(HttpHeadersDebuggerProxy))]
internal class ListHttpHeaders : IHttpHeaders
{
private readonly IList<KeyValuePair<string, string>> _values;
public ListHttpHeaders(IList<KeyValuePair<string, string>> values)
{
_values = values;
}
public string GetByName(string name)
{
return _values.Where(kvp => kvp.Key.Equals(name, StringComparison.InvariantCultureIgnoreCase)).Select(kvp => kvp.Value).First();
}
public bool TryGetByName(string name, out string value)
{
value = _values.Where(kvp => kvp.Key == name).Select(kvp => kvp.Value).FirstOrDefault();
return (value != default(string));
}
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
return _values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
internal int Count
{
get
{
return _values.Count;
}
}
}
[DebuggerDisplay("{Count} Headers")]
[DebuggerTypeProxy(typeof(HttpHeadersDebuggerProxy))]
internal class HttpHeaders : IHttpHeaders
......
......@@ -57,7 +57,7 @@ namespace uhttpsharp
_requestProvider = requestProvider;
var bufferedStream = new BufferedStream(_client.Stream);
_outputStream = new StreamWriter(bufferedStream) { NewLine = CrLf };
_inputStream = new StreamReader(bufferedStream);
......
......@@ -100,6 +100,7 @@ namespace uhttpsharp
{
ContentStream.Position = 0;
await ContentStream.CopyToAsync(writer.BaseStream).ConfigureAwait(false);
await writer.BaseStream.FlushAsync().ConfigureAwait(false);
}
......

\ No newline at end of file
......@@ -32,17 +32,20 @@ namespace uhttpsharp.RequestProviders
var queryString = GetQueryStringData(ref url);
var uri = new Uri(url, UriKind.Relative);
var headersRaw = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
var headersRaw = new List<KeyValuePair<string, string>>();
// get the headers
string line;
while (!string.IsNullOrEmpty((line = await streamReader.ReadLineAsync().ConfigureAwait(false))))
{
var headerKvp = SplitHeader(line);
headersRaw.Add(headerKvp.Key, headerKvp.Value);
{
string currentLine = line;
var headerKvp = SplitHeader(currentLine);
headersRaw.Add(headerKvp);
}
IHttpHeaders headers = new HttpHeaders(headersRaw);
IHttpHeaders headers = new ListHttpHeaders(headersRaw);
IHttpHeaders post = await GetPostData(streamReader, headers).ConfigureAwait(false);
return new HttpRequest(headers, httpMethod, httpProtocol, uri,
......
......@@ -78,7 +78,6 @@
<Compile Include="HttpResponse.cs" />
<Compile Include="HttpServer.cs" />
<Compile Include="HttpServerExtensions.cs" />
<Compile Include="IEnumerable.cs" />
<Compile Include="IHttpContext.cs" />
<Compile Include="IHttpMethodProvider.cs" />
<Compile Include="Listeners\IHttpListener.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment