void dynamic_1B(TestArg *arg) { char *uri; HttpEngine engine; HttpRequest *request; HttpResponse *response; arg->returnVal = 0; uri = (char *)malloc(sizeof(TEST_QUERY) + strlen(arg->uri) + 2); sprintf(uri, "%s?%s", arg->uri, TEST_QUERY); request = new HttpRequest(arg->server, uri, arg->proto); request->setExpectDynamicBody(); response = engine.makeRequest(*request); if (response->getStatus() != 200) { Logger::logError(LOGERROR, "server responded with status code %d", response->getStatus()); arg->returnVal = -1; } char *query = response->getDynamicResponse().lookupValue("BASIC", "queryString"); if (!query || strcmp(query, TEST_QUERY)) { Logger::logError(LOGERROR, "query string mismatch! (\"%s\")", query); arg->returnVal = -1; } free(uri); delete request; delete response; }
void dynamic_1D(TestArg *arg) { HttpEngine engine; HttpRequest request(arg->server, arg->uri, arg->proto); HttpResponse *response; char header[1024], value[1024]; arg->returnVal = 0; memset(header, 'X', 1024); header[1024-1] = '\0'; memset(value, 'Y', 1024); value[1024-1] = '\0'; request.addHeader(header,value); request.setExpectDynamicBody(); response = engine.makeRequest(request); if (response->getStatus() != 200) { Logger::logError(LOGERROR, "server responded with status code %d", response->getStatus()); arg->returnVal = -1; } char *rvheader = response->getDynamicResponse().lookupValue("REQUEST HEADERS", header); if (!rvheader || strcmp(rvheader, value)) { fprintf(stdout, "strlen(rvheader) is %d\n", strlen(rvheader)); fprintf(stdout, "strlen(header) is %d\n", strlen(header)); Logger::logError(LOGERROR, "long header mismatch! (\"%s\")", rvheader); arg->returnVal = -1; } delete response; }
void lastmodified() { if (!instance) return; // retrieve the file and save the last modified date char *lm=NULL; request = new HttpRequest(&instance->myServer(), SMALLFILE, instance->myProtocol(), Engine::globaltimeout); HttpEngine engine; response = engine.makeRequest(*request, instance->myServer()); if (response && (response->getStatus() != 200)) Logger::logError(LOGERROR, "server could not get %s (%d)", SMALLFILE, response->getStatus()); if (response) { lm = response->getHeader("last-modified"); delete response; response = NULL; }; if (!lm) Logger::logError(LOGWARNING, "server did not respond with last-modified header"); else lastModified = strdup(lm); delete request; request = NULL; };
virtual PRBool run() { if (!instance) return PR_FALSE; const HttpServer& server = instance->myServer(); /* // first upload the file server.putFile(fname, fsize); */ // simple GET request = new HttpRequest(&server, fname, instance->myProtocol(), Engine::globaltimeout); request->setExpectedResponseLength(fsize); request->setExpectStandardBody(); HttpEngine engine; response = engine.makeRequest(*request, server); if (response) { if (response->getStatus() != 200) Logger::logError(LOGERROR, "server responded with status code %d", response->getStatus()); else instance->setStatus(PR_SUCCESS); // success delete response; response = NULL; }; return PR_TRUE; };
virtual PRBool run() { PRBool supportsRanges = PR_FALSE; if (!instance) return PR_FALSE; // put the file on the server instance->myServer().putFile(BYTEFILE, BYTESIZE); // retrieve the file { request = new HttpRequest(&instance->myServer(), BYTEFILE, instance->myProtocol(), Engine::globaltimeout); request->addHeader("range", "bytes=0-127"); request->setExpectedResponseLength(128); request->setExpectStandardBody(); HttpEngine engine; response = engine.makeRequest(*request, instance->myServer()); if (response && (response->getStatus() == 206)) instance->setStatus(PR_SUCCESS); // success else if (response) { if (response->getStatus() == 200) { Logger::logError(LOGWARNING, "server does not support byte ranges"); } else { Logger::logError(LOGERROR, "server could not get %s (%d)", BYTEFILE, response->getStatus()); }; char *contentRangeHeader = response->getHeader("Content-range"); if (!contentRangeHeader) Logger::logError(LOGERROR, "server did not send content range header"); }; delete request; request = NULL; delete response; response=NULL; }; return PR_TRUE; };
void dynamic_1C(TestArg *arg) { HttpEngine engine; HttpRequest request(arg->server, arg->uri, arg->proto); HttpResponse *response; arg->returnVal = 0; request.addHeader(HEADER1, VALUE1); request.addHeader(HEADER2, VALUE2); request.addHeader(HEADER3, VALUE3); request.addHeader(HEADER4, VALUE4); request.setExpectDynamicBody(); response = engine.makeRequest(request); if (response->getStatus() != 200) { Logger::logError(LOGERROR, "server responded with status code %d", response->getStatus()); arg->returnVal = -1; } char *header = response->getDynamicResponse().lookupValue("REQUEST HEADERS", HEADER1); if (!header || strcmp(header, VALUE1)) { Logger::logError(LOGERROR, "header1 mismatch! (\"%s\")", header); arg->returnVal = -1; } header = response->getDynamicResponse().lookupValue("REQUEST HEADERS", HEADER2); if (!header || strcmp(header, VALUE2)) { Logger::logError(LOGERROR, "header2 mismatch! (\"%s\")", header); arg->returnVal = -1; } header = response->getDynamicResponse().lookupValue("REQUEST HEADERS", HEADER3); if (!header || strcmp(header, VALUE3)) { Logger::logError(LOGERROR, "header3 mismatch! (\"%s\")", header); arg->returnVal = -1; } header = response->getDynamicResponse().lookupValue("REQUEST HEADERS", HEADER4); if (!header || strcmp(header, VALUE4)) { Logger::logError(LOGERROR, "header4 mismatch! (\"%s\")", header); arg->returnVal = -1; } delete response; }
void dynamic_1A(TestArg *arg) { HttpEngine engine; HttpRequest request(arg->server, arg->uri, arg->proto); HttpResponse *response; arg->returnVal = 0; request.setExpectDynamicBody(); response = engine.makeRequest(request); if (response->getStatus() != 200) { Logger::logError(LOGERROR, "server responded with status code %d", response->getStatus()); arg->returnVal = -1; } delete response; }
void cause304() { if (!instance) return; // try to cause a 304 request if (lastModified) { request = new HttpRequest(&instance->myServer(), SMALLFILE, instance->myProtocol(), Engine::globaltimeout); request->addHeader("If-modified-since", lastModified); HttpEngine engine; response = engine.makeRequest(*request, instance->myServer()); if (response) { if (PR_TRUE == expected) { if (response->getStatus() != 304) Logger::logError(LOGERROR, "server did not respond with 304 response (%d)", response->getStatus()); else instance->setStatus(PR_SUCCESS); // success } else { if (response->getStatus() != 200) Logger::logError(LOGERROR, "server did not respond with 200 response (%d)", response->getStatus()); else instance->setStatus(PR_SUCCESS); // success } delete response; response=NULL; }; delete request; request=NULL; }; };
TPS_PUBLIC PSHttpResponse *HttpConnection::getResponse(int index, const char *servlet, const char *body) { char *host_port; char uri[800]; char *nickname; const char *httpprotocol; ConnectionInfo *failoverList = GetFailoverList(); int len = failoverList->ConnectionInfo::GetHostPortListLen(); if (index >= len) { index = len - 1; // use the last one } host_port= (failoverList->GetHostPortList())[index]; if (IsSSL()) { httpprotocol = "https"; } else { httpprotocol = "http"; } PR_snprintf((char *)uri, 800, "%s://%s/%s", httpprotocol, host_port, servlet); RA::Debug("HttpConnection::getResponse", "Send request to host %s servlet %s", host_port, servlet); RA::Debug(LL_PER_PDU, "HttpConnection::getResponse", "uri=%s", uri); RA::Debug(LL_PER_PDU, "HttpConnection::getResponse", "host_port=%s", host_port); char *pPort = NULL; char *pPortActual = NULL; char hostName[512]; /* * Isolate the host name, account for IPV6 numeric addresses. * */ if(host_port) strncpy(hostName,host_port,512); pPort = hostName; while(1) { pPort = strchr(pPort, ':'); if (pPort) { pPortActual = pPort; pPort++; } else break; } if(pPortActual) *pPortActual = '\0'; /* * Rifle through the values for the host */ PRAddrInfo *ai; void *iter; PRNetAddr addr; int family = PR_AF_INET; ai = PR_GetAddrInfoByName(hostName, PR_AF_UNSPEC, PR_AI_ADDRCONFIG); if (ai) { printf("%s\n", PR_GetCanonNameFromAddrInfo(ai)); iter = NULL; while ((iter = PR_EnumerateAddrInfo(iter, ai, 0, &addr)) != NULL) { char buf[512]; PR_NetAddrToString(&addr, buf, sizeof buf); RA::Debug( LL_PER_PDU, "HttpConnection::getResponse: ", "Sending addr -- Msg='%s'\n", buf ); family = PR_NetAddrFamily(&addr); RA::Debug( LL_PER_PDU, "HttpConnection::getResponse: ", "Sending family -- Msg='%d'\n", family ); break; } PR_FreeAddrInfo(ai); } PSHttpServer httpserver(host_port, family); nickname = GetClientNickname(); if (IsSSL()) httpserver.setSSL(PR_TRUE); else httpserver.setSSL(PR_FALSE); PSHttpRequest httprequest(&httpserver, uri, HTTP11, 0); if (IsSSL()) { httprequest.setSSL(PR_TRUE); if (nickname != NULL) { httprequest.setCertNickName(nickname); } else { return NULL; } } else httprequest.setSSL(PR_FALSE); httprequest.setMethod("POST"); if (body != NULL) { httprequest.setBody( strlen(body), body); } httprequest.addHeader( "Content-Type", "application/x-www-form-urlencoded" ); if (m_headers != NULL) { for (int i=0; i<m_headers->Size(); i++) { char *name = m_headers->GetNameAt(i); httprequest.addHeader(name, m_headers->GetValue(name)); } } if (IsKeepAlive()) httprequest.addHeader( "Connection", "keep-alive" ); HttpEngine httpEngine; return httpEngine.makeRequest(httprequest, httpserver, (PRIntervalTime)GetTimeout(), PR_FALSE /*expectChunked*/); }