Beispiel #1
0
/**
 * This is a factory method that constructs HTTP_Response a 
 * provided HTTP_Request request.
 * @param request pointer to HTTP_Request for which the response is created for
 * @return response A HTTP_Response constructed from the binary buffer contents
 */
HTTP_Response* HTTP_Response::buildResponseToRequest(const HTTP_Request *request)
{
    HTTP_Response *response = new HTTP_Response();
    string clientKey = request->getWebSocketKey();
    string generatedKey = generateWebSocketAcceptVal(clientKey);
	//TODO: don't use setResponseString, build a real HTTP_Response object that can be used for other things
    //response->setResponseString("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: "+ generatedKey +"\r\nSec-WebSocket-Protocol: chat\r\n\r\n");
    response->setResponseString("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: "+ generatedKey +"\r\n\r\n");
    return response;
}
/**
 * This is a factory method that constructs HTTP_Response a 
 * provided HTTP_Request request.
 * @param request pointer to HTTP_Request for which the response is created for
 * @return response A HTTP_Response constructed from the binary buffer contents
 */
HTTP_Response* HTTP_Response::buildResponseToRequest(const HTTP_Request *request)
{
    HTTP_Response *response = new HTTP_Response();
	if(!request->isValid()) {
		response->setStatusCode("400");
		//TODO: Add explanation of failure to body (custom reason-phrase)
		return response;
	}
    string clientKey = request->getWebSocketKeyFieldValue();
    string generatedKey = generateWebSocketAcceptVal(clientKey);
	//TODO: don't use setResponseString, build a real HTTP_Response object that can be used for other things
    //response->setResponseString("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: "+ generatedKey +"\r\nSec-WebSocket-Protocol: chat\r\n\r\n");
    response->setResponseString("HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: "+ generatedKey +"\r\n\r\n");
    return response;
}
Beispiel #3
0
void
HTTP_Response::process_request(HTTP_Response &response)
{
  response.process_request();
}