-
Notifications
You must be signed in to change notification settings - Fork 894
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
Fix #3112 serve docs on localhost:{random port} #3697
base: master
Are you sure you want to change the base?
Changes from all commits
3f6b85c
046ee47
8bac841
ec74a12
c18c165
1b2bd36
77b4769
ff3e3e7
1def36e
1a4cfe6
468bcaf
aab2838
1c2b60b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,13 @@ build = "build.rs" | |
|
||
[features] | ||
curl-backend = ["download/curl-backend"] | ||
|
||
default = [ | ||
"curl-backend", | ||
"reqwest-backend", | ||
"reqwest-default-tls", | ||
"reqwest-rustls-tls", | ||
] | ||
|
||
reqwest-backend = ["download/reqwest-backend"] | ||
vendored-openssl = ['openssl/vendored'] | ||
|
||
|
@@ -90,6 +90,7 @@ termcolor.workspace = true | |
thiserror.workspace = true | ||
threadpool = "1" | ||
tokio = { workspace = true, optional = true } | ||
tiny_http = "0.11" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too easy, will do |
||
toml = "0.8" | ||
tracing-opentelemetry = { workspace = true, optional = true } | ||
tracing-subscriber = { workspace = true, optional = true, features = ["env-filter"] } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ use clap::{ | |
}; | ||
use clap_complete::Shell; | ||
use itertools::Itertools; | ||
use tiny_http::{Response, Server}; | ||
|
||
use crate::{ | ||
cli::{ | ||
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should probably be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be a new |
||
) | ||
.group( | ||
ArgGroup::new("page").args( | ||
DOCS_DATA | ||
|
@@ -738,7 +742,7 @@ pub(crate) fn cli() -> Command { | |
.iter() | ||
.map(|&(name, help_msg, _)| Arg::new(name).long(name).help(help_msg).action(ArgAction::SetTrue)) | ||
.collect::<Vec<_>>(), | ||
), | ||
) | ||
); | ||
|
||
if cfg!(not(target_os = "windows")) { | ||
|
@@ -1613,6 +1617,44 @@ fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> { | |
let doc_path = toolchain.doc_path(doc_url)?; | ||
writeln!(process().stdout().lock(), "{}", doc_path.display())?; | ||
Ok(utils::ExitCode(0)) | ||
} else if m.subcommand_matches("servedoc").is_some() { | ||
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(); | ||
} | ||
} | ||
} | ||
} | ||
Comment on lines
+1621
to
+1657
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be outlined into a separate function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too easy, will do |
||
} else { | ||
toolchain.open_docs(doc_url)?; | ||
Ok(utils::ExitCode(0)) | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. Will avoid