Skip to content

Commit 0fc0439

Browse files
Gaurav Sainimetamemelord
authored andcommitted
Added fn-fdk-runtime header to response
1 parent 7b7d5cd commit 0fc0439

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ repository = "https://github.com/fnproject/fdk-rust"
88
keywords = ["Fn", "serverless", "FaaS"]
99
categories = ["web-programming", "development-tools"]
1010
license = "Apache-2.0"
11+
build = "src/build.rs"
1112

1213
[badges]
1314
maintenance = { status = "experimental" }
1415

1516
[dependencies]
1617
hyper = { version = "0.14", features = ["full"] }
17-
tokio = { version = "1.6", features = ["net"] }
18+
tokio = { version = "1.8", features = ["net"] }
1819
futures = "0.3"
1920
object-pool = "0.5"
2021
lazy_static = "1"
@@ -27,3 +28,6 @@ serde_plain = "0.3"
2728
serde_urlencoded = "0.7"
2829
clap = "2"
2930
thiserror = "1"
31+
32+
[build-dependencies]
33+
built = "0.5.1"

images/init/template/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use fdk::{Function, FunctionError, RuntimeContext};
1+
use fdk::{Function, FunctionError, Result, RuntimeContext};
22
use tokio;
33

44
#[tokio::main]
5-
async fn main() -> Result<(), FunctionError> {
5+
async fn main() -> Result<()> {
66
if let Err(e) = Function::run(|_: &mut RuntimeContext, i: String| {
77
Ok(format!(
88
"Hello {}!",

src/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
built::write_built_file().expect("Failed to acquire build-time information");
3+
}

src/utils.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,22 @@ use hyper::{
33
header::{HeaderName, HeaderValue},
44
Body, HeaderMap, Response, StatusCode,
55
};
6+
use lazy_static::lazy_static;
67
use std::str::FromStr;
78

9+
pub mod built_info {
10+
include!(concat!(env!("OUT_DIR"), "/built.rs"));
11+
}
12+
13+
lazy_static! {
14+
static ref COMPILER_VERSION: String = built_info::RUSTC_VERSION
15+
.split_ascii_whitespace()
16+
.skip(1)
17+
.next()
18+
.map(|s| s.to_owned())
19+
.unwrap_or_else(|| String::from("UNKNOWN"));
20+
}
21+
822
pub fn make_header_map_with_single_value(key: HeaderName, value: HeaderValue) -> HeaderMap {
923
let mut header_map = HeaderMap::new();
1024
header_map.insert(key, value);
@@ -19,6 +33,10 @@ fn generic_response(status: StatusCode, body: Option<Body>, headers: HeaderMap)
1933
"Fn-Fdk-Version",
2034
HeaderValue::from_str(&format!("fdk-rust/{}", crate_version!())).unwrap(),
2135
);
36+
headers.insert(
37+
"Fn-Fdk-Runtime",
38+
HeaderValue::from_str(&format!("rustc/{}", *COMPILER_VERSION)).unwrap(),
39+
);
2240
let resp_headers = builder.headers_mut().unwrap();
2341
*resp_headers = headers;
2442
}

0 commit comments

Comments
 (0)