Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions
HttpTime.h File Reference

Provides tools to parse and format HTTP dates. More...

Classes

class  BPrivate::Network::BHttpTime
 Utility class that can parse and format HTTP Date strings. More...
 
class  BPrivate::Network::BHttpTime::InvalidInput
 Error that indicates that a string cannot be parsed as a valid HTTP timestamp. More...
 

Namespaces

namespace  BPrivate
 Internal or experimental API.
 
namespace  BPrivate::Network
 Experimental Network Services API.
 

Enumerations

enum class  BPrivate::Network::BHttpTimeFormat : int8
 Describes the three time formats supported by the HTTP RFC.
 

Functions

BString BPrivate::Network::format_http_time (BDateTime timestamp, BHttpTimeFormat outputFormat=BHttpTimeFormat::RFC1123)
 Format the timestamp into a string according to the outputFormat.
 
BDateTime BPrivate::Network::parse_http_time (const BString &string)
 Parse a string that contains a timestamp and return a BDateTime object.
 

Detailed Description

Provides tools to parse and format HTTP dates.

The HTTP protocols prescribe that each HTTP response should have a Date header field with a timestamp the response was generated. Optionally, there are other fields that may have a timestamp in them, such as Set-Cookie or If-Modified-Since.

According to section 3.3 of RFC 2616, the standard date format is the format described by RFC 1123, which updates the previous RFC 822. However, a proper implementation of a HTTP parser may also want to support the RFC 850 format (which was obsoleted by RFC 1036) and the old C-library standard date formatting of asctime().

Examples:

RFC1123 / RFC822Sun, 06 Nov 1994 08:49:37 GMT
RFC850Sunday, 06-Nov-94 08:49:37 GMT
asctimeSun Nov 6 08:49:37 1994

The tools in this module will make it easer to parse and format dates according to those standards. When parsing the

You can use parse_http_time() to parse a string that contains a HTTP timestamp. You can use format_http_time() to format the HTTP time according to the prescribed format. If you want slightly more information about parsing, or if you want to hold an intermediate representation of the timestamp, have a look at the BPrivate::Network::BHttpTime class.

Note that when parsing a timestamp string, the tools are slightly more permissive than the standards. For example, if the RFC 1123 timestamp does not have the GMT timezone indicator at the end, it will still be accepted. Likewise, there is support for RFC 850 timestamps with a 4-digit year format. When formatting a BPrivate::BDateTime to a string, it will always use prescribed representation.

Since
Haiku R1