/* function get statusMessage(): String */ static EjsString *http_statusMessage(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv) { HttpConn *conn; if (!waitForResponseHeaders(hp)) { return 0; } conn = hp->conn; if (conn->errorMsg) { return ejsCreateStringFromAsc(ejs, conn->errorMsg); } return ejsCreateStringFromAsc(ejs, httpGetStatusMessage(hp->conn)); }
bool simpleForm(MprTestGroup *gp, char *uri, char *formData, int expectStatus) { HttpConn *conn; MprOff contentLen; ssize len; int status; contentLen = 0; if (expectStatus <= 0) { expectStatus = 200; } if (startRequest(gp, "POST", uri) < 0) { return 0; } conn = getConn(gp); if (formData) { httpSetHeader(conn, "Content-Type", "application/x-www-form-urlencoded"); len = slen(formData); if (httpWrite(conn->writeq, formData, len) != len) { return MPR_ERR_CANT_WRITE; } } httpFinalizeOutput(conn); if (httpWait(conn, HTTP_STATE_COMPLETE, -1) < 0) { return MPR_ERR_CANT_READ; } status = httpGetStatus(conn); if (status != expectStatus) { mprLog("appweb test form", 0, "Client failed for %s, response code: %d, msg %s", uri, status, httpGetStatusMessage(conn)); return 0; } gp->content = httpReadString(conn); contentLen = httpGetContentLength(conn); if (! tassert(gp->content != 0 && contentLen > 0)) { return 0; } return 1; }
bool simplePost(MprTestGroup *gp, char *uri, char *bodyData, ssize len, int expectStatus) { HttpConn *conn; MprOff contentLen; int status; contentLen = 0; conn = getConn(gp); if (expectStatus <= 0) { expectStatus = 200; } if (startRequest(gp, "POST", uri) < 0) { return 0; } if (bodyData) { if (httpWrite(conn->writeq, bodyData, len) != len) { return MPR_ERR_CANT_WRITE; } } httpFinalizeOutput(conn); if (httpWait(conn, HTTP_STATE_COMPLETE, -1) < 0) { return MPR_ERR_CANT_READ; } status = httpGetStatus(conn); if (status != expectStatus) { mprLog("appweb test post", 0, "Client failed for %s, response code: %d, msg %s", uri, status, httpGetStatusMessage(conn)); return 0; } gp->content = httpReadString(conn); contentLen = httpGetContentLength(conn); if (! tassert(gp->content != 0 && contentLen > 0)) { return 0; } return 1; }
char *espGetStatusMessage(HttpConn *conn) { return httpGetStatusMessage(conn); }