public static int GetResponseLength(ReadOnlySpan <byte> buffer) { if (!HttpHelper.SeekHeader(buffer, CommonStrings.HeaderContentLength.Span, out var index, out var length)) { return(-1); } var headerEndIndex = buffer.Slice(index + length).IndexOf(CommonStrings.HeaderEnd.Span); if (headerEndIndex < 0) { return(-1); } var contentLength = ByteExtensions.ConvertToInt(buffer.Slice(index, length)); return(index + length + headerEndIndex + 4 + contentLength); }
public void ByteExtensions_ConvertToInt() { Assert.AreEqual(5, ByteExtensions.ConvertToInt(_request.Span.Slice(90, 1))); Assert.AreEqual(12345, ByteExtensions.ConvertToInt(_request.Span.Slice(95, 5))); }
public static int GetStatusCode(ReadOnlySpan <byte> buffer) { return(ByteExtensions.ConvertToInt(buffer.Slice(9, 3))); }
public static int GetStatusCode(byte[] buffer, int start, int end) { return(ByteExtensions.ConvertToInt(buffer, start + 9, 3, end)); }
public static int GetHeaderContentLength(ReadOnlySpan <byte> buffer) { HttpHelper.SeekHeader(buffer, CommonStrings.HeaderContentLength.Span, out var index, out var length); return(ByteExtensions.ConvertToInt(buffer.Slice(index, length))); }
public static int GetHeaderContentLength(byte[] buffer, int start, int end) { HttpHelper.SeekHeader(buffer, HttpHeaders.ContentLength, start, end, out var index, out var length); return(ByteExtensions.ConvertToInt(buffer, index, length, end)); }
public void ByteExtensions_ConvertToInt() { Assert.AreEqual(5, ByteExtensions.ConvertToInt(_request, 90, 1, _request.Length)); Assert.AreEqual(12345, ByteExtensions.ConvertToInt(_request, 95, 5, _request.Length)); }