Commit 51705f0b authored by jan.koester's avatar jan.koester
Browse files

test

parent d0991739
Loading
Loading
Loading
Loading
+35 −50
Original line number Diff line number Diff line
@@ -3253,7 +3253,7 @@ void libhttppp::HttpHeader::clear(){
void libhttppp::HttpHeader::HeaderData::erase(int /*pos*/){
}

void libhttppp::HttpHeader::HeaderData::push_back(const char* val){
libhttppp::HttpHeader::HeaderData::Values &libhttppp::HttpHeader::HeaderData::push_back(const char* val){
  if(_firstValue==nullptr){
    _firstValue=std::make_unique<Values>(val);
    _lastValue=_firstValue.get();
@@ -3261,9 +3261,10 @@ void libhttppp::HttpHeader::HeaderData::push_back(const char* val){
    _lastValue->_nextvalue=std::make_unique<Values>(val);
    _lastValue=_lastValue->_nextvalue.get();
  }
  return *_lastValue;
}

void libhttppp::HttpHeader::HeaderData::push_back(const Values& val){
libhttppp::HttpHeader::HeaderData::Values &libhttppp::HttpHeader::HeaderData::push_back(const Values& val){
  if(_firstValue==nullptr){
    _firstValue=std::make_unique<Values>(val);
    _lastValue=_firstValue.get();
@@ -3271,10 +3272,11 @@ void libhttppp::HttpHeader::HeaderData::push_back(const Values& val){
    _lastValue->_nextvalue=std::make_unique<Values>(val);
    _lastValue=_lastValue->_nextvalue.get();
  }
  return *_lastValue;
}


void libhttppp::HttpHeader::HeaderData::push_back(const std::string &val){
libhttppp::HttpHeader::HeaderData::Values &libhttppp::HttpHeader::HeaderData::push_back(const std::string &val){
  if(_firstValue==nullptr){
    _firstValue=std::make_unique<Values>(val);
    _lastValue=_firstValue.get();
@@ -3282,14 +3284,15 @@ void libhttppp::HttpHeader::HeaderData::push_back(const std::string &val){
    _lastValue->_nextvalue=std::make_unique<Values>(val);
    _lastValue=_lastValue->_nextvalue.get();
  }
  return *_lastValue;
}

void libhttppp::HttpHeader::HeaderData::push_back(int val){
  push_back(std::to_string(val));
libhttppp::HttpHeader::HeaderData::Values &libhttppp::HttpHeader::HeaderData::push_back(int val){
  return push_back(std::to_string(val));
}

void libhttppp::HttpHeader::HeaderData::push_back(size_t val){
  push_back(std::to_string(val));
libhttppp::HttpHeader::HeaderData::Values &libhttppp::HttpHeader::HeaderData::push_back(size_t val){
  return push_back(std::to_string(val));
}


@@ -5139,50 +5142,32 @@ void libhttppp::HttpCookie::setcookie(libhttppp::HttpResponse &curresp,
    httpexception[HTTPException::Note] << "no key or value set in cookie!";
    throw httpexception;
  }
  HttpHeader::HeaderData *dat=curresp.setHeaderData("set-cookie");

  // A cookie's attributes (Max-Age, Path, SameSite, ...) belong on the same
  // Set-Cookie line as its name=value, joined with "; " -- printHeader() emits
  // one physical line per push_back()'d value (see comment there), so pushing
  // once per *attribute* here used to fan a single cookie out into N separate
  // top-level Set-Cookie headers, each parsed by the browser as its own cookie.
  std::string buf=key;
  buf+="=";
  buf+=value;

  if(!comment.empty()){
    buf+="; comment=";
    buf+=comment;
  }
  if(!domain.empty()){
    buf+="; domain=";
    buf+=domain;
  }
  if(maxage>=0){
    buf+="; max-age=" + std::to_string(maxage);
  }
  if(!path.empty()){
    buf+="; path=";
    buf+=path;
  }
  if(!samesite.empty()){
    buf+="; sameSite=";
    buf+=samesite;
  }else{
    buf+="; sameSite=Lax";
  }
  if(secure){
    buf+="; secure";
  }
  if(!version.empty()){
    buf+="; version=";
    buf+=version;
  }
  if(httponly){
    buf+="; httponly";
  }

  dat->push_back(buf);
  // Set-Cookie line as its name=value -- printHeader() emits one physical line
  // per push_back()'d value (see comment there), so pushing once per *attribute*
  // used to fan a single cookie out into N separate top-level Set-Cookie headers,
  // each parsed by the browser as its own cookie. Chain onto the one Values node
  // this call owns instead of pushing a new one per attribute.
  HttpHeader::HeaderData::Values &val = curresp.setHeaderData("set-cookie")->push_back(key + "=" + value);

  if(!comment.empty())
    val << "; comment=" << comment;
  if(!domain.empty())
    val << "; domain=" << domain;
  if(maxage>=0)
    val << "; max-age=" << maxage;
  if(!path.empty())
    val << "; path=" << path;
  if(!samesite.empty())
    val << "; sameSite=" << samesite;
  else
    val << "; sameSite=Lax";
  if(secure)
    val << "; secure";
  if(!version.empty())
    val << "; version=" << version;
  if(httponly)
    val << "; httponly";
}

void libhttppp::HttpCookie::parse(libhttppp::HttpRequest &curreq){
+5 −5
Original line number Diff line number Diff line
@@ -336,11 +336,11 @@ namespace libhttppp {
      Values &at(int pos);
      Values &operator[](int pos);

      void push_back(const Values &val);
      void push_back(const std::string &val);
      void push_back(const char* val);
      void push_back(size_t val);
      void push_back(int val);
      Values &push_back(const Values &val);
      Values &push_back(const std::string &val);
      Values &push_back(const char* val);
      Values &push_back(size_t val);
      Values &push_back(int val);

      bool empty();