#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), _WEBClientState(WEBServer<WEBClient>::WEBClientState::ACCEPTED), _httpParserState(WEBServer<WEBClient>::HttpParserStatus::HTTP_VERB)
{
  #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.getParamsDataPointer = NULL;
  _httpRequestData.postParamsDataPointer = NULL;
  
  _httpRequestData.httpResource = NULL;
  _httpRequestData.maxResourceBuffer = maxResourceBuffer;
  _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.getParams.dispose();
  _httpRequestData.postParams.dispose();
}
