aboutsummaryrefslogtreecommitdiff
path: root/lib/Net.Http/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Net.Http/src')
-rw-r--r--lib/Net.Http/src/Core/ConnectionInfo.cs59
-rw-r--r--lib/Net.Http/src/Core/Response/ResponseWriter.cs6
-rw-r--r--lib/Net.Http/src/IConnectionInfo.cs19
3 files changed, 10 insertions, 74 deletions
diff --git a/lib/Net.Http/src/Core/ConnectionInfo.cs b/lib/Net.Http/src/Core/ConnectionInfo.cs
index e680152..8a1525c 100644
--- a/lib/Net.Http/src/Core/ConnectionInfo.cs
+++ b/lib/Net.Http/src/Core/ConnectionInfo.cs
@@ -24,13 +24,11 @@
using System;
using System.Net;
-using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Security.Authentication;
using VNLib.Net.Http.Core;
-using VNLib.Utils.Extensions;
namespace VNLib.Net.Http
{
@@ -76,65 +74,16 @@ namespace VNLib.Net.Http
///<inheritdoc/>
public IReadOnlyDictionary<string, string> RequestCookies => Context.Request.Cookies;
///<inheritdoc/>
- public IEnumerable<string> Accept => Context.Request.Accept;
+ public IReadOnlyCollection<string> Accept => Context.Request.Accept;
///<inheritdoc/>
public TransportSecurityInfo? TransportSecurity => Context.GetSecurityInfo();
///<inheritdoc/>
- public bool Accepts(ContentType type)
- {
- //Get the content type string from he specified content type
- string contentType = HttpHelpers.GetContentTypeString(type);
- return Accepts(contentType);
- }
-
- ///<inheritdoc/>
- public bool Accepts(string contentType)
- {
- if (AcceptsAny())
- {
- return true;
- }
-
- //If client accepts exact requested encoding
- if (Accept.Contains(contentType, StringComparer.OrdinalIgnoreCase))
- {
- return true;
- }
-
- //Search for the content-sub-type
-
- //Get prinary side of mime type
- ReadOnlySpan<char> primary = contentType.AsSpan().SliceBeforeParam('/');
-
- for (int i = 0; i < Context.Request.Accept.Count; i++)
- {
- //The the accept subtype
- ReadOnlySpan<char> ctSubType = Context.Request.Accept[i].AsSpan().SliceBeforeParam('/');
-
- //See if accepts any subtype, or the primary sub-type matches
- if(ctSubType[0] == '*' || ctSubType.Equals(primary, StringComparison.OrdinalIgnoreCase))
- {
- return true;
- }
- }
-
- return false;
- }
-
- /// <summary>
- /// Determines if the connection accepts any content type
- /// </summary>
- /// <returns>true if the connection accepts any content typ, false otherwise</returns>
- private bool AcceptsAny()
- {
- //Accept any if no accept header was present, or accept all value */*
- return Context.Request.Accept.Count == 0 || Accept.Where(static t => t.StartsWith("*/*", StringComparison.OrdinalIgnoreCase)).Any();
- }
-
- ///<inheritdoc/>
public void SetCookie(string name, string value, string? domain, string? path, TimeSpan Expires, CookieSameSite sameSite, bool httpOnly, bool secure)
{
+ //name MUST not be null
+ _ = name ?? throw new ArgumentNullException(nameof(name));
+
//Create the new cookie
HttpCookie cookie = new(name)
{
diff --git a/lib/Net.Http/src/Core/Response/ResponseWriter.cs b/lib/Net.Http/src/Core/Response/ResponseWriter.cs
index d67fc01..dcb220f 100644
--- a/lib/Net.Http/src/Core/Response/ResponseWriter.cs
+++ b/lib/Net.Http/src/Core/Response/ResponseWriter.cs
@@ -242,7 +242,7 @@ namespace VNLib.Net.Http.Core
}
//Compress the buffered data and flush if required
- if(CompressNextSegment(buffer, comp, writer))
+ if (CompressNextSegment(buffer, read, comp, writer))
{
//Time to flush
await writer.FlushAsync(false);
@@ -309,13 +309,13 @@ namespace VNLib.Net.Http.Core
return writer.Advance(res.BytesWritten) == 0;
}
- private static bool CompressNextSegment(Memory<byte> readSegment, IResponseCompressor comp, IResponseDataWriter writer)
+ private static bool CompressNextSegment(Memory<byte> readSegment, int read, IResponseCompressor comp, IResponseDataWriter writer)
{
//Get output buffer
Memory<byte> output = writer.GetMemory();
//Compress the trimmed block
- CompressionResult res = comp.CompressBlock(readSegment, output);
+ CompressionResult res = comp.CompressBlock(readSegment[..read], output);
return writer.Advance(res.BytesWritten) == 0;
}
diff --git a/lib/Net.Http/src/IConnectionInfo.cs b/lib/Net.Http/src/IConnectionInfo.cs
index 17ee16f..0feedd9 100644
--- a/lib/Net.Http/src/IConnectionInfo.cs
+++ b/lib/Net.Http/src/IConnectionInfo.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Net.Http
@@ -113,25 +113,12 @@ namespace VNLib.Net.Http
/// <summary>
/// Gets an <see cref="IEnumerator{T}"/> for the parsed accept header values
/// </summary>
- IEnumerable<string> Accept { get; }
+ IReadOnlyCollection<string> Accept { get; }
/// <summary>
/// Gets the underlying transport security information for the current connection
/// </summary>
TransportSecurityInfo? TransportSecurity { get; }
-
- /// <summary>
- /// Determines if the client accepts the response content type
- /// </summary>
- /// <param name="type">The desired content type</param>
- /// <returns>True if the client accepts the content type, false otherwise</returns>
- bool Accepts(ContentType type);
-
- /// <summary>
- /// Determines if the client accepts the response content type
- /// </summary>
- /// <param name="contentType">The desired content type</param>
- /// <returns>True if the client accepts the content type, false otherwise</returns>
- bool Accepts(string contentType);
+
/// <summary>
/// Adds a new cookie to the response. If a cookie with the same name and value