Skip to content

Commit

Permalink
Added fn-fdk-runtime header to response
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav Saini authored and metamemelord committed Aug 13, 2021
1 parent 7b7d5cd commit 101af42
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ repository = "https://github.com/fnproject/fdk-rust"
keywords = ["Fn", "serverless", "FaaS"]
categories = ["web-programming", "development-tools"]
license = "Apache-2.0"
build = "src/build.rs"

[badges]
maintenance = { status = "experimental" }

[dependencies]
hyper = { version = "0.14", features = ["full"] }
tokio = { version = "1.6", features = ["net"] }
tokio = { version = "~1.10", features = ["net"] }
futures = "0.3"
object-pool = "0.5"
lazy_static = "1"
Expand All @@ -27,3 +28,6 @@ serde_plain = "0.3"
serde_urlencoded = "0.7"
clap = "2"
thiserror = "1"

[build-dependencies]
built = "0.5.1"
4 changes: 2 additions & 2 deletions images/init/template/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use fdk::{Function, FunctionError, RuntimeContext};
use fdk::{Function, FunctionError, Result, RuntimeContext};
use tokio;

#[tokio::main]
async fn main() -> Result<(), FunctionError> {
async fn main() -> Result<()> {
if let Err(e) = Function::run(|_: &mut RuntimeContext, i: String| {
Ok(format!(
"Hello {}!",
Expand Down
3 changes: 3 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
built::write_built_file().expect("Failed to acquire build-time information");
}
18 changes: 18 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@ use hyper::{
header::{HeaderName, HeaderValue},
Body, HeaderMap, Response, StatusCode,
};
use lazy_static::lazy_static;
use std::str::FromStr;

pub mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

lazy_static! {
static ref COMPILER_VERSION: String = built_info::RUSTC_VERSION
.split_ascii_whitespace()
.skip(1)
.next()
.map(|s| s.to_owned())
.unwrap_or_else(|| String::from("UNKNOWN"));
}

pub fn make_header_map_with_single_value(key: HeaderName, value: HeaderValue) -> HeaderMap {
let mut header_map = HeaderMap::new();
header_map.insert(key, value);
Expand All @@ -19,6 +33,10 @@ fn generic_response(status: StatusCode, body: Option<Body>, headers: HeaderMap)
"Fn-Fdk-Version",
HeaderValue::from_str(&format!("fdk-rust/{}", crate_version!())).unwrap(),
);
headers.insert(
"Fn-Fdk-Runtime",
HeaderValue::from_str(&format!("rustc/{}", *COMPILER_VERSION)).unwrap(),
);
let resp_headers = builder.headers_mut().unwrap();
*resp_headers = headers;
}
Expand Down

0 comments on commit 101af42

Please sign in to comment.