mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-24 08:01:38 +00:00
fix: allow no body in job requests (#4413)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use axum::{
|
||||
extract::{Path, Query},
|
||||
response::IntoResponse,
|
||||
routing::{any, delete, get, post},
|
||||
routing::{delete, get, post},
|
||||
Extension, Json, Router,
|
||||
};
|
||||
use http::{HeaderMap, StatusCode};
|
||||
@@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||
use sql_builder::{bind::Bind, SqlBuilder};
|
||||
use sqlx::prelude::FromRow;
|
||||
use std::collections::HashMap;
|
||||
use tower_http::cors::CorsLayer;
|
||||
use windmill_audit::{audit_ee::audit_log, ActionKind};
|
||||
use windmill_common::{
|
||||
auth::fetch_authed_from_permissioned_as,
|
||||
@@ -34,7 +35,27 @@ lazy_static::lazy_static! {
|
||||
}
|
||||
|
||||
pub fn routes_global_service() -> Router {
|
||||
Router::new().route("/*path", any(route_job))
|
||||
let cors = CorsLayer::new()
|
||||
.allow_methods([
|
||||
http::Method::GET,
|
||||
http::Method::POST,
|
||||
http::Method::DELETE,
|
||||
http::Method::PUT,
|
||||
http::Method::PATCH,
|
||||
])
|
||||
.allow_headers([http::header::CONTENT_TYPE, http::header::AUTHORIZATION])
|
||||
.allow_origin(tower_http::cors::Any);
|
||||
Router::new()
|
||||
.route(
|
||||
"/*path",
|
||||
get(route_job)
|
||||
.post(route_job)
|
||||
.delete(route_job)
|
||||
.put(route_job)
|
||||
.patch(route_job)
|
||||
.head(|| async { "" }),
|
||||
)
|
||||
.layer(cors)
|
||||
}
|
||||
|
||||
pub fn workspaced_service() -> Router {
|
||||
|
||||
@@ -350,9 +350,7 @@ pub async fn run_server(
|
||||
)
|
||||
.nest(
|
||||
"/r",
|
||||
http_triggers::routes_global_service()
|
||||
.layer(from_extractor::<OptAuthed>())
|
||||
.layer(cors),
|
||||
http_triggers::routes_global_service().layer(from_extractor::<OptAuthed>()),
|
||||
)
|
||||
.route("/version", get(git_v))
|
||||
.route("/uptodate", get(is_up_to_date))
|
||||
|
||||
@@ -2866,10 +2866,21 @@ where
|
||||
(content_type, extra, raw, wrap_body)
|
||||
};
|
||||
|
||||
if content_type.is_none() || content_type.unwrap().starts_with("application/json") {
|
||||
let no_content_type = content_type.is_none();
|
||||
if no_content_type || content_type.unwrap().starts_with("application/json") {
|
||||
let bytes = Bytes::from_request(req, _state)
|
||||
.await
|
||||
.map_err(IntoResponse::into_response)?;
|
||||
if no_content_type && bytes.is_empty() {
|
||||
if use_raw {
|
||||
extra.insert("raw_string".to_string(), to_raw_value(&"".to_string()));
|
||||
}
|
||||
let mut args = HashMap::new();
|
||||
if wrap_body {
|
||||
args.insert("body".to_string(), to_raw_value(&serde_json::json!({})));
|
||||
}
|
||||
return Ok(PushArgsOwned { extra: Some(extra), args: args });
|
||||
}
|
||||
let str = String::from_utf8(bytes.to_vec())
|
||||
.map_err(|e| Error::BadRequest(format!("invalid utf8: {}", e)).into_response())?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user