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

Add reply::file(path) helper #171

Open
ngotchac opened this issue Feb 13, 2019 · 4 comments · May be fixed by #1049
Open

Add reply::file(path) helper #171

ngotchac opened this issue Feb 13, 2019 · 4 comments · May be fixed by #1049
Labels
feature New feature or request rfc Extra attention is needed

Comments

@ngotchac
Copy link

Hi, I have a question on how to properly use the fs::file Filter.

I'd like to have something like this:

	let route = warp::get2()
		.and(path!("files" / String))
		.and(warp::path::end())
		.and_then(get_file_path)
		.and_then(|filepath| warp::fs::file(filepath));

Where get_file_path would be a Future returning a PathBuf.

Is there any way to achieve this?

Thanks, and great project BTW 😃

@seanmonstar
Copy link
Owner

At the moment, no, there's no real good way to do this...

I suppose there's two ways warp could enable this:

  • Allow "flattening" of filters, like as proposed in Add a flatten() function to the Filter trait. #92. That'd allow creating a new filter within an existing one, like your example wants to do.
  • Consider a warp::reply::file helper, which does a lot of what the fs::file filter does. It wouldn't be able to handle conditionals or ranges, but it could simply send the file to the client...

@ngotchac
Copy link
Author

Okay I see, I thought about n°2, since in my case I don't really need those condition filters. I'll watch #92 then!
Should I close this issue, or do you want to keep it open?

@seanmonstar seanmonstar changed the title [Question] Dynamic file Filter Add reply::file(path) helper Feb 25, 2019
@seanmonstar seanmonstar added feature New feature or request rfc Extra attention is needed labels Feb 25, 2019
Ruin0x11 added a commit to Ruin0x11/mdBook that referenced this issue Aug 30, 2020
We can't redirect in warp based on the URL, so redirect to the default
language's 404 page instead.

See: seanmonstar/warp#171
@SuperCuber
Copy link

Recently needed this for a route that generates a file, caches it, and serves the cached file. Wanted to switch to a different library to allow for this, but none of the other big ones implement serving partial file...

Gonna either go for some solution with route wrapping, or going to modify the client to first request the server generates the cache and tells it what filename to request, then sends another request which will go through a proper fs::dir filter.

@flosse
Copy link

flosse commented May 12, 2021

why can't we make file_reply public?

