Skip to content

Commit

Permalink
Add inject_raw_with_peer_addr (#189)
Browse files Browse the repository at this point in the history
If a peer address is available, this function is useful to inject it
along te raw request.
  • Loading branch information
CBenoit authored Jan 18, 2022
1 parent de6e52a commit e403596
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion saphir/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,11 @@ mod ssl_loading_utils {

/// Inject a http request into saphir
pub async fn inject_raw(req: RawRequest<RawBody>) -> Result<RawResponse<RawBody>, SaphirError> {
inject_raw_with_peer_addr(req, None).await
}

/// Inject a http request into saphir
pub async fn inject_raw_with_peer_addr(req: RawRequest<RawBody>, peer_addr: Option<SocketAddr>) -> Result<RawResponse<RawBody>, SaphirError> {
if INIT_STACK.state() != OnceState::Done {
return Err(SaphirError::Other("Stack is not initialized".to_owned()));
}
Expand All @@ -933,7 +938,7 @@ pub async fn inject_raw(req: RawRequest<RawBody>) -> Result<RawResponse<RawBody>
// We checked that memory has been initialized above
let stack = unsafe { STACK.as_ptr().as_ref().expect("Memory has been initialized above.") };

let saphir_req = Request::new(req.map(Body::from_raw), None);
let saphir_req = Request::new(req.map(Body::from_raw), peer_addr);
REQUEST_FUTURE_COUNT.fetch_add(1, Ordering::SeqCst);
let saphir_res = stack.invoke(saphir_req).await?;
Ok(saphir_res.into_raw().map(|r| r.map(|b| b.into_raw()))?)
Expand Down

0 comments on commit e403596

Please sign in to comment.