Class
BasePipe

Abstract base class for the ClientPipe and ServerPipe classes. A Pipe represents a connection to either the client or the server, optionally encrypted using SSL/TLS.

Definition

Namespace:Fiddler

Assembly:FiddlerCore.dll

Syntax:

cs-api-definition
public abstract class BasePipe

Inheritance: objectBasePipe

Derived Classes: ClientPipeServerPipe

Inherited Members object.GetType()object.MemberwiseClone()object.ToString()object.Equals(object)object.Equals(object, object)object.ReferenceEquals(object, object)object.GetHashCode()

Constructors

BasePipe(Socket, string)

Create a new pipe, an enhanced wrapper around a socket

Declaration

cs-api-definition
public BasePipe(Socket oSocket, string sName)

Parameters

oSocket

Socket

Socket which this pipe wraps

sName

string

Identification string used for debugging purposes

Fields

SendLock

Used to ensure that send operations on the pipe are queued

Declaration

cs-api-definition
protected readonly SemaphoreSlim SendLock

Field Value

SemaphoreSlim

_baseSocket

The base socket wrapped in this pipe

Declaration

cs-api-definition
protected Socket _baseSocket

Field Value

Socket

_httpsStream

The HTTPS stream wrapped around the base socket (SslStream on Windows/Linux or BcTlsConnection.AuthenticatedStream on MacOS)

Declaration

cs-api-definition
protected Stream _httpsStream

Field Value

Stream

_sPipeName

The display name of this Pipe. Use strings starting with "ClientPipe" for client pipes and "ServerPipe" for server pipes.

Declaration

cs-api-definition
protected string _sPipeName

Field Value

string

clientPipeName

The name that should be used for client pipes

Declaration

cs-api-definition
public const string clientPipeName = "ClientPipe"

Field Value

string

iUseCount

The number of times that this Pipe has been used

Declaration

cs-api-definition
protected uint iUseCount

Field Value

uint

serverPipeName

The name that should be used for client pipes

Declaration

cs-api-definition
public const string serverPipeName = "ServerPipe"

Field Value

string

Properties

Address

Returns the remote address to which this Pipe is connected, or 0.0.0.0 on error.

Declaration

cs-api-definition
public IPAddress Address { get; }

Property Value

IPAddress

Connected

Return the Connected status of the base socket. WARNING: This doesn't work as you might expect; you can see Connected == false when a READ timed out but a WRITE will succeed.

Declaration

cs-api-definition
public bool Connected { get; }

Property Value

bool

IsHTTP2

Returns true if the SslStream's negotiated protocol is h2

Declaration

cs-api-definition
public bool IsHTTP2 { get; }

Property Value

bool

LocalPort

Return the Local Port to which the base socket is attached. Note: May return a misleading port if the ISA Firewall Client is in use.

Declaration

cs-api-definition
public int LocalPort { get; }

Property Value

int

Port

Return the Remote Port to which this socket is attached.

Declaration

cs-api-definition
public int Port { get; }

Property Value

int

SecureProtocol

Returns the SSL/TLS protocol securing this connection

Declaration

cs-api-definition
public SslProtocols SecureProtocol { get; }

Property Value

SslProtocols

TransmitDelay

Gets or sets the transmission delay on this Pipe, used for performance simulation purposes.

Declaration

cs-api-definition
public int TransmitDelay { get; set; }

Property Value

int

bIsSecured

Returns a bool indicating if the socket in this Pipe is CURRENTLY connected and wrapped in a SecureStream

Declaration

cs-api-definition
public bool bIsSecured { get; }

Property Value

bool

Methods

EndAsync(ErrorCode, string)

Shutdown and close the socket inside this pipe. Eats exceptions.

Declaration

cs-api-definition
public Task EndAsync(ErrorCode errorCode = 0, string debugData = "")

Parameters

errorCode

ErrorCode

debugData

string

Returns

Task

EndWithRST()

