PUBLIC HttpTx *httpCreateTx(HttpConn *conn, MprHash *headers) { HttpTx *tx; if ((tx = mprAllocObj(HttpTx, manageTx)) == 0) { return 0; } conn->tx = tx; tx->conn = conn; tx->status = HTTP_CODE_OK; tx->length = -1; tx->entityLength = -1; tx->chunkSize = -1; tx->queue[HTTP_QUEUE_TX] = httpCreateQueueHead(conn, "TxHead"); conn->writeq = tx->queue[HTTP_QUEUE_TX]->nextQ; tx->queue[HTTP_QUEUE_RX] = httpCreateQueueHead(conn, "RxHead"); conn->readq = tx->queue[HTTP_QUEUE_RX]->prevQ; if (headers) { tx->headers = headers; } else { tx->headers = mprCreateHash(HTTP_SMALL_HASH_SIZE, MPR_HASH_CASELESS); if (!conn->endpoint) { httpAddHeaderString(conn, "User-Agent", sclone(BIT_HTTP_SOFTWARE)); } } return tx; }
/* Create a new connection object */ PUBLIC HttpConn *httpCreateConn(HttpEndpoint *endpoint, MprDispatcher *dispatcher) { HttpConn *conn; HttpHost *host; HttpRoute *route; if ((conn = mprAllocObj(HttpConn, manageConn)) == 0) { return 0; } conn->protocol = HTTP->protocol; conn->http = HTTP; conn->port = -1; conn->retries = HTTP_RETRIES; conn->endpoint = endpoint; conn->lastActivity = HTTP->now; conn->ioCallback = httpIOEvent; if (endpoint) { conn->notifier = endpoint->notifier; host = mprGetFirstItem(endpoint->hosts); if (host && (route = host->defaultRoute) != 0) { conn->limits = route->limits; conn->trace = route->trace; } else { conn->limits = HTTP->serverLimits; conn->trace = HTTP->trace; } } else { conn->limits = HTTP->clientLimits; conn->trace = HTTP->trace; } conn->keepAliveCount = conn->limits->keepAliveMax; conn->serviceq = httpCreateQueueHead(conn, "serviceq"); if (dispatcher) { conn->dispatcher = dispatcher; } else if (endpoint) { conn->dispatcher = endpoint->dispatcher; } else { conn->dispatcher = mprGetDispatcher(); } conn->rx = httpCreateRx(conn); conn->tx = httpCreateTx(conn, NULL); httpSetState(conn, HTTP_STATE_BEGIN); httpAddConn(conn); return conn; }