f9e1854f19
The asynchronous listener had no reliable way to access HTTP result and headers from the callbacks. As the callbacks are triggered asynchronously, they can be run after the request has carried on and, for example, followed an HTTP redirect, clearing its internal state. The HeadersReceived callback now passes a reference to BUrlResult for the request. There are two cases: - Synchronous listener: passes a reference to the request's results directly - Asynchronous listener: archives a copy of the result into the notification message, and passes a reference to the unarchived copy. Unfortunately this comes with several ABI and API breakages: - Change to the prototype of HeadersReceived() - Change to the class hierarchy of BUrlResult (implements BArchivable) All users of HTTP requests will need to be updated if they implemented in HeadersReceived or used BUrlResult.
91 lines
2.0 KiB
C++
91 lines
2.0 KiB
C++
/*
|
|
* Copyright 2010 Haiku Inc. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _B_HTTP_HEADERS_H_
|
|
#define _B_HTTP_HEADERS_H_
|
|
|
|
|
|
#include <List.h>
|
|
#include <Message.h>
|
|
#include <String.h>
|
|
|
|
|
|
class BHttpHeader {
|
|
public:
|
|
BHttpHeader();
|
|
BHttpHeader(const char* string);
|
|
BHttpHeader(const char* name,
|
|
const char* value);
|
|
BHttpHeader(const BHttpHeader& copy);
|
|
|
|
// Header data modification
|
|
void SetName(const char* name);
|
|
void SetValue(const char* value);
|
|
bool SetHeader(const char* string);
|
|
|
|
// Header data access
|
|
const char* Name() const;
|
|
const char* Value() const;
|
|
const char* Header() const;
|
|
|
|
// Header data test
|
|
bool NameIs(const char* name) const;
|
|
|
|
// Overloaded members
|
|
BHttpHeader& operator=(const BHttpHeader& other);
|
|
|
|
private:
|
|
BString fName;
|
|
BString fValue;
|
|
|
|
mutable BString fRawHeader;
|
|
mutable bool fRawHeaderValid;
|
|
};
|
|
|
|
|
|
class BHttpHeaders {
|
|
public:
|
|
BHttpHeaders();
|
|
BHttpHeaders(const BHttpHeaders& copy);
|
|
~BHttpHeaders();
|
|
|
|
// Header list access
|
|
const char* HeaderValue(const char* name) const;
|
|
BHttpHeader& HeaderAt(int32 index) const;
|
|
|
|
// Header count
|
|
int32 CountHeaders() const;
|
|
|
|
// Header list tests
|
|
int32 HasHeader(const char* name) const;
|
|
|
|
// Header add or replacement
|
|
bool AddHeader(const char* line);
|
|
bool AddHeader(const char* name,
|
|
const char* value);
|
|
bool AddHeader(const char* name,
|
|
int32 value);
|
|
|
|
// Archiving
|
|
void PopulateFromArchive(BMessage*);
|
|
void Archive(BMessage*) const;
|
|
|
|
// Header deletion
|
|
void Clear();
|
|
|
|
// Overloaded operators
|
|
BHttpHeaders& operator=(const BHttpHeaders& other);
|
|
BHttpHeader& operator[](int32 index) const;
|
|
const char* operator[](const char* name) const;
|
|
|
|
private:
|
|
void _EraseData();
|
|
bool _AddOrDeleteHeader(BHttpHeader* header);
|
|
|
|
private:
|
|
BList fHeaderList;
|
|
};
|
|
|
|
#endif // _B_HTTP_HEADERS_H_
|