@@ -11,7 +11,7 @@ public class HttpAdapter(IHttpClient httpClient) : IHttpAdapter
1111{
1212 private readonly List < IMyObserver < ProtocolMessage > > _observers = [ ] ;
1313
14- private async Task < IHttpResponse > GetResponseAsync ( ProtocolMessage message , CancellationToken cancellationToken )
14+ private async Task < IHttpResponse > SendProtocolMessageAsync ( ProtocolMessage message , CancellationToken cancellationToken )
1515 {
1616 var req = new HttpRequest
1717 {
@@ -35,7 +35,7 @@ private async Task<IHttpResponse> GetResponseAsync(ProtocolMessage message, Canc
3535 private static async Task < ProtocolMessage > GetMessageAsync ( IHttpResponse response )
3636 {
3737 var message = new ProtocolMessage ( ) ;
38- if ( response . MediaType . Equals ( "application/octet-stream" , StringComparison . InvariantCultureIgnoreCase ) )
38+ if ( response . MediaType . Equals ( MediaTypeNames . Application . Octet , StringComparison . InvariantCultureIgnoreCase ) )
3939 {
4040 message . Type = ProtocolMessageType . Bytes ;
4141 message . Bytes = await response . ReadAsByteArrayAsync ( ) ;
@@ -50,14 +50,25 @@ private static async Task<ProtocolMessage> GetMessageAsync(IHttpResponse respons
5050
5151 public async Task SendAsync ( ProtocolMessage message , CancellationToken cancellationToken )
5252 {
53- var response = await GetResponseAsync ( message , cancellationToken ) ;
53+ var response = await SendProtocolMessageAsync ( message , cancellationToken ) ;
54+ await HandleResponseAsync ( response ) ;
55+ }
56+
57+ private async Task HandleResponseAsync ( IHttpResponse response )
58+ {
5459 var incomingMessage = await GetMessageAsync ( response ) ;
5560 foreach ( var observer in _observers )
5661 {
5762 observer . OnNext ( incomingMessage ) ;
5863 }
5964 }
6065
66+ public async Task SendAsync ( IHttpRequest req , CancellationToken cancellationToken )
67+ {
68+ var response = await httpClient . SendAsync ( req , cancellationToken ) ;
69+ await HandleResponseAsync ( response ) ;
70+ }
71+
6172 public void Subscribe ( IMyObserver < ProtocolMessage > observer )
6273 {
6374 if ( _observers . Contains ( observer ) )
0 commit comments