Skip to content

Commit

Permalink
no cab frfr
Browse files Browse the repository at this point in the history
  • Loading branch information
nick1udwig committed Oct 28, 2024
1 parent 6d3e977 commit 1e6792d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
40 changes: 20 additions & 20 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::str::FromStr;
use thiserror::Error;

/// Request type sent to the `http_client:distro:sys` service in order to open a
/// Request type sent to the `http-client:distro:sys` service in order to open a
/// WebSocket connection, send a WebSocket message on an existing connection, or
/// send an HTTP request.
///
Expand All @@ -31,7 +31,7 @@ pub enum HttpClientAction {
}

/// HTTP Request type that can be shared over Wasm boundary to apps.
/// This is the one you send to the `http_client:distro:sys` service.
/// This is the one you send to the `http-client:distro:sys` service.
///
/// BODY is stored in the lazy_load_blob, as bytes
///
Expand All @@ -48,7 +48,7 @@ pub struct OutgoingHttpRequest {
}

/// Request that comes from an open WebSocket client connection in the
/// `http_client:distro:sys` service. Be prepared to receive these after
/// `http-client:distro:sys` service. Be prepared to receive these after
/// using a [`HttpClientAction::WebSocketOpen`] to open a connection.
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum HttpClientRequest {
Expand All @@ -61,7 +61,7 @@ pub enum HttpClientRequest {
},
}

