protected override async Task DoProcess(CancellationToken cancel_token) { try { this.Status = ConnectionStatus.Connecting; var host = SourceUri.DnsSafeHost; if (SourceUri.Port != -1 && SourceUri.Port != 80) { host = String.Format("{0}:{1}", SourceUri.DnsSafeHost, SourceUri.Port); } var request = String.Format( "GET {0} HTTP/1.1\r\n" + "Host: {1}\r\n" + "User-Agent: NSPlayer ({2})\r\n" + "Connection: close\r\n" + "Pragma: stream-switch\r\n" + "\r\n", SourceUri.PathAndQuery, host, PeerCast.AgentName); await connection.Stream.WriteAsync(System.Text.Encoding.UTF8.GetBytes(request)).ConfigureAwait(false); Logger.Debug("Sending request:\n" + request); response = null; response = await HTTPResponseReader.ReadAsync(connection.Stream, cancel_token).ConfigureAwait(false); if (response.Status != 200) { Logger.Error("Server responses {0} to GET {1}", response.Status, SourceUri.PathAndQuery); Stop(response.Status == 404 ? StopReason.OffAir : StopReason.UnavailableError); } this.Status = ConnectionStatus.Connected; await contentReader.ReadAsync(contentSink, connection.Stream, cancel_token).ConfigureAwait(false); Stop(StopReason.OffAir); } catch (InvalidDataException) { Stop(StopReason.ConnectionError); } catch (OperationCanceledException) { Logger.Error("Recv content timed out"); Stop(StopReason.ConnectionError); } catch (IOException) { Stop(StopReason.ConnectionError); } this.Status = ConnectionStatus.Error; }
protected override async Task DoProcess(CancellationToken cancel_token) { try { this.Status = ConnectionStatus.Connecting; var host = SourceUri.DnsSafeHost; if (SourceUri.Port != -1 && SourceUri.Port != 80) { host = $"{SourceUri.DnsSafeHost}:{SourceUri.Port}"; } var request = $"GET {SourceUri.PathAndQuery} HTTP/1.1\r\n" + $"Host: {host}\r\n" + "Accept: */*\r\n" + "User-Agent: NSPlayer/12.0\r\n" + "Connection: close\r\n" + "Cache-Control: no-cache\r\n" + "Pragma: xPlayStrm=1\r\n" + "Pragma: rate=1.000,stream-time=0\r\n" + "\r\n"; await connection.Stream.WriteAsync(System.Text.Encoding.UTF8.GetBytes(request)).ConfigureAwait(false); Logger.Debug("Sending request:\n" + request); response = null; response = await HTTPResponseReader.ReadAsync(connection.Stream, cancel_token).ConfigureAwait(false); if (response.Status != 200) { Logger.Error("Server responses {0} to GET {1}", response.Status, SourceUri.PathAndQuery); Stop(response.Status == 404 ? StopReason.OffAir : StopReason.UnavailableError); } this.Status = ConnectionStatus.Connected; await contentReader.ReadAsync(contentSink, connection.Stream, cancel_token).ConfigureAwait(false); Stop(StopReason.OffAir); } catch (InvalidDataException) { Stop(StopReason.ConnectionError); } catch (OperationCanceledException) { Logger.Error("Recv content timed out"); Stop(StopReason.ConnectionError); } catch (IOException) { Stop(StopReason.ConnectionError); } this.Status = ConnectionStatus.Error; }