MCPcopy Index your code
hub / github.com/aws/aws-lambda-rust-runtime / from_response

Method from_response

lambda-http/src/response.rs:64–200  ·  view source on GitHub ↗
(request_origin: &RequestOrigin, value: Response<Body>)

Source from the content-addressed store, hash-verified

62/// Transformation from http type to internal type
63impl LambdaResponse {
64 pub(crate) fn from_response(request_origin: &RequestOrigin, value: Response<Body>) -> Self {
65 let (parts, bod) = value.into_parts();
66 let (is_base64_encoded, body) = match bod {
67 Body::Empty => (false, None),
68 b @ Body::Text(_) => (false, Some(b)),
69 b @ Body::Binary(_) => (true, Some(b)),
70 _ => (false, None),
71 };
72
73 let headers = parts.headers;
74 let status_code = parts.status.as_u16();
75
76 match request_origin {
77 #[cfg(feature = "apigw_rest")]
78 RequestOrigin::ApiGatewayV1 => LambdaResponse::ApiGatewayV1({
79 let mut response = ApiGatewayProxyResponse::default();
80
81 response.body = body;
82 response.is_base64_encoded = is_base64_encoded;
83 response.status_code = status_code as i64;
84 // Explicitly empty, as API gateway v1 will merge "headers" and
85 // "multi_value_headers" fields together resulting in duplicate response headers.
86 response.headers = HeaderMap::new();
87 response.multi_value_headers = headers;
88 // Today, this implementation doesn't provide any additional fields
89 #[cfg(feature = "catch-all-fields")]
90 {
91 response.other = Default::default();
92 }
93 response
94 }),
95 #[cfg(feature = "apigw_http")]
96 RequestOrigin::ApiGatewayV2 => {
97 use http::header::SET_COOKIE;
98 let mut headers = headers;
99 // ApiGatewayV2 expects the set-cookies headers to be in the "cookies" attribute,
100 // so remove them from the headers.
101 let cookies = headers
102 .get_all(SET_COOKIE)
103 .iter()
104 .map(|v| v.to_str().ok().unwrap_or_default().to_string())
105 .collect();
106 headers.remove(SET_COOKIE);
107
108 LambdaResponse::ApiGatewayV2({
109 let mut response = ApiGatewayV2httpResponse::default();
110 response.body = body;
111 response.is_base64_encoded = is_base64_encoded;
112 response.status_code = status_code as i64;
113 response.cookies = cookies;
114 // API gateway v2 doesn't have "multi_value_headers" field. Duplicate headers
115 // are combined with commas and included in the headers field.
116 response.headers = headers;
117 response.multi_value_headers = HeaderMap::new();
118 // Today, this implementation doesn't provide any additional fields
119 #[cfg(feature = "catch-all-fields")]
120 {
121 response.other = Default::default();

Callers

nothing calls this directly

Calls 4

into_partsMethod · 0.80
collectMethod · 0.80
from_strFunction · 0.70
cloneMethod · 0.45

Tested by

no test coverage detected