Skip to content

Commit

Permalink
Revert "feat: add postBody Functionality"
Browse files Browse the repository at this point in the history
This reverts commit 73e1a3a.
  • Loading branch information
cdloh committed Aug 6, 2024
1 parent 73e1a3a commit 7d3113e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 101 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Library supports all instructions that the Ledge parser supports. Also supports
- [varsCookieBlacklist](#varscookieblacklist)
- [Custom ESI Vars Function](#custom-esi-vars-function)
- [Custom Fetch Function](#custom-fetch-function)
- [Optional Post Body Function](#optional-post-body-function)
- [Caching and upstream requests](#caching-and-upstream-requests)
- [Edge Side Includes](#edge-side-includes)
- [Regular expressions in conditions](#regular-expressions-in-conditions)
Expand Down Expand Up @@ -59,7 +58,6 @@ new esi(
options?: // Config
customESIFunction?: // Custom ESI Vars Function
fetcher?: // Custom Fetch Function
postBodyFunction?: // Optional function that will be called once the body has been completed
)
```

Expand Down Expand Up @@ -247,10 +245,6 @@ new esi(undefined, undefined, customFetcher)
```


### Optional Post Body Function

If you need to do extra work once the body has completed streaming, eg you record how many fetches your custom fetcher handles. Or need to fire off some context.waitUntil functions at the end you can fire them after this function has been called.


## Caching and upstream requests

Expand Down
15 changes: 3 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export type customESIVarsFunction = (
request: Request,
) => Promise<customESIVars>;
export type fetchFunction = (request: string | Request) => Promise<Response>;
export type postBodyFunction = () => void | Promise<void>;

const processorToken = "ESI";
const processorVersion = 1.0;
Expand All @@ -112,22 +111,19 @@ export class esi {
options: ESIConfig;
esiFunction?: customESIVarsFunction;
fetcher: fetchFunction;
postBodyFunction?: postBodyFunction;

constructor(
options?: ESIConfig,
customESIFunction?: customESIVarsFunction,
fetcher = fetch as fetchFunction,
postBodyFunction?: postBodyFunction,
) {
const defaultConfig = {
recursionLimit: 10,
contentTypes: ["text/html", "text/plain"],
};
this.options = { ...defaultConfig, ...options };
this.fetcher = fetcher;
this.esiFunction = customESIFunction;
this.postBodyFunction = postBodyFunction;
if (customESIFunction) this.esiFunction = customESIFunction;
}

async parse(origRequest: Request, recursion = 0): Promise<Response> {
Expand Down Expand Up @@ -256,7 +252,7 @@ export class esi {
/**
* Flushes output to the Writeable Stream
*/
const flush_output = async () => {
async function flush_output() {
// Can't call this if we're waiting for an sync option to complete
if (pending) {
return;
Expand Down Expand Up @@ -291,13 +287,8 @@ export class esi {
if (ended && output.length === 0) {
const writer = writable.getWriter();
await writer.close();

// we're completely done now notify the post body function
if (this.postBodyFunction) {
this.postBodyFunction();
}
}
};
}

const writer = (text: string, esi: boolean) => {
if (esi) {
Expand Down
83 changes: 0 additions & 83 deletions test/postBody.spec.ts

This file was deleted.

0 comments on commit 7d3113e

Please sign in to comment.