nu_command/network/http/
pool.rs1use crate::network::http::client::{
2 RedirectMode, add_unix_socket_flag, expand_unix_socket_path, http_parse_redirect_mode,
3 reset_http_client_pool,
4};
5use nu_engine::command_prelude::*;
6
7#[derive(Clone)]
8pub struct HttpPool;
9
10impl Command for HttpPool {
11 fn name(&self) -> &str {
12 "http pool"
13 }
14
15 fn signature(&self) -> Signature {
16 let sig = Signature::build("http pool")
17 .input_output_types(vec![(Type::Nothing, Type::Any)])
18 .allow_variants_without_examples(true)
19 .switch(
20 "insecure",
21 "allow insecure server connections when using SSL",
22 Some('k'),
23 )
24 .switch(
25 "allow-errors",
26 "do not fail if the server returns an error code",
27 Some('e'),
28 )
29 .param(
30 Flag::new("redirect-mode")
31 .short('R')
32 .arg(SyntaxShape::String)
33 .desc(
34 "What to do when encountering redirects. Default: 'follow'. Valid \
35 options: 'follow' ('f'), 'manual' ('m'), 'error' ('e').",
36 )
37 .completion(Completion::new_list(RedirectMode::MODES)),
38 )
39 .category(Category::Network);
40 add_unix_socket_flag(sig)
41 }
42
43 fn description(&self) -> &str {
44 "Configure and reset builtin http connection pool."
45 }
46
47 fn extra_description(&self) -> &str {
48 "All connections inside http connection poll will be closed."
49 }
50
51 fn search_terms(&self) -> Vec<&str> {
52 vec!["network"]
53 }
54
55 fn run(
56 &self,
57 engine_state: &EngineState,
58 stack: &mut Stack,
59 call: &Call,
60 _input: PipelineData,
61 ) -> Result<PipelineData, ShellError> {
62 let args = Arguments {
63 insecure: call.has_flag(engine_state, stack, "insecure")?,
64 redirect: call.get_flag(engine_state, stack, "redirect-mode")?,
65 unix_socket: call.get_flag(engine_state, stack, "unix-socket")?,
66 };
67
68 let redirect_mode = http_parse_redirect_mode(args.redirect)?;
69
70 let cwd = engine_state.cwd(None)?;
71 let unix_socket_path = expand_unix_socket_path(args.unix_socket, &cwd);
72 reset_http_client_pool(
73 args.insecure,
74 redirect_mode,
75 unix_socket_path,
76 engine_state,
77 stack,
78 )?;
79 Ok(PipelineData::Empty)
80 }
81}
82
83struct Arguments {
84 insecure: bool,
85 redirect: Option<Spanned<String>>,
86 unix_socket: Option<Spanned<String>>,
87}