mirror of
https://github.com/mikedilger/chorus.git
synced 2026-05-03 06:51:42 +00:00
Try to better support pre-flight checks
This commit is contained in:
parent
85859502f4
commit
ef33cf0828
@ -15,6 +15,8 @@ pub async fn serve_http(
|
|||||||
peer: HashedPeer,
|
peer: HashedPeer,
|
||||||
request: Request<Incoming>,
|
request: Request<Incoming>,
|
||||||
) -> Result<Response<BoxBody<Bytes, Error>>, Error> {
|
) -> Result<Response<BoxBody<Bytes, Error>>, Error> {
|
||||||
|
let method = request.method().clone();
|
||||||
|
|
||||||
// Handle server-wide OPTIONS requests
|
// Handle server-wide OPTIONS requests
|
||||||
let p = request.uri().path();
|
let p = request.uri().path();
|
||||||
if p == "*" && request.method() == Method::OPTIONS {
|
if p == "*" && request.method() == Method::OPTIONS {
|
||||||
@ -59,15 +61,37 @@ pub async fn serve_http(
|
|||||||
|
|
||||||
log::debug!(target: "Client", "{}: HTTP request for {}", peer, uri);
|
log::debug!(target: "Client", "{}: HTTP request for {}", peer, uri);
|
||||||
|
|
||||||
let response = Response::builder()
|
let response = match method {
|
||||||
.header("Access-Control-Allow-Origin", "*")
|
Method::OPTIONS => Response::builder()
|
||||||
.header("Access-Control-Allow-Headers", "*")
|
.header("Access-Control-Allow-Origin", "*")
|
||||||
.header("Access-Control-Allow-Methods", "*")
|
.header("Access-Control-Allow-Headers", "*")
|
||||||
.status(StatusCode::OK)
|
.header("Access-Control-Allow-Methods", "*")
|
||||||
.body(
|
.header("Allow", "OPTIONS, GET, HEAD, PUT, DELETE")
|
||||||
Full::new("This is a nostr relay. Please use a nostr client to connect.".into())
|
.status(StatusCode::NO_CONTENT)
|
||||||
.map_err(|e| e.into())
|
.body(Empty::new().map_err(|e| e.into()).boxed())?,
|
||||||
.boxed(),
|
Method::HEAD => Response::builder()
|
||||||
)?;
|
.header("Access-Control-Allow-Origin", "*")
|
||||||
|
.header("Access-Control-Allow-Headers", "*")
|
||||||
|
.header("Access-Control-Allow-Methods", "*")
|
||||||
|
.status(StatusCode::OK)
|
||||||
|
.body(Empty::new().map_err(|e| e.into()).boxed())?,
|
||||||
|
Method::GET => Response::builder()
|
||||||
|
.header("Access-Control-Allow-Origin", "*")
|
||||||
|
.header("Access-Control-Allow-Headers", "*")
|
||||||
|
.header("Access-Control-Allow-Methods", "*")
|
||||||
|
.status(StatusCode::OK)
|
||||||
|
.body(
|
||||||
|
Full::new("This is a nostr relay. Please use a nostr client to connect.".into())
|
||||||
|
.map_err(|e| e.into())
|
||||||
|
.boxed(),
|
||||||
|
)?,
|
||||||
|
_ => Response::builder()
|
||||||
|
.header("Access-Control-Allow-Origin", "*")
|
||||||
|
.header("Access-Control-Allow-Headers", "*")
|
||||||
|
.header("Access-Control-Allow-Methods", "*")
|
||||||
|
.status(StatusCode::METHOD_NOT_ALLOWED)
|
||||||
|
.body(Empty::new().map_err(|e| e.into()).boxed())?,
|
||||||
|
};
|
||||||
|
|
||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user