HttpRequest: allow custom http methods
* The W3C XmlHttpRequest testsuite likes to use "CHICKEN" as a method. * Also add constants for all specified methods in HTTP 1.1.
This commit is contained in:
@@ -29,7 +29,7 @@ public:
|
|||||||
BUrlContext* context = NULL);
|
BUrlContext* context = NULL);
|
||||||
virtual ~BHttpRequest();
|
virtual ~BHttpRequest();
|
||||||
|
|
||||||
void SetMethod(int8 method);
|
void SetMethod(const char* const method);
|
||||||
void SetFollowLocation(bool follow);
|
void SetFollowLocation(bool follow);
|
||||||
void SetMaxRedirections(int8 maxRedirections);
|
void SetMaxRedirections(int8 maxRedirections);
|
||||||
void SetReferrer(const BString& referrer);
|
void SetReferrer(const BString& referrer);
|
||||||
@@ -74,7 +74,7 @@ private:
|
|||||||
BNetworkAddress fRemoteAddr;
|
BNetworkAddress fRemoteAddr;
|
||||||
bool fSSL;
|
bool fSSL;
|
||||||
|
|
||||||
int8 fRequestMethod;
|
BString fRequestMethod;
|
||||||
int8 fHttpVersion;
|
int8 fHttpVersion;
|
||||||
|
|
||||||
BString fOutputBuffer;
|
BString fOutputBuffer;
|
||||||
@@ -123,14 +123,14 @@ enum {
|
|||||||
|
|
||||||
|
|
||||||
// Request method
|
// Request method
|
||||||
enum {
|
const char* const B_HTTP_GET = "GET";
|
||||||
B_HTTP_GET = 1,
|
const char* const B_HTTP_POST = "POST";
|
||||||
B_HTTP_POST,
|
const char* const B_HTTP_PUT = "PUT";
|
||||||
B_HTTP_PUT,
|
const char* const B_HTTP_HEAD = "HEAD";
|
||||||
B_HTTP_HEAD,
|
const char* const B_HTTP_DELETE = "DELETE";
|
||||||
B_HTTP_DELETE,
|
const char* const B_HTTP_OPTIONS = "OPTIONS";
|
||||||
B_HTTP_OPTIONS
|
const char* const B_HTTP_TRACE = "TRACE";
|
||||||
};
|
const char* const B_HTTP_CONNECT = "CONNECT";
|
||||||
|
|
||||||
|
|
||||||
// HTTP Version
|
// HTTP Version
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ BHttpRequest::~BHttpRequest()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BHttpRequest::SetMethod(int8 method)
|
BHttpRequest::SetMethod(const char* const method)
|
||||||
{
|
{
|
||||||
fRequestMethod = method;
|
fRequestMethod = method;
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,8 @@ BHttpRequest::_ProtocolLoop()
|
|||||||
|
|
||||||
if (!_ResolveHostName()) {
|
if (!_ResolveHostName()) {
|
||||||
_EmitDebug(B_URL_PROTOCOL_DEBUG_ERROR,
|
_EmitDebug(B_URL_PROTOCOL_DEBUG_ERROR,
|
||||||
"Unable to resolve hostname, aborting.");
|
"Unable to resolve hostname (%s), aborting.",
|
||||||
|
fUrl.Host().String());
|
||||||
return B_PROT_CANT_RESOLVE_HOSTNAME;
|
return B_PROT_CANT_RESOLVE_HOSTNAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -732,22 +733,7 @@ BHttpRequest::_ParseHeaders()
|
|||||||
void
|
void
|
||||||
BHttpRequest::_CreateRequest()
|
BHttpRequest::_CreateRequest()
|
||||||
{
|
{
|
||||||
BString request;
|
BString request(fRequestMethod);
|
||||||
|
|
||||||
switch (fRequestMethod) {
|
|
||||||
case B_HTTP_POST:
|
|
||||||
request << "POST";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case B_HTTP_PUT:
|
|
||||||
request << "PUT";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
case B_HTTP_GET:
|
|
||||||
request << "GET";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Url().HasPath())
|
if (Url().HasPath())
|
||||||
request << ' ' << Url().Path();
|
request << ' ' << Url().Path();
|
||||||
@@ -804,21 +790,7 @@ BHttpRequest::_AddHeaders()
|
|||||||
|
|
||||||
// Authentication
|
// Authentication
|
||||||
if (fAuthentication.Method() != B_HTTP_AUTHENTICATION_NONE) {
|
if (fAuthentication.Method() != B_HTTP_AUTHENTICATION_NONE) {
|
||||||
BString request;
|
BString request(fRequestMethod);
|
||||||
switch (fRequestMethod) {
|
|
||||||
case B_HTTP_POST:
|
|
||||||
request = "POST";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case B_HTTP_PUT:
|
|
||||||
request = "PUT";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
case B_HTTP_GET:
|
|
||||||
request = "GET";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fOutputHeaders.AddHeader("Authorization",
|
fOutputHeaders.AddHeader("Authorization",
|
||||||
fAuthentication.Authorization(fUrl, request));
|
fAuthentication.Authorization(fUrl, request));
|
||||||
|
|||||||
Reference in New Issue
Block a user