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.
47 lines
1.4 KiB
C++
47 lines
1.4 KiB
C++
/*
|
|
* Copyright 2010 Haiku Inc. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _B_URL_SYNCHRONOUS_REQUEST_H_
|
|
#define _B_URL_SYNCHRONOUS_REQUEST_H_
|
|
|
|
|
|
#include <UrlRequest.h>
|
|
#include <UrlProtocolListener.h>
|
|
|
|
|
|
class BUrlSynchronousRequest : public BUrlRequest, public BUrlProtocolListener {
|
|
public:
|
|
BUrlSynchronousRequest(BUrlRequest& asynchronousRequest);
|
|
virtual ~BUrlSynchronousRequest() { };
|
|
|
|
// Synchronous wait
|
|
virtual status_t Perform();
|
|
virtual status_t WaitUntilCompletion();
|
|
|
|
// Protocol hooks
|
|
virtual void ConnectionOpened(BUrlRequest* caller);
|
|
virtual void HostnameResolved(BUrlRequest* caller,
|
|
const char* ip);
|
|
virtual void ResponseStarted(BUrlRequest* caller);
|
|
virtual void HeadersReceived(BUrlRequest* caller,
|
|
const BUrlResult& result);
|
|
virtual void DataReceived(BUrlRequest* caller,
|
|
const char* data, off_t position,
|
|
ssize_t size);
|
|
virtual void DownloadProgress(BUrlRequest* caller,
|
|
ssize_t bytesReceived, ssize_t bytesTotal);
|
|
virtual void UploadProgress(BUrlRequest* caller,
|
|
ssize_t bytesSent, ssize_t bytesTotal);
|
|
virtual void RequestCompleted(BUrlRequest* caller,
|
|
bool success);
|
|
|
|
|
|
protected:
|
|
bool fRequestComplete;
|
|
BUrlRequest& fWrappedRequest;
|
|
};
|
|
|
|
|
|
#endif // _B_URL_SYNCHRONOUS_REQUEST_H_
|