Move UrlResult to HttpResult
* Remove the fRawData field, as handling it is too complicated (it's not easy to have proper copy semantics on a BDataIO) and it's not used anyway, as the listener DataReceived call is enough to get the data and handle it. * All the remaining fields are HTTP-only, so rename the class to HttpResult and attach it to HttpRequest instead of UrlRequest.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <HttpAuthentication.h>
|
||||
#include <HttpForm.h>
|
||||
#include <HttpHeaders.h>
|
||||
#include <HttpResult.h>
|
||||
#include <NetBuffer.h>
|
||||
#include <NetworkAddress.h>
|
||||
#include <UrlRequest.h>
|
||||
@@ -48,6 +49,9 @@ public:
|
||||
const ssize_t size = -1);
|
||||
void AdoptHeaders(BHttpHeaders* const headers);
|
||||
|
||||
const BHttpResult& Result() const;
|
||||
const char* StatusString(status_t threadStatus) const;
|
||||
|
||||
static bool IsInformationalStatusCode(int16 code);
|
||||
static bool IsSuccessStatusCode(int16 code);
|
||||
static bool IsRedirectionStatusCode(int16 code);
|
||||
@@ -55,8 +59,6 @@ public:
|
||||
static bool IsServerErrorStatusCode(int16 code);
|
||||
static int16 StatusCodeClass(int16 code);
|
||||
|
||||
virtual const char* StatusString(status_t threadStatus) const;
|
||||
|
||||
private:
|
||||
void _ResetOptions();
|
||||
status_t _ProtocolLoop();
|
||||
@@ -73,6 +75,11 @@ private:
|
||||
|
||||
void _AddOutputBufferLine(const char* line);
|
||||
|
||||
// URL result parameters access
|
||||
BPositionIO* _ResultRawData();
|
||||
BHttpHeaders& _ResultHeaders();
|
||||
void _SetResultStatusCode(int32 statusCode);
|
||||
BString& _ResultStatusText();
|
||||
|
||||
private:
|
||||
BAbstractSocket* fSocket;
|
||||
@@ -91,6 +98,7 @@ private:
|
||||
// Request status
|
||||
|
||||
BHttpHeaders fOutputHeaders;
|
||||
BHttpResult fResult;
|
||||
|
||||
// Request state/events
|
||||
enum {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _B_URL_RESULT_H_
|
||||
#define _B_URL_RESULT_H_
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <HttpHeaders.h>
|
||||
#include <String.h>
|
||||
#include <Url.h>
|
||||
|
||||
|
||||
class BUrlRequest;
|
||||
|
||||
|
||||
class BHttpResult {
|
||||
friend class BHttpRequest;
|
||||
|
||||
public:
|
||||
BHttpResult(const BUrl& url);
|
||||
BHttpResult(const BHttpResult& other);
|
||||
~BHttpResult();
|
||||
|
||||
// Result parameters modifications
|
||||
void SetUrl(const BUrl& url);
|
||||
|
||||
// Result parameters access
|
||||
const BUrl& Url() const;
|
||||
|
||||
// HTTP-Specific stuff
|
||||
const BHttpHeaders& Headers() const;
|
||||
const BString& StatusText() const;
|
||||
int32 StatusCode() const;
|
||||
|
||||
// Result tests
|
||||
bool HasHeaders() const;
|
||||
|
||||
// Overloaded members
|
||||
BHttpResult& operator=(const BHttpResult& other);
|
||||
|
||||
private:
|
||||
BUrl fUrl;
|
||||
|
||||
// TODO: HTTP specific stuff should not live here.
|
||||
BHttpHeaders fHeaders;
|
||||
int32 fStatusCode;
|
||||
BString fStatusString;
|
||||
};
|
||||
|
||||
|
||||
#endif // _B_URL_RESULT_H_
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
|
||||
#include <Url.h>
|
||||
#include <UrlResult.h>
|
||||
#include <UrlContext.h>
|
||||
#include <UrlProtocolListener.h>
|
||||
#include <OS.h>
|
||||
@@ -30,13 +29,11 @@ public:
|
||||
|
||||
// URL protocol parameters modification
|
||||
status_t SetUrl(const BUrl& url);
|
||||
status_t SetResult(BUrlResult& result);
|
||||
status_t SetContext(BUrlContext* context);
|
||||
status_t SetListener(BUrlProtocolListener* listener);
|
||||
|
||||
// URL protocol parameters access
|
||||
const BUrl& Url() const;
|
||||
const BUrlResult& Result() const;
|
||||
BUrlContext* Context() const;
|
||||
BUrlProtocolListener* Listener() const;
|
||||
const BString& Protocol() const;
|
||||
@@ -53,16 +50,8 @@ protected:
|
||||
virtual status_t _ProtocolLoop();
|
||||
virtual void _EmitDebug(BUrlProtocolDebugMessage type,
|
||||
const char* format, ...);
|
||||
|
||||
// URL result parameters access
|
||||
BMallocIO& _ResultRawData();
|
||||
BHttpHeaders& _ResultHeaders();
|
||||
void _SetResultStatusCode(int32 statusCode);
|
||||
BString& _ResultStatusText();
|
||||
|
||||
protected:
|
||||
BUrl fUrl;
|
||||
BUrlResult fResult;
|
||||
BUrlContext* fContext;
|
||||
BUrlProtocolListener* fListener;
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _B_URL_RESULT_H_
|
||||
#define _B_URL_RESULT_H_
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <DataIO.h>
|
||||
#include <HttpHeaders.h>
|
||||
#include <String.h>
|
||||
#include <Url.h>
|
||||
|
||||
|
||||
class BUrlRequest;
|
||||
|
||||
|
||||
class BUrlResult {
|
||||
friend class BUrlRequest;
|
||||
|
||||
public:
|
||||
BUrlResult(const BUrl& url);
|
||||
BUrlResult(const BUrlResult& other);
|
||||
|
||||
// Result parameters modifications
|
||||
void SetUrl(const BUrl& url);
|
||||
|
||||
// Result parameters access
|
||||
const BUrl& Url() const;
|
||||
const BMallocIO& RawData() const;
|
||||
const BHttpHeaders& Headers() const;
|
||||
const BString& StatusText() const;
|
||||
int32 StatusCode() const;
|
||||
|
||||
// Result tests
|
||||
bool HasHeaders() const;
|
||||
|
||||
// Overloaded members
|
||||
BUrlResult& operator=(const BUrlResult& other);
|
||||
friend std::ostream& operator<<(std::ostream& out,
|
||||
const BUrlResult& result);
|
||||
|
||||
private:
|
||||
BUrl fUrl;
|
||||
BMallocIO fRawData;
|
||||
BHttpHeaders fHeaders;
|
||||
// TODO: HTTP specific stuff should not live here.
|
||||
|
||||
int32 fStatusCode;
|
||||
BString fStatusString;
|
||||
};
|
||||
|
||||
|
||||
#endif // _B_URL_RESULT_H_
|
||||
Reference in New Issue
Block a user