-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7940f3
commit 7442510
Showing
7 changed files
with
101 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// The Sisk Framework source code | ||
// Copyright (c) 2024- PROJECT PRINCIPIUM and all Sisk contributors | ||
// | ||
// The code below is licensed under the MIT license as | ||
// of the date of its publication, available at | ||
// | ||
// File name: HttpEventStreamWriter.cs | ||
// Repository: https://github.com/sisk-http/core | ||
|
||
using System.Text; | ||
|
||
namespace Sisk.ManagedHttpListener; | ||
|
||
public sealed class HttpEventStreamWriter { | ||
private Stream _innerStream; | ||
private Encoding _messageEncoding; | ||
|
||
internal HttpEventStreamWriter ( Stream innerStream, Encoding encoding ) { | ||
this._innerStream = innerStream; | ||
this._messageEncoding = encoding; | ||
} | ||
|
||
public async Task WriteDataAsync ( string data ) { | ||
byte [] payload = this._messageEncoding.GetBytes ( $"data: {data}\n\n" ); | ||
await this._innerStream.WriteAsync ( payload ); | ||
} | ||
|
||
public async Task WriteEventAsync ( string eventName ) { | ||
byte [] payload = this._messageEncoding.GetBytes ( $"event: {eventName}\n\n" ); | ||
await this._innerStream.WriteAsync ( payload ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters