#include "WEBClient.h"

//#define DEBUG_WEBCL

WEBClient::WEBClient(WiFiClient client, uint8_t id, uint16_t maxResourceBuffer, uint16_t maxBodyBuffer, uint16_t dataBufferSize) : TCPClient(client, id, dataBufferSize)
{
  #ifdef DEBUG_WEBCL
  Serial.println("WEBClient : Standard constructor called");
  #endif
  
  _httpRequestData.HRM = WEBServer<WEBClient>::HttpRequestMethod::UNDEFINED;
  _httpRequestData.HV  = WEBServer<WEBClient>::HttpVersion::UNKNOWN;
  _httpRequestData.HMT = WEBServer<WEBClient>::HttpMIMEType::UNKNOWN_MIME;
  _httpRequestData.contentLength = 0;

  _httpRequestData.postParamsDataPointer = NULL;
  
  _httpRequestData.httpResource = NULL;
  _httpRequestData.maxResourceBuffer = maxResourceBuffer; // \0 included
  _httpRequestData.httpBody = NULL;
  _httpRequestData.maxBodyBuffer = maxBodyBuffer;
}

WEBClient::~WEBClient()
{
  #ifdef DEBUG_WEBCL
  Serial.println("WEBClient : Destructor called");
  #endif
  clearHttpRequestData();
}

void WEBClient::clearHttpRequestData()
{
  free(_httpRequestData.httpResource);free(_httpRequestData.httpBody);
  _httpRequestData.cookies.dispose();
  _httpRequestData.getParams.dispose();
  _httpRequestData.postParams.dispose();
}
