pub struct TokenField { /* private fields */ }Expand description
The anti-forgery token field to capture from a multipart body.
§Examples
use form_net::{TokenField, TokenPlacement};
let strict = TokenField::new("csrf_token");
assert_eq!(strict.placement(), TokenPlacement::BeforeFirstFile);
assert_eq!(strict.anywhere().placement(), TokenPlacement::Anywhere);Implementations§
Source§impl TokenField
impl TokenField
Sourcepub const fn new(name: &'static str) -> TokenField
pub const fn new(name: &'static str) -> TokenField
A token field named name that must come before the first file.
§Examples
use form_net::{TokenField, TokenPlacement};
const TOKEN: TokenField = TokenField::new("csrf_token");
assert_eq!(TOKEN.name(), "csrf_token");
assert_eq!(TOKEN.placement(), TokenPlacement::BeforeFirstFile);Sourcepub const fn anywhere(self) -> TokenField
pub const fn anywhere(self) -> TokenField
The same field, allowed anywhere in the body.
§Examples
use form_net::{Limits, Policy, TokenField};
let relaxed = Policy::DEFAULT.with_token_field(TokenField::new("csrf").anywhere());
let body = b"--X\r\nContent-Disposition: form-data; name=f; filename=a.txt\r\n\r\nhi\r\n\
--X\r\nContent-Disposition: form-data; name=csrf\r\n\r\nt0k\r\n--X--";
let form = form_net::parse_multipart_with(CT, body, &Limits::DEFAULT, &relaxed)?;
assert_eq!(form.field("csrf"), Some("t0k"));Sourcepub const fn name(&self) -> &'static str
pub const fn name(&self) -> &'static str
The field name, matched byte for byte.
§Examples
let field = form_net::TokenField::new("csrf").anywhere();
assert_eq!(field.name(), "csrf");Sourcepub const fn placement(&self) -> TokenPlacement
pub const fn placement(&self) -> TokenPlacement
Where the field must be.
§Examples
use form_net::{TokenField, TokenPlacement};
assert_eq!(TokenField::new("t").placement(), TokenPlacement::BeforeFirstFile);
assert_eq!(TokenField::new("t").anywhere().placement(), TokenPlacement::Anywhere);Trait Implementations§
Source§impl Clone for TokenField
impl Clone for TokenField
impl Copy for TokenField
Source§impl Debug for TokenField
impl Debug for TokenField
impl Eq for TokenField
Source§impl PartialEq for TokenField
impl PartialEq for TokenField
impl StructuralPartialEq for TokenField
Auto Trait Implementations§
impl Forget for TokenField
impl Freeze for TokenField
impl Move for TokenField
impl RefUnwindSafe for TokenField
impl Send for TokenField
impl Sync for TokenField
impl Unpin for TokenField
impl UnsafeUnpin for TokenField
impl UnwindSafe for TokenField
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more