void EventSource::didFail(const ResourceError& error) { int canceled = error.isCancellation(); if (((m_state == CONNECTING) && !canceled) || ((m_state == OPEN) && canceled)) m_state = CLOSED; endRequest(); }
void Controller::writeBenchmarkResponse(Client **client, Request **req, bool end) { if (canKeepAlive(*req)) { writeResponse(*client, P_STATIC_STRING( "HTTP/1.1 200 OK\r\n" "Status: 200 OK\r\n" "Date: Wed, 15 Nov 1995 06:25:24 GMT\r\n" "Content-Type: text/plain\r\n" "Content-Length: 3\r\n" "Connection: keep-alive\r\n" "\r\n" "ok\n")); } else { writeResponse(*client, P_STATIC_STRING( "HTTP/1.1 200 OK\r\n" "Status: 200 OK\r\n" "Date: Wed, 15 Nov 1995 06:25:24 GMT\r\n" "Content-Type: text/plain\r\n" "Content-Length: 3\r\n" "Connection: close\r\n" "\r\n" "ok\n")); } if (end && !(*req)->ended()) { endRequest(client, req); } }
void EventSource::didFinishLoading(unsigned long) { if (m_receiveBuf.size() > 0 || m_data.size() > 0) { append(m_receiveBuf, "\n\n"); parseEventStream(); } m_state = CONNECTING; endRequest(); }
void Controller::endRequestAsBadGateway(Client **client, Request **req) { if ((*req)->responseBegun) { disconnectWithError(client, "bad gateway"); } else { ServerKit::HeaderTable headers; headers.insert((*req)->pool, "cache-control", "no-cache, no-store, must-revalidate"); writeSimpleResponse(*client, 502, &headers, "<h1>Bad Gateway</h1>"); endRequest(client, req); } }
/** * `data` must outlive the request. */ void Controller::endRequestWithSimpleResponse(Client **c, Request **r, const StaticString &body, int code) { Client *client = *c; Request *req = *r; ServerKit::HeaderTable headers; headers.insert(req->pool, "cache-control", "no-cache, no-store, must-revalidate"); writeSimpleResponse(client, code, &headers, body); endRequest(c, r); }
int WebSocketClient::begin(const char* aPath) { // start the GET request beginRequest(); connectionKeepAlive(); int status = get(aPath); if (status == 0) { uint8_t randomKey[16]; char base64RandomKey[25]; // create a random key for the connection upgrade for (int i = 0; i < (int)sizeof(randomKey); i++) { randomKey[i] = random(0x01, 0xff); } memset(base64RandomKey, 0x00, sizeof(base64RandomKey)); b64_encode(randomKey, sizeof(randomKey), (unsigned char*)base64RandomKey, sizeof(base64RandomKey)); // start the connection upgrade sequence sendHeader("Upgrade", "websocket"); sendHeader("Connection", "Upgrade"); sendHeader("Sec-WebSocket-Key", base64RandomKey); sendHeader("Sec-WebSocket-Version", "13"); endRequest(); status = responseStatusCode(); if (status > 0) { skipResponseHeaders(); } } iRxSize = 0; // status code of 101 means success return (status == 101) ? 0 : status; }