/// Response type received from the `http_client:distro:sys` service after
/// Response type received from the `http-client:distro:sys` service after
/// sending a successful [`HttpClientAction`] to it.
#[derive(Debug, Serialize, Deserialize)]
pub enum HttpClientResponse {
Expand All @@ -72,15 +72,15 @@ pub enum HttpClientResponse {
#[derive(Error, Debug, Serialize, Deserialize)]
pub enum HttpClientError {
// HTTP errors
#[error("http_client: request is not valid HttpClientRequest: {req}.")]
#[error("http-client: request is not valid HttpClientRequest: {req}.")]
BadRequest { req: String },
#[error("http_client: http method not supported: {method}.")]
#[error("http-client: http method not supported: {method}.")]
BadMethod { method: String },
#[error("http_client: url could not be parsed: {url}.")]
#[error("http-client: url could not be parsed: {url}.")]
BadUrl { url: String },
#[error("http_client: http version not supported: {version}.")]
#[error("http-client: http version not supported: {version}.")]
BadVersion { version: String },
#[error("http_client: failed to execute request {error}.")]
#[error("http-client: failed to execute request {error}.")]
RequestFailed { error: String },

// WebSocket errors
Expand All @@ -105,7 +105,7 @@ pub fn send_request(
timeout: Option<u64>,
body: Vec<u8>,
) {
let req = KiRequest::to(("our", "http_client", "distro", "sys"))
let req = KiRequest::to(("our", "http-client", "distro", "sys"))
.body(
serde_json::to_vec(&HttpClientAction::Http(OutgoingHttpRequest {
method: method.to_string(),
Expand All @@ -123,7 +123,7 @@ pub fn send_request(
}
}

/// Make an HTTP request using http_client and await its response.
/// Make an HTTP request using http-client and await its response.
///
/// Returns [`Response`] from the `http` crate if successful, with the body type as bytes.
pub fn send_request_await_response(
Expand All @@ -133,7 +133,7 @@ pub fn send_request_await_response(
timeout: u64,
body: Vec<u8>,
) -> std::result::Result<http::Response<Vec<u8>>, HttpClientError> {
let res = KiRequest::to(("our", "http_client", "distro", "sys"))
let res = KiRequest::to(("our", "http-client", "distro", "sys"))
.body(
serde_json::to_vec(&HttpClientAction::Http(OutgoingHttpRequest {
method: method.to_string(),
Expand All @@ -150,7 +150,7 @@ pub fn send_request_await_response(
.unwrap();
let Ok(Message::Response { body, .. }) = res else {
return Err(HttpClientError::RequestFailed {
error: "http_client timed out".to_string(),
error: "http-client timed out".to_string(),
});
};
let resp = match serde_json::from_slice::<
Expand All @@ -160,13 +160,13 @@ pub fn send_request_await_response(
Ok(Ok(HttpClientResponse::Http(resp))) => resp,
Ok(Ok(HttpClientResponse::WebSocketAck)) => {
return Err(HttpClientError::RequestFailed {
error: "http_client gave unexpected response".to_string(),
error: "http-client gave unexpected response".to_string(),
})
}
Ok(Err(e)) => return Err(e),
Err(e) => {
return Err(HttpClientError::RequestFailed {
error: format!("http_client gave invalid response: {e:?}"),
error: format!("http-client gave invalid response: {e:?}"),
})
}
};
Expand All @@ -176,12 +176,12 @@ pub fn send_request_await_response(
for (key, value) in &resp.headers {
let Ok(key) = http::header::HeaderName::from_str(key) else {
return Err(HttpClientError::RequestFailed {
error: format!("http_client gave invalid header key: {key}"),
error: format!("http-client gave invalid header key: {key}"),
});
};
let Ok(value) = http::header::HeaderValue::from_str(value) else {
return Err(HttpClientError::RequestFailed {
error: format!("http_client gave invalid header value: {value}"),
error: format!("http-client gave invalid header value: {value}"),
});
};
headers.insert(key, value);
Expand All @@ -197,7 +197,7 @@ pub fn open_ws_connection(
channel_id: u32,
) -> std::result::Result<(), HttpClientError> {
let Ok(Ok(Message::Response { body, .. })) =
KiRequest::to(("our", "http_client", "distro", "sys"))
KiRequest::to(("our", "http-client", "distro", "sys"))
.body(
serde_json::to_vec(&HttpClientAction::WebSocketOpen {
url: url.clone(),
Expand All @@ -219,7 +219,7 @@ pub fn open_ws_connection(

/// Send a WebSocket push message on an open WebSocket channel.
pub fn send_ws_client_push(channel_id: u32, message_type: WsMessageType, blob: KiBlob) {
KiRequest::to(("our", "http_client", "distro", "sys"))
KiRequest::to(("our", "http-client", "distro", "sys"))
.body(
serde_json::to_vec(&HttpClientAction::WebSocketPush {
channel_id,
Expand All @@ -235,7 +235,7 @@ pub fn send_ws_client_push(channel_id: u32, message_type: WsMessageType, blob: K
/// Close a WebSocket connection.
pub fn close_ws_connection(channel_id: u32) -> std::result::Result<(), HttpClientError> {
let Ok(Ok(Message::Response { body, .. })) =
KiRequest::to(("our", "http_client", "distro", "sys"))
KiRequest::to(("our", "http-client", "distro", "sys"))
.body(
serde_json::json!(HttpClientAction::WebSocketClose { channel_id })
.to_string()
Expand Down
40 changes: 20 additions & 20 deletions src/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use thiserror::Error;

/// HTTP Request received from the `http_server:distro:sys` service as a
/// HTTP Request received from the `http-server:distro:sys` service as a
/// result of either an HTTP or WebSocket binding, created via [`HttpServerAction`].
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum HttpServerRequest {
Expand Down Expand Up @@ -144,7 +144,7 @@ pub enum WsMessageType {
Close,
}

/// Request type sent to `http_server:distro:sys` in order to configure it.
/// Request type sent to `http-server:distro:sys` in order to configure it.
///
/// If a response is expected, all actions will return a Response
/// with the shape `Result<(), HttpServerActionError>` serialized to JSON.
Expand Down Expand Up @@ -213,8 +213,8 @@ pub enum HttpServerAction {
desired_reply_type: MessageType,
},
/// For communicating with the ext.
/// Kinode's http_server sends this to the ext after receiving `WebSocketExtPushOutgoing`.
/// Upon receiving reply with this type from ext, http_server parses, setting:
/// Kinode's http-server sends this to the ext after receiving `WebSocketExtPushOutgoing`.
/// Upon receiving reply with this type from ext, http-server parses, setting:
/// * id as given,
/// * message type as given (Request or Response),
/// * body as HttpServerRequest::WebSocketPush,
Expand Down Expand Up @@ -268,7 +268,7 @@ impl HttpResponse {
}
}

/// Part of the Response type issued by http_server
/// Part of the Response type issued by http-server
#[derive(Clone, Debug, Error, Serialize, Deserialize)]
pub enum HttpServerError {
#[error("request could not be parsed to HttpServerAction: {req}.")]
Expand All @@ -279,11 +279,11 @@ pub enum HttpServerError {
PathBindError { error: String },
#[error("WebSocket error: {error}")]
WebSocketPushError { error: String },
/// Not actually issued by `http_server:distro:sys`, just this library
/// Not actually issued by `http-server:distro:sys`, just this library
#[error("timeout")]
Timeout,
/// Not actually issued by `http_server:distro:sys`, just this library
#[error("unexpected response from http_server")]
/// Not actually issued by `http-server:distro:sys`, just this library
#[error("unexpected response from http-server")]
UnexpectedResponse,
}

Expand All @@ -301,7 +301,7 @@ pub struct HttpServer {
ws_paths: HashMap<String, WsBindingConfig>,
/// A mapping of WebSocket paths to the channels that are open on them.
ws_channels: HashMap<String, HashSet<u32>>,
/// The timeout given for `http_server:distro:sys` to respond to a configuration request.
/// The timeout given for `http-server:distro:sys` to respond to a configuration request.
pub timeout: u64,
}

Expand Down Expand Up @@ -485,7 +485,7 @@ impl HttpServer {
{
let path: String = path.into();
let cache = config.static_content.is_some();
let req = KiRequest::to(("our", "http_server", "distro", "sys")).body(
let req = KiRequest::to(("our", "http-server", "distro", "sys")).body(
serde_json::to_vec(&if config.secure_subdomain {
HttpServerAction::SecureBind {
path: path.clone(),
Expand Down Expand Up @@ -529,7 +529,7 @@ impl HttpServer {
T: Into<String>,
{
let path: String = path.into();
let res = KiRequest::to(("our", "http_server", "distro", "sys"))
let res = KiRequest::to(("our", "http-server", "distro", "sys"))
.body(if config.secure_subdomain {
serde_json::to_vec(&HttpServerAction::WebSocketSecureBind {
path: path.clone(),
Expand Down Expand Up @@ -573,7 +573,7 @@ impl HttpServer {
T: Into<String>,
{
let path: String = path.into();
let res = KiRequest::to(("our", "http_server", "distro", "sys"))
let res = KiRequest::to(("our", "http-server", "distro", "sys"))
.body(
serde_json::to_vec(&HttpServerAction::Bind {
path: path.clone(),
Expand Down Expand Up @@ -624,7 +624,7 @@ impl HttpServer {
T: Into<String>,
{
let path: String = path.into();
let res = KiRequest::to(("our", "http_server", "distro", "sys"))
let res = KiRequest::to(("our", "http-server", "distro", "sys"))
.body(
serde_json::to_vec(&HttpServerAction::SecureBind {
path: path.clone(),
Expand Down Expand Up @@ -666,7 +666,7 @@ impl HttpServer {
T: Into<String>,
{
let path: String = path.into();
let res = KiRequest::to(("our", "http_server", "distro", "sys"))
let res = KiRequest::to(("our", "http-server", "distro", "sys"))
.body(
serde_json::to_vec(&HttpServerAction::WebSocketSecureBind {
path: path.clone(),
Expand Down Expand Up @@ -711,7 +711,7 @@ impl HttpServer {
.ok_or(HttpServerError::PathBindError {
error: "path not found".to_string(),
})?;
let res = KiRequest::to(("our", "http_server", "distro", "sys"))
let res = KiRequest::to(("our", "http-server", "distro", "sys"))
.body(
serde_json::to_vec(&HttpServerAction::Bind {
path: path.to_string(),
Expand Down Expand Up @@ -750,7 +750,7 @@ impl HttpServer {
.ok_or(HttpServerError::PathBindError {
error: "path not found".to_string(),
})?;
let res = KiRequest::to(("our", "http_server", "distro", "sys"))
let res = KiRequest::to(("our", "http-server", "distro", "sys"))
.body(if entry.secure_subdomain {
serde_json::to_vec(&HttpServerAction::WebSocketSecureBind {
path: path.to_string(),
Expand Down Expand Up @@ -790,7 +790,7 @@ impl HttpServer {
T: Into<String>,
{
let path: String = path.into();
let res = KiRequest::to(("our", "http_server", "distro", "sys"))
let res = KiRequest::to(("our", "http-server", "distro", "sys"))
.body(serde_json::to_vec(&HttpServerAction::Unbind { path: path.clone() }).unwrap())
.send_and_await_response(self.timeout)
.unwrap();
Expand All @@ -812,7 +812,7 @@ impl HttpServer {
T: Into<String>,
{
let path: String = path.into();
let res = KiRequest::to(("our", "http_server", "distro", "sys"))
let res = KiRequest::to(("our", "http-server", "distro", "sys"))
.body(
serde_json::to_vec(&HttpServerAction::WebSocketUnbind { path: path.clone() })
.unwrap(),
Expand Down Expand Up @@ -909,7 +909,7 @@ impl HttpServer {
}

/// Serve static files from a given directory by binding all of them
/// in http_server to their filesystem path.
/// in http-server to their filesystem path.
///
/// The directory is relative to the `pkg` folder within this package's drive.
///
Expand Down Expand Up @@ -1065,7 +1065,7 @@ pub fn send_response(status: StatusCode, headers: Option<HashMap<String, String>

/// Send a WebSocket push message on an open WebSocket channel.
pub fn send_ws_push(channel_id: u32, message_type: WsMessageType, blob: KiBlob) {
KiRequest::to(("our", "http_server", "distro", "sys"))
KiRequest::to(("our", "http-server", "distro", "sys"))
.body(
serde_json::to_vec(&HttpServerRequest::WebSocketPush {
channel_id,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub mod homepage;
/// Contains types from the `http` crate to use as well.
///
/// Your process must have the capability to message and receive messages from
/// `http_server:distro:sys` and/or `http_client:distro:sys` to use this module.
/// `http-server:distro:sys` and/or `http-client:distro:sys` to use this module.
pub mod http;
/// The types that the kernel itself uses -- warning -- these will
/// be incompatible with WIT types in some cases, leading to annoying errors.
Expand Down

0 comments on commit 1e6792d

Please sign in to comment.