Beispiel #1
0
void WebServer::favicon(ConnectionType type) {
	httpSuccess("image/x-icon", "Cache-Control: max-age=31536000\r\n");
	if (type != HEAD) {
		P (faviconIco) = WEBDUINO_FAVICON_DATA;
		writeP(faviconIco, sizeof(faviconIco));
	}
}
Beispiel #2
0
void WebServer::noRobots(ConnectionType type)
{
  httpSuccess("text/plain");
  if (type != HEAD)
  {
    P(allowNoneMsg) = "User-agent: *" CRLF "Disallow: /" CRLF;
    printP(allowNoneMsg);
  }
}
// virtual
void LLCurl::Responder::httpCompleted()
{
	if (isGoodStatus())
	{
		httpSuccess();
	}
	else
	{
		httpFailure();
	}
}
void LLCurl::Responder::successResult(const LLSD& content)
{
	setResult(HTTP_OK, "", content);
	httpSuccess();
}
Beispiel #5
0
void WebServer::processRestReguest(ConnectionType type, char *tail, bool tail_complete, Binding & binding) {

	long id = atol(tail);
	byte i = 0;

	aJsonObject *oldModel;
	aJsonObject *newModel;

	this->currentCollection = binding.collection;

	if (id) {
		oldModel = (*binding.collection)->child;
		if (type == WebServer::GET || type == WebServer::PUT || type == WebServer::DELETE) {
			while (oldModel) {
				aJsonObject* idItem = aJson.getObjectItem(oldModel, "id");
				if (idItem->valuelong == id) {
					break;
				}
				oldModel = oldModel->next;
				i++;
			}
			this->currentModel = &oldModel;
		}
		if (type == WebServer::PUT) {
			newModel = aJson.parse(*this);
			this->currentModel = &newModel;
		}
	} else {
		if (type == WebServer::POST) {
			newModel = aJson.parse(*this);
			this->currentModel = &newModel;
		} else {
			this->currentModel = NULL;
		}
	}

	if (*binding.beforeResponse != NULL) {
		binding.beforeResponse(*this, type, tail, tail_complete, this->currentCollection, this->currentModel);
	}

	if (!this->preventDefault) {
		if (id) {
			if (type == WebServer::GET) {
				httpSuccess("application/json");
				aJson.print(oldModel, *this);
			}
			if (type == WebServer::PUT) {
				aJson.replaceItemInArray(*this->currentCollection, i, newModel);
				httpSuccess("application/json");
				aJson.print(newModel, *this);
			}
			if (type == WebServer::DELETE) {
				aJson.deleteItemFromArray(*this->currentCollection, i);
				httpSuccess();
			}

		} else {
			if (type == WebServer::GET) {
				httpSuccess("application/json");
				aJson.print(*this->currentCollection, *this);
			}
			if (type == WebServer::POST) {
				aJson.addNumberToObject(newModel, "id", ++binding.curId);
				aJson.addItemToArray(*this->currentCollection, newModel);
				httpCreated("application/json");
				aJson.print(newModel, *this);
			}
			if (type == WebServer::PUT) {
				aJson.deleteItem(*this->currentCollection);
				*this->currentCollection = aJson.parse(*this);
				httpSuccess("application/json");
				aJson.print(*this->currentCollection, *this);
			}
			if (type == WebServer::DELETE) {
				aJson.deleteItem(*this->currentCollection);
				httpNoContent();
			}
		}

	} else {
		this->preventDefault = false;
	}


	if (*binding.afterResponce != NULL){
		this->finalCommand = binding.afterResponce;
	}

}