hrev46234 adds 2 changesets to branch 'master' old head: f6f14c5d1c0464f34a1a7637c1a9c356df4172aa new head: bb1d0adcd1224c4b9d9bb69c783c001f05cda314 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=bb1d0ad+%5Ef6f14c5 ---------------------------------------------------------------------------- 7696f7d: 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. bb1d0ad: BUrl: fix handling of @ character * @ is a separator (between user:password and host) only if there are no slashes before it * All slashes in user and password should be urlencoded (as well as any @ and :) * On the other hand, it's possible to have @ as part of an URL path or query. An example is Google Maps. Gets Google Maps working. [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- 3 files changed, 23 insertions(+), 44 deletions(-) headers/os/net/HttpRequest.h | 20 +++++++------- src/kits/network/libnetapi/HttpRequest.cpp | 38 ++++---------------------- src/kits/network/libnetapi/Url.cpp | 9 +++++- ############################################################################ Commit: 7696f7dd5492c8553f1c81a7ac27c4c4403dbcaa URL: http://cgit.haiku-os.org/haiku/commit/?id=7696f7d Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> Date: Tue Oct 15 12:43:09 2013 UTC 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. ---------------------------------------------------------------------------- diff --git a/headers/os/net/HttpRequest.h b/headers/os/net/HttpRequest.h index cb65e1e..c88c4de 100644 --- a/headers/os/net/HttpRequest.h +++ b/headers/os/net/HttpRequest.h @@ -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 diff --git a/src/kits/network/libnetapi/HttpRequest.cpp b/src/kits/network/libnetapi/HttpRequest.cpp index 796764d..39b6543 100644 --- a/src/kits/network/libnetapi/HttpRequest.cpp +++ b/src/kits/network/libnetapi/HttpRequest.cpp @@ -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)); ############################################################################ Revision: hrev46234 Commit: bb1d0adcd1224c4b9d9bb69c783c001f05cda314 URL: http://cgit.haiku-os.org/haiku/commit/?id=bb1d0ad Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> Date: Tue Oct 15 12:45:16 2013 UTC BUrl: fix handling of @ character * @ is a separator (between user:password and host) only if there are no slashes before it * All slashes in user and password should be urlencoded (as well as any @ and :) * On the other hand, it's possible to have @ as part of an URL path or query. An example is Google Maps. Gets Google Maps working. ---------------------------------------------------------------------------- diff --git a/src/kits/network/libnetapi/Url.cpp b/src/kits/network/libnetapi/Url.cpp index 8c26442..898d2f9 100644 --- a/src/kits/network/libnetapi/Url.cpp +++ b/src/kits/network/libnetapi/Url.cpp @@ -659,7 +659,14 @@ BUrl::_ExtractAuthority(const BString& urlString, int16* origin) (*origin) += 2; - int16 userInfoEnd = urlString.FindFirst('@', *origin); + int32 userInfoEnd = urlString.FindFirst('@', *origin); + + // if the @ comes after a /, it can't be the delimiter for + // user:pasword@host. Characters /:@ in user and password must be escaped. + // RFC1738, 3.1, Common Internet Scheme Syntax. + int32 nextSlash = urlString.FindFirst('/', *origin); + if(userInfoEnd > nextSlash) + userInfoEnd = -1; // URL contains userinfo field if (userInfoEnd != -1) {