+#include "message.h"
#include <cstdlib>
#include <msp/core/maputils.h>
#include <msp/strings/format.h>
#include <msp/strings/utils.h>
-#include "message.h"
using namespace std;
namespace Msp {
namespace Http {
-Message::Message():
- http_version(0x11),
- chunk_length(0),
- complete(false)
-{ }
-
void Message::set_header(const string &hdr, const string &val)
{
headers[normalize_header_name(hdr)] = val;
if(complete)
return 0;
- HeaderMap::const_iterator i = headers.find("Content-Length");
+ auto i = headers.find("Content-Length");
if(i!=headers.end())
{
string::size_type needed = lexical_cast<string::size_type>(i->second)-content.size();
{
string result;
- for(HeaderMap::const_iterator i=headers.begin(); i!=headers.end(); ++i)
- if(i->first[0]!='-')
- result += format("%s: %s\r\n", i->first, i->second);
+ for(auto &kvp: headers)
+ if(kvp.first[0]!='-')
+ result += format("%s: %s\r\n", kvp.first, kvp.second);
result += "\r\n";
result += content;
{
string result = hdr;
bool upper = true;
- for(string::iterator i=result.begin(); i!=result.end(); ++i)
+ for(char &c: result)
{
- if(*i=='-')
+ if(c=='-')
upper = true;
else if(upper)
{
- *i = toupper(*i);
+ c = toupper(static_cast<unsigned char>(c));
upper = false;
}
else
- *i = tolower(*i);
+ c = tolower(static_cast<unsigned char>(c));
}
return result;
}