Skip to content

Fast Date Generation for HTTP Header

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE.txt
MIT
LICENSE-MIT.txt
Notifications You must be signed in to change notification settings

errantmind/faf-http-date

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

faf-http-date (no_std)

Quickly (~20ns) generate a date for an HTTP header, formatted to be fully compliant with RFCs 822/1123/2616. This is used in the faf web server

This crate is simple, you pass a buffer to the provided function. The function populates the buffer with the date

  • Why use a buffer? It is faster.
  • Why pass a buffer instead of just having the date function return one? It is faster.
  • Why bytes instead of a string/str? It is faster and bytes are what you will write to the TCP socket, not a string. If you want a string, you can convert the buffer to a &str or String. See the examples below

This is a heavily optimized, stripped, and otherwise modified version of pyfisch/httpdate

Examples

// Format: b"Thu, 01 Jan 1970 00:00:00 GMT"

let mut buf = faf_http_date::get_date_buff_no_key();
faf_http_date::get_date_no_key(&mut buf);

// Optional, convert to str
let date_str = unsafe { std::str::from_utf8_unchecked(&buf[..]) };

Format: b"Date: Thu, 01 Jan 1970 00:00:00 GMT" (notice the 'Date: ' at the first)

let mut buf = faf_http_date::get_date_buff_with_key();
faf_http_date::get_date_with_key(&mut buf);

// Optional, convert to str
let date_str = unsafe { std::str::from_utf8_unchecked(&buf[..]) };

About

Fast Date Generation for HTTP Header

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE.txt
MIT
LICENSE-MIT.txt

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages