Use Accept header instead of Content-Type header for client content negotiation

This commit is contained in:
Tobie Morgan Hitchcock 2022-09-16 02:18:28 +01:00
parent b2f4101a9c
commit 8403238dbb
4 changed files with 12 additions and 12 deletions

View file

@ -1,7 +1,7 @@
use crate::err::Error; use crate::err::Error;
use reqwest::blocking::Client; use reqwest::blocking::Client;
use reqwest::blocking::Response; use reqwest::blocking::Response;
use reqwest::header::CONTENT_TYPE; use reqwest::header::ACCEPT;
use rustyline::error::ReadlineError; use rustyline::error::ReadlineError;
use rustyline::Editor; use rustyline::Editor;
use serde_json::Value; use serde_json::Value;
@ -41,7 +41,7 @@ pub fn init(matches: &clap::ArgMatches) -> Result<(), Error> {
// Make a new remote request // Make a new remote request
let res = Client::new() let res = Client::new()
.post(&conn) .post(&conn)
.header(CONTENT_TYPE, "application/json") .header(ACCEPT, "application/json")
.basic_auth(user, Some(pass)); .basic_auth(user, Some(pass));
// Add NS header if specified // Add NS header if specified
let res = match ns { let res = match ns {

View file

@ -15,7 +15,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
.and(warp::path::end()) .and(warp::path::end())
.and(warp::post()) .and(warp::post())
.and(session::build()) .and(session::build())
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str())) .and(warp::header::<String>(http::header::ACCEPT.as_str()))
.and(warp::body::content_length_limit(MAX)) .and(warp::body::content_length_limit(MAX))
.and(warp::body::bytes()) .and(warp::body::bytes())
.and_then(handler) .and_then(handler)

View file

@ -36,7 +36,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
let select = warp::any() let select = warp::any()
.and(warp::get()) .and(warp::get())
.and(session::build()) .and(session::build())
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str())) .and(warp::header::<String>(http::header::ACCEPT.as_str()))
.and(path!("key" / String).and(warp::path::end())) .and(path!("key" / String).and(warp::path::end()))
.and(warp::query()) .and(warp::query())
.and_then(select_all); .and_then(select_all);
@ -44,7 +44,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
let create = warp::any() let create = warp::any()
.and(warp::post()) .and(warp::post())
.and(session::build()) .and(session::build())
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str())) .and(warp::header::<String>(http::header::ACCEPT.as_str()))
.and(path!("key" / String).and(warp::path::end())) .and(path!("key" / String).and(warp::path::end()))
.and(warp::body::content_length_limit(MAX)) .and(warp::body::content_length_limit(MAX))
.and(warp::body::bytes()) .and(warp::body::bytes())
@ -53,7 +53,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
let delete = warp::any() let delete = warp::any()
.and(warp::delete()) .and(warp::delete())
.and(session::build()) .and(session::build())
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str())) .and(warp::header::<String>(http::header::ACCEPT.as_str()))
.and(path!("key" / String).and(warp::path::end())) .and(path!("key" / String).and(warp::path::end()))
.and_then(delete_all); .and_then(delete_all);
// Specify route // Specify route
@ -67,14 +67,14 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
let select = warp::any() let select = warp::any()
.and(warp::get()) .and(warp::get())
.and(session::build()) .and(session::build())
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str())) .and(warp::header::<String>(http::header::ACCEPT.as_str()))
.and(path!("key" / String / String).and(warp::path::end())) .and(path!("key" / String / String).and(warp::path::end()))
.and_then(select_one); .and_then(select_one);
// Set create method // Set create method
let create = warp::any() let create = warp::any()
.and(warp::post()) .and(warp::post())
.and(session::build()) .and(session::build())
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str())) .and(warp::header::<String>(http::header::ACCEPT.as_str()))
.and(path!("key" / String / String).and(warp::path::end())) .and(path!("key" / String / String).and(warp::path::end()))
.and(warp::body::content_length_limit(MAX)) .and(warp::body::content_length_limit(MAX))
.and(warp::body::bytes()) .and(warp::body::bytes())
@ -83,7 +83,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
let update = warp::any() let update = warp::any()
.and(warp::put()) .and(warp::put())
.and(session::build()) .and(session::build())
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str())) .and(warp::header::<String>(http::header::ACCEPT.as_str()))
.and(path!("key" / String / String).and(warp::path::end())) .and(path!("key" / String / String).and(warp::path::end()))
.and(warp::body::content_length_limit(MAX)) .and(warp::body::content_length_limit(MAX))
.and(warp::body::bytes()) .and(warp::body::bytes())
@ -92,7 +92,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
let modify = warp::any() let modify = warp::any()
.and(warp::patch()) .and(warp::patch())
.and(session::build()) .and(session::build())
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str())) .and(warp::header::<String>(http::header::ACCEPT.as_str()))
.and(path!("key" / String / String).and(warp::path::end())) .and(path!("key" / String / String).and(warp::path::end()))
.and(warp::body::content_length_limit(MAX)) .and(warp::body::content_length_limit(MAX))
.and(warp::body::bytes()) .and(warp::body::bytes())
@ -101,7 +101,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
let delete = warp::any() let delete = warp::any()
.and(warp::delete()) .and(warp::delete())
.and(session::build()) .and(session::build())
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str())) .and(warp::header::<String>(http::header::ACCEPT.as_str()))
.and(path!("key" / String / String).and(warp::path::end())) .and(path!("key" / String / String).and(warp::path::end()))
.and_then(delete_one); .and_then(delete_one);
// Specify route // Specify route

View file

@ -20,7 +20,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
let post = base let post = base
.and(warp::post()) .and(warp::post())
.and(session::build()) .and(session::build())
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str())) .and(warp::header::<String>(http::header::ACCEPT.as_str()))
.and(warp::body::content_length_limit(MAX)) .and(warp::body::content_length_limit(MAX))
.and(warp::body::bytes()) .and(warp::body::bytes())
.and_then(handler); .and_then(handler);