mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 23:07:18 +03:00
gotham_ext: lfs_server: move ServerIdentityMiddleware from lfs_server to gotham_ext
Summary: Move the generally-useful ServerIdentityMiddleware into gotham_ext so we can use it in the EdenAPI server. Reviewed By: xavierd Differential Revision: D19845282 fbshipit-source-id: 3a01b15dc64cee99cefafcdac229c0b70a4db683
This commit is contained in:
parent
a4b83e384a
commit
4ac91b4fa9
@ -5,9 +5,14 @@
|
||||
* GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
use std::panic::RefUnwindSafe;
|
||||
|
||||
use gotham::state::State;
|
||||
use hyper::{Body, Response};
|
||||
use std::panic::RefUnwindSafe;
|
||||
|
||||
pub mod server_identity;
|
||||
|
||||
pub use server_identity::ServerIdentityMiddleware;
|
||||
|
||||
pub trait Middleware: 'static + RefUnwindSafe + Send + Sync {
|
||||
fn inbound(&self, _state: &mut State) {
|
||||
|
@ -5,13 +5,14 @@
|
||||
* GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
|
||||
use anyhow::Error;
|
||||
use gotham::helpers::http::header::X_REQUEST_ID;
|
||||
use gotham::state::{request_id, State};
|
||||
use hyper::header::HeaderValue;
|
||||
use hyper::{Body, Response};
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
|
||||
use super::Middleware;
|
||||
|
||||
@ -20,10 +21,10 @@ pub struct ServerIdentityMiddleware {
|
||||
}
|
||||
|
||||
impl ServerIdentityMiddleware {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(server_name: HeaderValue) -> Self {
|
||||
let mut headers = HashMap::new();
|
||||
|
||||
headers.insert("Server", HeaderValue::from_static("mononoke-lfs"));
|
||||
headers.insert("Server", server_name);
|
||||
|
||||
// NOTE: We ignore errors here — those will happen if environment variables are missing,
|
||||
// which is fine.
|
@ -26,6 +26,7 @@ use futures_preview::{
|
||||
use futures_util::try_join;
|
||||
use gotham::{bind_server, bind_server_with_pre_state};
|
||||
use gotham_ext::handler::MononokeHttpHandler;
|
||||
use hyper::header::HeaderValue;
|
||||
use slog::{error, info, warn};
|
||||
use std::collections::HashMap;
|
||||
use std::net::ToSocketAddrs;
|
||||
@ -347,7 +348,9 @@ fn main(fb: FacebookInit) -> Result<(), Error> {
|
||||
))
|
||||
.add(LoadMiddleware::new())
|
||||
.add(log_middleware)
|
||||
.add(ServerIdentityMiddleware::new())
|
||||
.add(ServerIdentityMiddleware::new(HeaderValue::from_static(
|
||||
"mononoke-lfs",
|
||||
)))
|
||||
.add(ScubaMiddleware::new(scuba_logger))
|
||||
.add(OdsMiddleware::new())
|
||||
.add(TimerMiddleware::new())
|
||||
|
@ -11,11 +11,10 @@ mod log;
|
||||
mod ods;
|
||||
mod request_context;
|
||||
mod scuba;
|
||||
mod server_identity;
|
||||
mod timer;
|
||||
mod tls_session_data;
|
||||
|
||||
pub use gotham_ext::middleware::Middleware;
|
||||
pub use gotham_ext::middleware::{Middleware, ServerIdentityMiddleware};
|
||||
|
||||
pub use self::client_identity::{ClientIdentity, ClientIdentityMiddleware};
|
||||
pub use self::load::{LoadMiddleware, RequestLoad};
|
||||
@ -23,6 +22,5 @@ pub use self::log::LogMiddleware;
|
||||
pub use self::ods::OdsMiddleware;
|
||||
pub use self::request_context::{LfsMethod, RequestContext, RequestContextMiddleware};
|
||||
pub use self::scuba::{ScubaKey, ScubaMiddleware, ScubaMiddlewareState};
|
||||
pub use self::server_identity::ServerIdentityMiddleware;
|
||||
pub use self::timer::TimerMiddleware;
|
||||
pub use self::tls_session_data::TlsSessionDataMiddleware;
|
||||
|
Loading…
Reference in New Issue
Block a user