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

Allow calling existing endpoints recursively #36

Closed
shouya opened this issue Feb 20, 2024 · 0 comments · Fixed by #47
Closed

Allow calling existing endpoints recursively #36

shouya opened this issue Feb 20, 2024 · 0 comments · Fixed by #47

Comments

@shouya
Copy link
Owner

shouya commented Feb 20, 2024

Now if we want to refer to an endpoint inside another endpoint (e.g. in merge filter), we have to write out the absolute url explicitly.

- path: /generate.xml
  filters: <some filters>
- path: /my-feed.xml
  source: <some source feed>
  filters:
    - merge: http://my-domain/generate.xml?source=https://source1/page.html
    - merge: http://my-domain/generate.xml?source=https://source2/page.html
    - merge: http://my-domain/generate.xml?source=https://source3/page.html

It would be nice if we can omit that like this:

- path: /generate.xml
  filters: <some filters>
- path: /my-feed.xml
  source: <some source feed>
  filters:
    - merge: /generate.xml?source=https://source1/page.html
    - merge: /generate.xml?source=https://source2/page.html
    - merge: /generate.xml?source=https://source3/page.html

It would be better if we can detect cycles and stops the infinite chain. But this shouldn't be much of an issue given the timeout setting is there to avoid leaking.

The host name can be either inferred from Host field or have it converted into an internal call.

shouya added a commit that referenced this issue Feb 22, 2024
Prior to this change, the `FeedFilter` trait is defined as follows:

``` rust
pub trait FeedFilter {
  async fn run(&self, feed: &mut Feed) -> Result<()>;
}
```

Now I want to change the `FeedFilter` trait to be as follows:

``` rust
pub trait FeedFilter {
  async fn run(&self, ctx: &mut FilterContext, feed: Feed) -> Result<Feed>;
}
```

There are two major changes made to this interface.

First, the `run` method now takes a `FilterContext` that can be used to
store and retrieve state. The can `FilterContext` is used to influence
the behavior of filters. Currently no filter uses this context yet. But
I plan to put the base address from the request to the context so that
the `client` downstream can use this information to reconstruct absolute
url from relative urls. (c.f. #36)

Secondly, I modified the `feed` parameter to allow each filter to take
full ownership of the feed. The main reason is that I hope to define a
`FeedFilter` as to a **stateful endofunction on a Feed** (or more
precisely: an async, fallible, and stateful endofunction). I think the
new type more clearly indicates its nature. The original signature hints
that a filter somehow "modifies" a feed, which is slightly different
conceptually.

-------

In addition to the above changes, I also extracted the `FilterPipeline`
type into a standalone module. The concept was previously known as
`Filters`, but I dislike terrible naming.

---------

Co-authored-by: Shou Ya <shouya@users.noreply.github.com>
shouya added a commit that referenced this issue Feb 22, 2024
Fix #36.

Note: this feature depends on correct `X-Forwarded-Host` and
`X-Forwarded-Proto` headers.

---------

Co-authored-by: shouya <shouya@users.noreply.github.com>
This issue was closed.
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 a pull request may close this issue.

1 participant