Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
#823 Update TODO comments
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoding121 committed Apr 26, 2021
1 parent 476f877 commit 158e728
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Titanium.Web.Proxy/Helpers/HttpStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ internal class HttpStream : Stream, IHttpStreamWriter, IHttpStreamReader, IPeekS
private readonly IBufferPool bufferPool;
private readonly CancellationToken cancellationToken;

public bool IsNetworkStream => isNetworkStream;

public event EventHandler<DataEventArgs>? DataRead;

public event EventHandler<DataEventArgs>? DataWrite;
Expand Down Expand Up @@ -1056,8 +1058,11 @@ public Task CopyBodyAsync(IHttpStreamWriter writer, bool isChunked, long content
{

#if DEBUG
if ((isRequest && args.HttpClient.Request.OriginalHasBody && !args.HttpClient.Request.IsBodyRead && server.ShouldCallBeforeRequestBodyWrite())
|| (!isRequest && args.HttpClient.Response.OriginalHasBody && !args.HttpClient.Response.IsBodyRead && server.ShouldCallBeforeResponseBodyWrite()))
var isResponse = !isRequest;

if (isNetworkStream && writer.IsNetworkStream &&
(isRequest && args.HttpClient.Request.OriginalHasBody && !args.HttpClient.Request.IsBodyRead && server.ShouldCallBeforeRequestBodyWrite()) ||
(isResponse && args.HttpClient.Response.OriginalHasBody && !args.HttpClient.Response.IsBodyRead && server.ShouldCallBeforeResponseBodyWrite()))
{
return handleBodyWrite(writer, isChunked, contentLength, isRequest, args, cancellationToken);
}
Expand All @@ -1084,6 +1089,10 @@ private Task handleBodyWrite(IHttpStreamWriter writer, bool isChunked, long cont
var originalContentLength = isRequest ? args.HttpClient.Request.OriginalContentLength : args.HttpClient.Response.OriginalContentLength;
var originalIsChunked = isRequest ? args.HttpClient.Request.OriginalIsChunked : args.HttpClient.Response.OriginalIsChunked;

//TODO
//create a new decompression stream to wrap this source HttpStream based on original content encoding if needed.
//create a new compression stream to wrap target writer stream based on content encoding if needed.

//1. Begin while(true) loop
//2. Parse chunk if chunked, and read bytes from original stream. Max length of bytes read will be equal to bufferPool.BufferSize.
//3. Call BeforeBodyWrite event handler with BeforeBodyWriteEventArgs.BodyBytes set to the bytes read from original stream (pass null if original stream reached its end).
Expand Down
2 changes: 2 additions & 0 deletions src/Titanium.Web.Proxy/Helpers/NullWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ internal class NullWriter : IHttpStreamWriter
{
public static NullWriter Instance { get; } = new NullWriter();

public bool IsNetworkStream => false;

private NullWriter()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
/// </summary>
public interface IHttpStreamWriter
{
bool IsNetworkStream { get; }

void Write(byte[] buffer, int offset, int count);

Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken);
Expand Down

0 comments on commit 158e728

Please sign in to comment.