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:
Adrien Destugues 2013-10-15 14:43:09 +02:00
parent f6f14c5d1c
commit 7696f7dd54
2 changed files with 15 additions and 43 deletions

View File

@ -29,7 +29,7 @@ public:
BUrlContext* context = NULL);
virtual ~BHttpRequest();
void SetMethod(int8 method);
void SetMethod(const char* const method);
void SetFollowLocation(bool follow);
void SetMaxRedirections(int8 maxRedirections);
void SetReferrer(const BString& referrer);
@ -74,7 +74,7 @@ private:
BNetworkAddress fRemoteAddr;
bool fSSL;
int8 fRequestMethod;
BString fRequestMethod;
int8 fHttpVersion;
BString fOutputBuffer;
@ -123,14 +123,14 @@ enum {
// Request method
enum {
B_HTTP_GET = 1,
B_HTTP_POST,
B_HTTP_PUT,
B_HTTP_HEAD,
B_HTTP_DELETE,
B_HTTP_OPTIONS
};
const char* const B_HTTP_GET = "GET";
const char* const B_HTTP_POST = "POST";
const char* const B_HTTP_PUT = "PUT";
const char* const B_HTTP_HEAD = "HEAD";
const char* const B_HTTP_DELETE = "DELETE";
const char* const B_HTTP_OPTIONS = "OPTIONS";
const char* const B_HTTP_TRACE = "TRACE";
const char* const B_HTTP_CONNECT = "CONNECT";
// HTTP Version

View File

@ -58,7 +58,7 @@ BHttpRequest::~BHttpRequest()
void
BHttpRequest::SetMethod(int8 method)
BHttpRequest::SetMethod(const char* const method)
{
fRequestMethod = method;
}
@ -265,7 +265,8 @@ BHttpRequest::_ProtocolLoop()
if (!_ResolveHostName()) {
_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;
}
@ -732,22 +733,7 @@ BHttpRequest::_ParseHeaders()
void
BHttpRequest::_CreateRequest()
{
BString request;
switch (fRequestMethod) {
case B_HTTP_POST:
request << "POST";
break;
case B_HTTP_PUT:
request << "PUT";
break;
default:
case B_HTTP_GET:
request << "GET";
break;
}
BString request(fRequestMethod);
if (Url().HasPath())
request << ' ' << Url().Path();
@ -804,21 +790,7 @@ BHttpRequest::_AddHeaders()
// Authentication
if (fAuthentication.Method() != B_HTTP_AUTHENTICATION_NONE) {
BString request;
switch (fRequestMethod) {
case B_HTTP_POST:
request = "POST";
break;
case B_HTTP_PUT:
request = "PUT";
break;
default:
case B_HTTP_GET:
request = "GET";
break;
}
BString request(fRequestMethod);
fOutputHeaders.AddHeader("Authorization",
fAuthentication.Authorization(fUrl, request));