fn file_reply(

flosse added a commit to flosse/warp that referenced this issue May 12, 2021
flosse added a commit to flosse/warp that referenced this issue May 12, 2021
Ruin0x11 added a commit to Ruin0x11/mdBook that referenced this issue May 19, 2021
We can't redirect in warp based on the URL, so redirect to the default
language's 404 page instead.

See: seanmonstar/warp#171
rzerres pushed a commit to rzerres/mdBook that referenced this issue Sep 14, 2021
We can't redirect in warp based on the URL, so redirect to the default
language's 404 page instead.

See: seanmonstar/warp#171
Ruin0x11 added a commit to Ruin0x11/mdBook that referenced this issue Sep 15, 2021
We can't redirect in warp based on the URL, so redirect to the default
language's 404 page instead.

See: seanmonstar/warp#171
arctic-hen7 added a commit to arctic-hen7/warp that referenced this issue Dec 11, 2021
@Molkars Molkars linked a pull request Jul 2, 2023 that will close this issue
mirrorcult added a commit to space-wizards/mdBook-spacewizards that referenced this issue Sep 28, 2023
commit 8664faea083017b1ec7c9d811be28427b8408bef
Author: Kara <lunarautomaton6@gmail.com>
Date:   Thu Sep 28 10:47:37 2023 -0500

    Update for new mdbook version

commit 1b45e7a7a6521b4df6d441788a7fff105eba9240
Merge: e74fdb1 79edc75
Author: Kara <lunarautomaton6@gmail.com>
Date:   Thu Sep 28 10:03:55 2023 -0500

    Merge branch 'master' into localization

    # Conflicts:
    #	Cargo.lock
    #	Cargo.toml
    #	src/book/book.rs
    #	src/book/init.rs
    #	src/book/mod.rs
    #	src/cmd/build.rs
    #	src/cmd/clean.rs
    #	src/cmd/serve.rs
    #	src/cmd/test.rs
    #	src/cmd/watch.rs
    #	src/config.rs
    #	src/preprocess/links.rs
    #	src/renderer/html_handlebars/hbs_renderer.rs
    #	src/renderer/markdown_renderer.rs
    #	src/utils/mod.rs
    #	tests/init.rs

commit e74fdb1
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Fri Feb 25 14:30:38 2022 -0800

    Make `chapter_titles` optional in Book

commit 7305e8c
Merge: 9d8147c 5921f59
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Fri Feb 25 14:13:22 2022 -0800

    Merge remote-tracking branch 'upstream/master' into localization

    # Conflicts:
    #	.gitignore
    #	guide/src/en/cli/completions.md
    #	guide/src/en/format/images/rust-logo-blk.svg
    #	guide/src/en/format/markdown.md
    #	guide/src/en/misc/introduction.md
    #	src/renderer/html_handlebars/hbs_renderer.rs
    #	src/utils/mod.rs

commit 9d8147c
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Wed Sep 15 21:49:58 2021 -0700

    Remove extra `localization.md`

commit 56e72a2
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Wed Sep 15 15:33:28 2021 -0700

    [localization] rustfmt

commit 92ec3dd
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Wed Sep 15 15:25:31 2021 -0700

    [localization] Fixes for latest master

commit d6c27ab
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Sat Aug 29 16:11:47 2020 -0700

    Implement translation fallback of files included with preprocessing

commit 5fed5e8
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Wed Sep 15 14:29:30 2021 -0700

    Update mdBook manual to have information about translations

commit 09a8b66
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Sat Aug 29 14:41:08 2020 -0700

    Improve robustness of link rewriting

commit 8d1c086
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Fri Aug 28 16:33:02 2020 -0700

    Fix {{#include}} directives for default language

commit 98c3a04
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Fri Aug 28 16:11:21 2020 -0700

    Move example book to multilingual structure

commit c72ce18
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Fri Aug 28 14:50:04 2020 -0700

    Rewrite links in Markdown to point to fallback if missing in translation

    It will follow relative links to other pages and embedded images.

commit ee740ac
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Fri Aug 28 12:26:08 2020 -0700

    Remove 'default' property on languages, use book.language instead

commit a042cfc
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Fri Aug 28 11:35:42 2020 -0700

    Make `mdbook init` output multilingual structure

commit 5e223e0
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Fri Aug 28 03:17:26 2020 -0700

    Support localizing book title/description

commit e17ce64
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Fri Aug 28 02:29:07 2020 -0700

    Fix test using create_missing

commit 282fdaa
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Fri Aug 28 02:05:21 2020 -0700

    Redirect to a 404 page when serving translated

    We can't redirect in warp based on the URL, so redirect to the default
    language's 404 page instead.

    See: seanmonstar/warp#171

commit 85ab4d3
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Fri Aug 28 01:36:22 2020 -0700

    Redirect to translation index page in serve command

commit 8869c2c
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Fri Aug 28 00:24:33 2020 -0700

    Build multiple books from localizations at once

    Changes how the `book` module loads books. Now it is possible to load
    all of the translations of a book and put them into a single output
    folder. If a book is generated this way, a menu will be created in the
    handlebars renderer for switching between languages.

commit 96d9271
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Thu Aug 27 19:44:24 2020 -0700

    Specify language for book in command line args

    - Add a [language] table to book.toml. Each key in the table defines a
    new language with `name` and `default` properties.
    - Changes the directory structure of localized books. If the [language]
    table exists, mdBook will now assume the src/ directory contains
    subdirectories named after the keys in [language]. The behavior is
    backwards-compatible if you don't specify [language].
    - Specify which language of book to build using the -l/--language
    argument to `mdbook build` and similar, or omit to use the default
    language.
    - Specify the default language by setting the `default` property to
    `true` in an entry in [language]. Exactly one language must have `default`
    set to `true` if the [language] table is defined.
    - Each language has its own SUMMARY.md. It can include links to files
    not in other translations. If a link in SUMMARY.md refers to a
    nonexistent file that is specified in the default language, the renderer
    will gracefully degrade the link to the default language's page. If it
    still doesn't exist, the config's `create_missing` option will be
    respected instead.

commit 3049d9f
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Thu Aug 27 16:35:00 2020 -0700

    Actually, don't change source root

    The book paths have to gracefully degrade to the default language if
    they aren't available.

commit 24e6d6b
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Thu Aug 27 16:26:07 2020 -0700

    Change book source root depending on language

commit e4b443c
Author: Ruin0x11 <ipickering2@gmail.com>
Date:   Thu Aug 27 13:27:47 2020 -0700

    Add language config section

    Referencing rust-lang#5 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request rfc Extra attention is needed
Projects
None yet
4 participants