Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix #3112 serve docs on localhost:{random port}#3697

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
brettearle wants to merge13 commits intorust-lang:master
base:master
Choose a base branch
Loading
frombrettearle:fix-3112

Conversation

brettearle
Copy link
Contributor

A starting implementation looking for feedback and whether I am on the right path

@brettearlebrettearle changed the titleFix 3112Fix 3112 serve docs on localhost:{random port}Mar 8, 2024
@brettearlebrettearle marked this pull request as draftMarch 8, 2024 12:43
@brettearlebrettearle changed the titleFix 3112 serve docs on localhost:{random port}Fix #3112 serve docs on localhost:{random port}Mar 8, 2024
@@ -12,13 +12,13 @@ build = "build.rs"

[features]
curl-backend = ["download/curl-backend"]

Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid making unrelated changes.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Sorry. Will avoid

@@ -86,6 +86,7 @@ termcolor.workspace = true
thiserror.workspace = true
threadpool = "1"
tokio = { workspace = true, optional = true }
tiny_http = "0.11"
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that we're already depending on hyper for the reqwest download backend, I think we should be using hyper (0.14) for the server, too.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Too easy, will do

@@ -725,6 +726,9 @@ pub(crate) fn cli() -> Command {
.value_parser(partial_toolchain_desc_parser),
)
.arg(Arg::new("topic").help(TOPIC_ARG_HELP))
.subcommand(
Command::new("servedoc")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should probably bedoc --serve rather than a new command.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Alright, so this would be instead of a specific doc flag and just do base docs or in addition to specific flag "doc --nomicon --serve"?

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be a new--serve flag on the existingdoc command, that works orthogonally to other flags. Maybe it should take an optional port number orSocketAddr (like192.168.0.1:3112) as argument?

Comment on lines +1616 to +1652
let doc_path_index = toolchain.doc_path(doc_url)?;
let doc_path_base = toolchain.doc_path("")?;
let doc_path_str = doc_path_base.to_string_lossy().into_owned();
loop {
let server = Server::http("127.0.0.1:0").unwrap();
println!("Serving documentation at {}", server.server_addr());
for request in server.incoming_requests() {
//TODO get request path and serve filebased on that
let request_path = request.url().strip_prefix('/');
match request_path {
Some(mut request_path) => {
println!("doc url: {:?}", &doc_url);
println!("Req file: {:?}", &request_path);
let base_string = doc_path_str.clone();
if request_path == "" {
request_path = doc_url;
}
//strip search params
if let Some(index) = request_path.find('?') {
request_path = &request_path[..index];
}
//ignore favicon requests
if request_path == "favicon.ico" {
continue;
}
let path = String::from(base_string + &request_path);
println!("Serving file: {:?}", &path);
let file = std::fs::File::open(path).unwrap();
request.respond(Response::from_file(file)).unwrap();
}
None => {
let file = std::fs::File::open(&doc_path_index).unwrap();
request.respond(Response::from_file(file)).unwrap();
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be outlined into a separate function.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Too easy, will do

@djc
Copy link
Contributor

djc commentedMar 8, 2024

(Also please make sure to runcargo fmt and committing the result before pushing.)

brettearle reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@djcdjcdjc left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@brettearle@djc

[8]ページ先頭

©2009-2025 Movatter.jp