Class HttpConnection
- Namespace
- AppleTvControlLibrary.Mrp.AirPlay.Http
- Assembly
- AppleTvControlLibrary.Mrp.dll
A TCP-backed HTTP/RTSP request/response connection used for the AirPlay 2 control channel. Supports optional send/receive processors so HAP encryption can be layered on transparently once pair-verify has completed.
public sealed class HttpConnection : IDisposable
- Inheritance
-
HttpConnection
- Implements
- Inherited Members
Remarks
Only the client-side subset needed to drive AirPlay 2 session setup is ported; the
server-side pieces of pyatv's support/http.py (used for local file serving) are out
of scope here.
Properties
LocalIp
Gets the local IP address of the connection.
public string LocalIp { get; }
Property Value
ReceiveProcessor
Gets or sets the processor applied to data as it is received (e.g. HAP decryption).
public Func<byte[], byte[]>? ReceiveProcessor { get; set; }
Property Value
RemoteIp
Gets the remote IP address of the connection.
public string RemoteIp { get; }
Property Value
SendProcessor
Gets or sets the processor applied to data before it is sent (e.g. HAP encryption).
public Func<byte[], byte[]>? SendProcessor { get; set; }
Property Value
Methods
ConnectAsync(string, int, CancellationToken)
Open a new connection to a remote host.
public static Task<HttpConnection> ConnectAsync(string address, int port, CancellationToken cancellationToken = default)
Parameters
addressstringThe remote address.
portintThe remote port.
cancellationTokenCancellationTokenA token used to cancel the connection attempt.
Returns
- Task<HttpConnection>
A connected HttpConnection.
Dispose()
Closes the underlying socket and stops the read loop.
public void Dispose()
GetAsync(string, bool, CancellationToken)
Send a GET request and wait for the response.
public Task<HttpResponse> GetAsync(string path, bool allowError = false, CancellationToken cancellationToken = default)
Parameters
pathstringThe request path.
allowErrorboolIf true, non-2xx responses are returned rather than throwing.
cancellationTokenCancellationTokenA token used to cancel the exchange.
Returns
PostAsync(string, IReadOnlyDictionary<string, string>?, byte[]?, bool, CancellationToken)
Send a POST request and wait for the response.
public Task<HttpResponse> PostAsync(string path, IReadOnlyDictionary<string, string>? headers = null, byte[]? body = null, bool allowError = false, CancellationToken cancellationToken = default)
Parameters
pathstringThe request path.
headersIReadOnlyDictionary<string, string>Additional request headers.
bodybyte[]The request body.
allowErrorboolIf true, non-2xx responses are returned rather than throwing.
cancellationTokenCancellationTokenA token used to cancel the exchange.
Returns
SendAndReceiveAsync(string, string, string, string, string?, IReadOnlyDictionary<string, string>?, byte[]?, bool, TimeSpan?, CancellationToken)
Send a request of the given method and wait for the matching response.
public Task<HttpResponse> SendAndReceiveAsync(string method, string uri, string protocol = "HTTP/1.1", string userAgent = "AppleTvControlLibrary", string? contentType = null, IReadOnlyDictionary<string, string>? headers = null, byte[]? body = null, bool allowError = false, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
methodstringThe request method.
uristringThe request path/URI.
protocolstringThe protocol/version string, e.g. "HTTP/1.1" or "RTSP/1.0".
userAgentstringThe value of the User-Agent header.
contentTypestringAn optional Content-Type header value.
headersIReadOnlyDictionary<string, string>Additional request headers.
bodybyte[]An optional request body.
allowErrorboolIf true, non-2xx responses are returned rather than throwing.
timeoutTimeSpan?How long to wait for a response before failing.
cancellationTokenCancellationTokenA token used to cancel the exchange.
Returns
- Task<HttpResponse>
The response to the request.