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

Commit

Permalink
#823 Add before write body prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoding121 committed Apr 22, 2021
1 parent d01da7e commit 8a32fa9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Titanium.Web.Proxy/EventArguments/BeforeBodySendEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#if DEBUG
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Titanium.Web.Proxy.EventArguments
{

public class BeforeBodyWriteEventArgs : ProxyEventArgsBase
{
internal BeforeBodyWriteEventArgs(SessionEventArgs session, byte[] bodyBytes, bool isChunked, bool isFinalChunk) : base(session.ClientConnection)
{
Session = session;
BodyBytes = bodyBytes;
IsChunked = isChunked;
IsFinalChunk = isFinalChunk;
}


/// <value>
/// The session arguments.
/// </value>
public SessionEventArgs Session { get; }

/// <summary>
/// Indicates whether body is written chunked stream.
/// If this is true, BeforeRequestBodySend or BeforeResponseBodySend will be called until IsLastChunk is false.
/// </summary>
public bool IsChunked { get; }

/// <summary>
/// Indicates if this is the last chunk from client or server stream, when request is chunked.
/// Override this property to true if there are more bytes to write.
/// </summary>
public bool IsFinalChunk { get; set; }

/// <summary>
/// The bytes about to be written. If IsChunked is true, this will be a chunk of the bytes to be written.
/// Override this property with custom bytes if needed, and adjust IsLastChunk accordingly.
/// </summary>
public byte[] BodyBytes { get; set; }
}
}
#endif
12 changes: 12 additions & 0 deletions src/Titanium.Web.Proxy/ProxyServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,23 @@ public ExceptionHandler ExceptionFunc
/// </summary>
public event AsyncEventHandler<SessionEventArgs>? BeforeRequest;

#if DEBUG
/// <summary>
/// Intercept request body send event to server.
/// </summary>
public event AsyncEventHandler<BeforeBodyWriteEventArgs>? OnRequestBodyWrite;
#endif
/// <summary>
/// Intercept response event from server.
/// </summary>
public event AsyncEventHandler<SessionEventArgs>? BeforeResponse;

#if DEBUG
/// <summary>
/// Intercept request body send event to client.
/// </summary>
public event AsyncEventHandler<BeforeBodyWriteEventArgs>? OnResponseBodyWrite;
#endif
/// <summary>
/// Intercept after response event from server.
/// </summary>
Expand Down

0 comments on commit 8a32fa9

Please sign in to comment.