-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How does Response support returning to SSE #89
Labels
feature request
Proposals for new features
Comments
I added the sse methodimport 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:meta/meta.dart';
import 'package:vania/src/http/response/stream_file.dart';
enum ResponseType {
...
sse,
}
class Response {
...
case ResponseType.sse:
res.headers.contentType = ContentType.parse('text/event-stream');
res.headers.add(HttpHeaders.cacheControlHeader, 'no-cache');
res.headers.add(HttpHeaders.connectionHeader, 'keep-alive');
res.headers.add(HttpHeaders.transferEncodingHeader, 'chunked');
void writeSSE(String data) {
res.add(utf8.encode('data: $data\n\n'));
}
await for (var event in data) {
writeSSE(jsonEncode(event));
await res.flush();
}
await res.close();
break;
default:
res.write(data);
await res.close();
}
}
...
static sse(
Stream<dynamic> eventStream, {
int statusCode = HttpStatus.ok,
Map<String, String> headers = const {},
}) =>
Response(
data: eventStream,
responseType: ResponseType.sse,
httpStatusCode: statusCode,
headers: headers,
);
} |
javad-zobeidi
added a commit
to javad-zobeidi/framework
that referenced
this issue
Jul 3, 2024
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How does Response support returning to SSE
The text was updated successfully, but these errors were encountered: