Skip to content

Commit

Permalink
Merge pull request #1228 from AmbientRun/prevail-changes
Browse files Browse the repository at this point in the history
HTTP POST support + misc changes
  • Loading branch information
philpax authored Dec 18, 2023
2 parents c8d4d3e + 47f002e commit fd058ac
Show file tree
Hide file tree
Showing 17 changed files with 749 additions and 390 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ These PRs are not directly user-facing, but improve the development experience.

#### Other

- `http::post` has been added to the server API to make it possible to make POST requests. It accepts optional `headers` and `body` arguments.

### Changed

#### Breaking
Expand All @@ -54,6 +56,8 @@ These PRs are not directly user-facing, but improve the development experience.
}
```
- Ambient will no longer update the `deployment` field of dependencies; instead, it will insert the version of that dependency, and that version is not automatically updated. The new `--version` argument can be used to update the versions of every package in your dependency tree: `ambient deploy --version 0.3`.
- `http::get` now accepts optional `headers`. To update your code, set `None` for the second argument.
- File I/O and the `http` APIs are now disabled when used on a hosted environment (i.e. Ambient deployments). To test if your logic still works in a hosted environment, run Ambient with the `AMBIENT_HOSTED` environment variable set to anything (e.g. `AMBIENT_HOSTED=1 ambient run`).

#### Non-breaking

Expand Down
3 changes: 2 additions & 1 deletion app/src/server/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ pub async fn initialize(
},
);

ambient_wasm::server::initialize(world, assets, data_path, messenger)?;
let hosted = std::env::var("AMBIENT_HOSTED").is_ok();
ambient_wasm::server::initialize(world, assets, hosted, data_path, messenger)?;

Ok(())
}
Expand Down
58 changes: 53 additions & 5 deletions crates/ecs/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1455,21 +1455,21 @@ mod raw {
#[derive(Clone, Debug)]
#[doc = "**HttpResponse**: Sent when an HTTP response is received."]
pub struct HttpResponse {
pub url: String,
pub response_id: u64,
pub status: u32,
pub body: Vec<u8>,
pub error: Option<String>,
}
impl HttpResponse {
#[allow(clippy::too_many_arguments)]
pub fn new(
url: impl Into<String>,
response_id: impl Into<u64>,
status: impl Into<u32>,
body: impl Into<Vec<u8>>,
error: impl Into<Option<String>>,
) -> Self {
Self {
url: url.into(),
response_id: response_id.into(),
status: status.into(),
body: body.into(),
error: error.into(),
Expand All @@ -1482,15 +1482,15 @@ mod raw {
}
fn serialize_message(&self) -> Result<Vec<u8>, MessageSerdeError> {
let mut output = vec![];
self.url.serialize_message_part(&mut output)?;
self.response_id.serialize_message_part(&mut output)?;
self.status.serialize_message_part(&mut output)?;
self.body.serialize_message_part(&mut output)?;
self.error.serialize_message_part(&mut output)?;
Ok(output)
}
fn deserialize_message(mut input: &[u8]) -> Result<Self, MessageSerdeError> {
Ok(Self {
url: String::deserialize_message_part(&mut input)?,
response_id: u64::deserialize_message_part(&mut input)?,
status: u32::deserialize_message_part(&mut input)?,
body: Vec::<u8>::deserialize_message_part(&mut input)?,
error: Option::<String>::deserialize_message_part(&mut input)?,
Expand Down Expand Up @@ -1528,6 +1528,54 @@ mod raw {
}
impl RuntimeMessage for WasmRebuild {}
}
#[doc = r" Auto-generated type definitions."]
pub mod types {
use ambient_package_rt::message_serde::*;
use serde;
#[derive(
Copy, Clone, Debug, PartialEq, Eq, serde :: Serialize, serde :: Deserialize, Default,
)]
#[serde(crate = "self::serde")]
#[doc = "**HttpMethod**: The HTTP method."]
pub enum HttpMethod {
#[default]
#[doc = "GET"]
Get,
#[doc = "POST"]
Post,
}
impl crate::EnumComponent for HttpMethod {
fn to_u32(&self) -> u32 {
match self {
Self::Get => HttpMethod::Get as u32,
Self::Post => HttpMethod::Post as u32,
}
}
fn from_u32(value: u32) -> Option<Self> {
if value == HttpMethod::Get as u32 {
return Some(Self::Get);
}
if value == HttpMethod::Post as u32 {
return Some(Self::Post);
}
None
}
}
impl MessageSerde for HttpMethod {
fn serialize_message_part(
&self,
output: &mut Vec<u8>,
) -> Result<(), MessageSerdeError> {
crate::EnumComponent::to_u32(self).serialize_message_part(output)
}
fn deserialize_message_part(
input: &mut dyn std::io::Read,
) -> Result<Self, MessageSerdeError> {
crate::EnumComponent::from_u32(u32::deserialize_message_part(input)?)
.ok_or(MessageSerdeError::InvalidValue)
}
}
}
pub fn init() {
crate::generated::raw::ambient_core::animation::components::init_components();
crate::generated::raw::ambient_core::app::components::init_components();
Expand Down
Loading

0 comments on commit fd058ac

Please sign in to comment.