Skip to content
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

Webstreams #70

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft

Webstreams #70

wants to merge 11 commits into from

Conversation

markusn
Copy link
Contributor

@markusn markusn commented Nov 8, 2023

based on the fastly branch


const reader = transformedStream.getReader();

for (;;) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (;;) {
while (true) {

kanske en gnutta mer lättläst?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praxis verkar vara att använda for…of loopar för att tugga igenom web streams – docs/api/webstreams.html#async-iteration. Varför gör vi inte det?

for await (const chunk of transformedStream) {
  if (chunk.done) break;
  body += chunk.value;
}

response.statusCode = statusCode;
if (location) {
response.headers = response.headers || {};
response.headers.location = location;
}
this.destroy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hur funkar det här nu istället, chunk.done ?

if (text) {
return this.evaluator.ontext(text, next);
return await this.evaluator.ontext(text, controller);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

behövs await ?

context.breakHit = context.breakHit || context.shouldWrite();
return context.breakHit ? next(null, { name: "esi:break" }) : next();
if (context.breakHit) controller.enqueue({ name: "esi:break" });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Varför används controller.enqueue istället för return här?
Känns som att det blandas ganska friskt med att använda controller eller return… ESIEvaluator borde väl kunna låta alla ESITag jobba med bara returvärden / kasta fel?

Comment on lines 82 to 90
// if this is localhost and we have a computeAtEdge config when we need to map to a
// backend
if (host === this.options.localhost && self.options.computeAtEdge) {
backend = self.options.computeAtEdge.defaultBackend;
// maybe we have different backends, let's check
if (self.options.computeAtEdge.pathToBackend) {
// FIXME: implement
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😵‍💫 Mycket options. Vet inte om jag hänger inte med… Är det typ i test: adress är http://localhost; i edge: adress är https://app-env.bn.nr ?

@@ -15,19 +15,13 @@
],
"author": "Bonnier News",
"license": "MIT",
"peerDependencies": {
"@bonniernews/atlas-html-stream": ">=2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Varför är det här inte längre en peer dependency? Det är ju ett paket som importas i koden. Går ju inte bara att ha som dev dependency.

Comment on lines +750 to +751
mock.method(global, "fetch", (url, options) => {
if (!(url === "http://mystuff/" && options.method === "GET" && !options.headers["content-type"])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sånt här är ju inte helt optimalt. URL-encoding, case insensitivity, timeouts etc… Finns det någon typ polyfill av fetch man kan skicka som tredje argument så nock kan fånga upp riktiga anrop?

if (!(url === "http://mystuff/" && options.method === "GET" && !options.headers["content-type"])) {
return { status: 404 };
}
return { body: ReadableStream.from(evalResponse), status: 200 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returnvärdet ska vara en promise

Comment on lines 917 to 919
if (url === "http://mystuff/case-insensitive" && options.method === "GET" && options.headers["extra-header"] === "Case insensitive") {
return { body: ReadableStream.from("header name is case insensitive"), status: 200 };
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xD testar väl inte längre case sensitivity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

const markup = "<esi:include src=\"/mystuff/\" dca=\"none\"/><p>efter</p>";

mock.method(global, "fetch", (url, options) => {
if (!(url === "http://localhost:1234/mystuff/" && options.method === "GET" && options.backend === "origin" && options.headers.foo === "bar")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch tar väl inte options.backend? Eller är det en egenhet i Fastly's edge miljö?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

det är fastlys

@Daghall
Copy link

Daghall commented Feb 8, 2024

@markusn, is this still relevant, or can we close it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants