1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/protocol/http/nsHttpRequestHead.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,92 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +// HttpLog.h should generally be included first 1.10 +#include "HttpLog.h" 1.11 + 1.12 +#include "nsHttpRequestHead.h" 1.13 + 1.14 +//----------------------------------------------------------------------------- 1.15 +// nsHttpRequestHead 1.16 +//----------------------------------------------------------------------------- 1.17 + 1.18 +namespace mozilla { 1.19 +namespace net { 1.20 + 1.21 +nsHttpRequestHead::nsHttpRequestHead() 1.22 + : mMethod(NS_LITERAL_CSTRING("GET")) 1.23 + , mVersion(NS_HTTP_VERSION_1_1) 1.24 + , mParsedMethod(kMethod_Get) 1.25 +{ 1.26 +} 1.27 + 1.28 +void 1.29 +nsHttpRequestHead::SetMethod(const nsACString &method) 1.30 +{ 1.31 + mParsedMethod = kMethod_Custom; 1.32 + mMethod = method; 1.33 + if (!strcmp(mMethod.get(), "GET")) { 1.34 + mParsedMethod = kMethod_Get; 1.35 + } else if (!strcmp(mMethod.get(), "POST")) { 1.36 + mParsedMethod = kMethod_Post; 1.37 + } else if (!strcmp(mMethod.get(), "OPTIONS")) { 1.38 + mParsedMethod = kMethod_Options; 1.39 + } else if (!strcmp(mMethod.get(), "CONNECT")) { 1.40 + mParsedMethod = kMethod_Connect; 1.41 + } else if (!strcmp(mMethod.get(), "HEAD")) { 1.42 + mParsedMethod = kMethod_Head; 1.43 + } else if (!strcmp(mMethod.get(), "PUT")) { 1.44 + mParsedMethod = kMethod_Put; 1.45 + } else if (!strcmp(mMethod.get(), "TRACE")) { 1.46 + mParsedMethod = kMethod_Trace; 1.47 + } 1.48 +} 1.49 + 1.50 +bool 1.51 +nsHttpRequestHead::IsSafeMethod() const 1.52 +{ 1.53 + // This code will need to be extended for new safe methods, otherwise 1.54 + // they'll default to "not safe". 1.55 + if (IsGet() || IsHead() || IsOptions() || IsTrace()) { 1.56 + return true; 1.57 + } 1.58 + 1.59 + if (mParsedMethod != kMethod_Custom) { 1.60 + return false; 1.61 + } 1.62 + 1.63 + return (!strcmp(mMethod.get(), "PROPFIND") || 1.64 + !strcmp(mMethod.get(), "REPORT") || 1.65 + !strcmp(mMethod.get(), "SEARCH")); 1.66 +} 1.67 + 1.68 +void 1.69 +nsHttpRequestHead::Flatten(nsACString &buf, bool pruneProxyHeaders) 1.70 +{ 1.71 + // note: the first append is intentional. 1.72 + 1.73 + buf.Append(mMethod); 1.74 + buf.Append(' '); 1.75 + buf.Append(mRequestURI); 1.76 + buf.AppendLiteral(" HTTP/"); 1.77 + 1.78 + switch (mVersion) { 1.79 + case NS_HTTP_VERSION_1_1: 1.80 + buf.AppendLiteral("1.1"); 1.81 + break; 1.82 + case NS_HTTP_VERSION_0_9: 1.83 + buf.AppendLiteral("0.9"); 1.84 + break; 1.85 + default: 1.86 + buf.AppendLiteral("1.0"); 1.87 + } 1.88 + 1.89 + buf.AppendLiteral("\r\n"); 1.90 + 1.91 + mHeaders.Flatten(buf, pruneProxyHeaders); 1.92 +} 1.93 + 1.94 +} // namespace mozilla::net 1.95 +} // namespace mozilla