Public Member Functions | List of all members
BHttpFormData Class Reference

Stores a form data entry sent or received during an HTTP request. More...

Public Member Functions

 BHttpFormData (const BString &name, const BString &value)
 Construct a BHttpFormData object with a string value.
 
 BHttpFormData (const BString &name, const BPath &file)
 Construct a BHttpFormData object which value is a file contents.
 
 BHttpFormData (const BString &name, const void *buffer, ssize_t size)
 Construct a BHttpFormData object which value is a binary buffer.
 
const void * Buffer () const
 Get a pointer to the data of a form field. More...
 
ssize_t BufferSize () const
 Get the buffer size. More...
 
status_t CopyBuffer ()
 Make a copy of the internal buffer. More...
 
const BPathFile () const
 Get the file path of a form field. More...
 
const BStringFilename () const
 
bool InitCheck () const
 Checks the initialization of the object. More...
 
bool IsFile () const
 
status_t MarkAsFile (const BString &filename, const BString &mimeType="")
 Mark a field as a file.
 
const BStringMimeType () const
 
const BStringName () const
 Get the form field name.
 
BHttpFormDataoperator= (const BHttpFormData &other)
 Assignment operator.
 
const BStringString () const
 Get the string value of a form field. More...
 
form_content_type Type () const
 
void UnmarkAsFile ()
 Unmark a field as a file.
 

Detailed Description

Stores a form data entry sent or received during an HTTP request.

Each element in a form is stored in an instance of this class. The values can be either strings, arbitrary binary buffers, or a pointer to a file.

The latter allows reading data from the file as it is being sent through the network, removing hte need to buffer the whole file contents in memory.

Member Function Documentation

const void * BHttpFormData::Buffer ( ) const

Get a pointer to the data of a form field.

Returns
An empty string for string and file based fields
ssize_t BHttpFormData::BufferSize ( ) const

Get the buffer size.

Returns
0 for string and file based fields.
status_t BHttpFormData::CopyBuffer ( )

Make a copy of the internal buffer.

The constructor for buffer-based fields does not copy the data given to it, it just keeps a pointer. If you want to retain ownership of the data, call this method so the buffer copies and releases it.

const BPath & BHttpFormData::File ( ) const

Get the file path of a form field.

Returns
An empty string for buffer and string based fields.
const BString & BHttpFormData::Filename ( ) const
Returns
The name of the file, for file based fields.
bool BHttpFormData::InitCheck ( ) const

Checks the initialization of the object.

Returns
false if attempting to construct a BHttpFormData with a NULL buffer.
bool BHttpFormData::IsFile ( ) const
Returns
true if the field data is a file.
const BString & BHttpFormData::MimeType ( ) const
Returns
The MIME type of the data.
const BString & BHttpFormData::String ( ) const

Get the string value of a form field.

Returns
An empty string for buffer and file based fields.
form_content_type BHttpFormData::Type ( ) const
Returns
The kind of field.