Abruptly closes the socket by sending a RST packet

Declaration

cs-api-definition
public void EndWithRST()

GetRawSocket()

Return the raw socket this pipe wraps. Avoid calling this method if at all possible.

Declaration

cs-api-definition
public Socket GetRawSocket()

Returns

Socket

The Socket object this Pipe wraps.

HasDataAvailable()

Poll the underlying socket for readable data (or closure/errors)

Declaration

cs-api-definition
public virtual bool HasDataAvailable()

Returns

bool

TRUE if this Pipe requires attention

InitializeHTTP2PipeAsync()

HTTP2 connections must be initialized by receiving and sending specific headers and settings frames. This happens only once per established connection.

Declaration

cs-api-definition
public Task InitializeHTTP2PipeAsync()

Returns

Task

SendAsync(byte[])

Sends a byte array through this pipe

Declaration

cs-api-definition
public Task SendAsync(byte[] oBytes)

Parameters

oBytes

byte[]

The bytes

Returns

Task

SendDataAsync(byte[], int, int, uint, bool)

Send a byte array through this pipe, taking into account the protocol used (http/1.1 or http/2)

Declaration

cs-api-definition
public Task<int> SendDataAsync(byte[] arrData, int responseOffset, int responseLength, uint streamId, bool final = true)

Parameters

arrData

byte[]

Array to send

responseOffset

int

The data offset in the array to send

responseLength

int

How many bytes of the array to send

streamId

uint

The stream ID - omitted for http/1.1 pipes

final

bool

True if this is the final data(body) to send through the pipe - not used for http/1.1 pipes

Returns

Task<int>

The size of the transferred data over the network in bytes

SendRequestHeadersAsync(HTTPRequestHeaders, uint, bool, string, bool?)

Send HTTP request headers through the pipe with additional options

Declaration

cs-api-definition
public Task<int> SendRequestHeadersAsync(HTTPRequestHeaders headers, uint newStreamId, bool includeProtocolInPath, string sVerbLineHost, bool? hasBody)

Parameters

headers

HTTPRequestHeaders

request headers

newStreamId

uint

the stream ID to use when sending HTTP2 headers

includeProtocolInPath

bool

TRUE if the SCHEME and HOST should be included in the HTTP REQUEST LINE

sVerbLineHost

string

the host to use in the HTTP REQUEST LINE

hasBody

bool?

HTTP2 only - True if there is a body ready to send after the headers

Returns

Task<int>

The size of the transferred data over the network in bytes

SendResponseHeadersAsync(HTTPResponseHeaders, uint?, bool?, bool, bool)

Send HTTP headers through a pipe

Declaration

cs-api-definition
public Task<int> SendResponseHeadersAsync(HTTPResponseHeaders headers, uint? streamId, bool? hasBody, bool ignoreTranslationErrors = false, bool trailersOnly = false)

Parameters

headers

HTTPResponseHeaders

response headers

streamId

uint?

HTTP2 only - the stream ID

hasBody

bool?

HTTP2 only - True if there is a body ready to send after the headers

ignoreTranslationErrors

bool

Ignore possible errors that occur if headers are translated from HTTP/1.1 to HTTP/2

trailersOnly

bool

Set to true only if this is a GRPC response that does not have response headers (e.g. error response)

Returns

Task<int>

The size of the transferred data over the network in bytes

UseCustomTlsProvider()

On Mac OS a SslStream cannot authenticate as a TLS server, so we need to use another TLS stream implementation. On Mac OS, SslStream does not support TLS 1.3 as client, so we need to use another TLS stream implementation.

Declaration

cs-api-definition
protected bool UseCustomTlsProvider()

Returns

bool

True if a custom stream should be used instead of the .NET SslStream for TLS connections.

Events

OnConnectionClosed

Raised when the connection is closed

Declaration

cs-api-definition
public event EventHandler OnConnectionClosed

Event Value

EventHandler