|
68 | 68 | } |
69 | 69 | } |
70 | 70 |
|
71 | | -/// Converts an `http::Response<B>` into a streaming Lambda response. |
72 | | -fn into_stream_response<B>(res: Response<B>) -> StreamResponse<BodyStream<B>> |
73 | | -where |
74 | | - B: Body + Unpin + Send + 'static, |
75 | | - B::Data: Into<Bytes> + Send, |
76 | | - B::Error: Into<Error> + Send + Debug, |
77 | | -{ |
78 | | - let (parts, body) = res.into_parts(); |
79 | | - |
80 | | - let mut headers = parts.headers; |
81 | | - let cookies = headers |
82 | | - .get_all(SET_COOKIE) |
83 | | - .iter() |
84 | | - .map(|c| String::from_utf8_lossy(c.as_bytes()).to_string()) |
85 | | - .collect::<Vec<_>>(); |
86 | | - headers.remove(SET_COOKIE); |
87 | | - |
88 | | - StreamResponse { |
89 | | - metadata_prelude: MetadataPrelude { |
90 | | - headers, |
91 | | - status_code: parts.status, |
92 | | - cookies, |
93 | | - }, |
94 | | - stream: BodyStream { body }, |
95 | | - } |
96 | | -} |
97 | | - |
98 | 71 | /// Builds a streaming-aware Tower service from a `Service<Request>` **without** |
99 | 72 | /// boxing its future (no heap allocation / vtable). |
100 | 73 | /// |
@@ -127,6 +100,33 @@ where |
127 | 100 | .map_response(into_stream_response) |
128 | 101 | } |
129 | 102 |
|
| 103 | +/// Converts an `http::Response<B>` into a streaming Lambda response. |
| 104 | +fn into_stream_response<B>(res: Response<B>) -> StreamResponse<BodyStream<B>> |
| 105 | +where |
| 106 | + B: Body + Unpin + Send + 'static, |
| 107 | + B::Data: Into<Bytes> + Send, |
| 108 | + B::Error: Into<Error> + Send + Debug, |
| 109 | +{ |
| 110 | + let (parts, body) = res.into_parts(); |
| 111 | + |
| 112 | + let mut headers = parts.headers; |
| 113 | + let cookies = headers |
| 114 | + .get_all(SET_COOKIE) |
| 115 | + .iter() |
| 116 | + .map(|c| String::from_utf8_lossy(c.as_bytes()).to_string()) |
| 117 | + .collect::<Vec<_>>(); |
| 118 | + headers.remove(SET_COOKIE); |
| 119 | + |
| 120 | + StreamResponse { |
| 121 | + metadata_prelude: MetadataPrelude { |
| 122 | + headers, |
| 123 | + status_code: parts.status, |
| 124 | + cookies, |
| 125 | + }, |
| 126 | + stream: BodyStream { body }, |
| 127 | + } |
| 128 | +} |
| 129 | + |
130 | 130 | /// Runs the Lambda runtime with a handler that returns **streaming** HTTP |
131 | 131 | /// responses. |
132 | 132 | /// |
|
0 commit comments