Factor out a BNetworkRequest
* Shares common behavior between the Gopher and HTTP request handlers. * Most of this can be used when implemeting other protocols.
This commit is contained in:
@@ -8,15 +8,10 @@
|
||||
|
||||
#include <deque>
|
||||
|
||||
#include <NetBuffer.h>
|
||||
#include <NetworkAddress.h>
|
||||
#include <UrlRequest.h>
|
||||
#include <NetworkRequest.h>
|
||||
|
||||
|
||||
class BAbstractSocket;
|
||||
|
||||
|
||||
class BGopherRequest : public BUrlRequest {
|
||||
class BGopherRequest : public BNetworkRequest {
|
||||
public:
|
||||
BGopherRequest(const BUrl& url,
|
||||
BUrlProtocolListener* listener = NULL,
|
||||
@@ -29,21 +24,17 @@ public:
|
||||
|
||||
private:
|
||||
status_t _ProtocolLoop();
|
||||
bool _ResolveHostName();
|
||||
void _SendRequest();
|
||||
|
||||
bool _NeedsParsing();
|
||||
bool _NeedsLastDotStrip();
|
||||
void _ParseInput(bool last);
|
||||
|
||||
status_t _GetLine(BString& destString);
|
||||
BString& _HTMLEscapeString(BString &str);
|
||||
|
||||
private:
|
||||
char fItemType;
|
||||
BString fPath;
|
||||
BAbstractSocket* fSocket;
|
||||
BNetworkAddress fRemoteAddr;
|
||||
|
||||
BNetBuffer fInputBuffer;
|
||||
ssize_t fPosition;
|
||||
|
||||
@@ -11,15 +11,11 @@
|
||||
#include <HttpForm.h>
|
||||
#include <HttpHeaders.h>
|
||||
#include <HttpResult.h>
|
||||
#include <NetBuffer.h>
|
||||
#include <NetworkAddress.h>
|
||||
#include <UrlRequest.h>
|
||||
#include <NetworkRequest.h>
|
||||
|
||||
|
||||
class BAbstractSocket;
|
||||
|
||||
|
||||
class BHttpRequest : public BUrlRequest {
|
||||
class BHttpRequest : public BNetworkRequest {
|
||||
public:
|
||||
BHttpRequest(const BUrl& url,
|
||||
bool ssl = false,
|
||||
@@ -63,15 +59,12 @@ public:
|
||||
private:
|
||||
void _ResetOptions();
|
||||
status_t _ProtocolLoop();
|
||||
bool _ResolveHostName();
|
||||
status_t _MakeRequest();
|
||||
|
||||
void _SendRequest();
|
||||
void _SendHeaders();
|
||||
void _SendPostData();
|
||||
|
||||
status_t _GetLine(BString& destString);
|
||||
|
||||
void _ParseStatus();
|
||||
void _ParseHeaders();
|
||||
|
||||
@@ -85,15 +78,11 @@ private:
|
||||
bool _IsDefaultPort();
|
||||
|
||||
private:
|
||||
BAbstractSocket* fSocket;
|
||||
BNetworkAddress fRemoteAddr;
|
||||
bool fSSL;
|
||||
|
||||
BString fRequestMethod;
|
||||
int8 fHttpVersion;
|
||||
|
||||
BNetBuffer fInputBuffer;
|
||||
|
||||
BHttpHeaders fHeaders;
|
||||
|
||||
// Request status
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2014 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _B_NET_REQUEST_H_
|
||||
#define _B_NET_REQUEST_H_
|
||||
|
||||
|
||||
#include <NetBuffer.h>
|
||||
#include <NetworkAddress.h>
|
||||
#include <UrlRequest.h>
|
||||
|
||||
|
||||
class BAbstractSocket;
|
||||
|
||||
|
||||
class BNetworkRequest: public BUrlRequest
|
||||
{
|
||||
public:
|
||||
BNetworkRequest(const BUrl& url,
|
||||
BUrlProtocolListener* listener,
|
||||
BUrlContext* context,
|
||||
const char* threadName,
|
||||
const char* protocolName);
|
||||
protected:
|
||||
bool _ResolveHostName(uint16_t port);
|
||||
|
||||
status_t _GetLine(BString& destString);
|
||||
|
||||
protected:
|
||||
BAbstractSocket* fSocket;
|
||||
BNetworkAddress fRemoteAddr;
|
||||
|
||||
BNetBuffer fInputBuffer;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user