Skip to main content

write_challenge

Function write_challenge 

Source
pub fn write_challenge(
    scheme: &str,
    params: &[(&str, &str)],
    out: &mut impl Sink,
) -> Result<(), WriteError>
Expand description

Writes a challenge with parameters: Bearer realm="api", error="invalid_token". realm is always quoted (RFC 9110 section 11.5); other values are tokens when they can be.

§Errors

WriteError::NotToken for the scheme or a name; WriteError::DuplicateName for a name given twice (RFC 9110 section 11.2 allows each once); WriteError::Forbidden for a control byte in a value; WriteError::Full (nothing written when the sink reports its room).

§Examples

use parse_net::{auth, SliceSink};

let mut buf = [0u8; 64];
let mut out = SliceSink::new(&mut buf);
auth::write_challenge("Bearer", &[("realm", "api"), ("error", "invalid_token")], &mut out).expect("room");
assert_eq!(out.written(), b"Bearer realm=\"api\", error=invalid_token");