Compare commits
5 Commits
version/20
...
version/20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b3c048363 | ||
|
|
01f689a0e4 | ||
|
|
b155f2e40f | ||
|
|
10ab8b830a | ||
|
|
8a4871db83 |
@@ -472,12 +472,26 @@ size_t Client::requestReadCallback(char *ptr, size_t size, size_t nmemb, void *u
|
||||
return actualBytes;
|
||||
}
|
||||
|
||||
bool isRedirectStatus(int code)
|
||||
{
|
||||
return ((code >= 300) && (code < 400));
|
||||
}
|
||||
|
||||
size_t Client::requestHeaderCallback(char *rawBuffer, size_t size, size_t nitems, void *userdata)
|
||||
{
|
||||
size_t byteSize = size * nitems;
|
||||
Request* req = static_cast<Request*>(userdata);
|
||||
std::string h = strutils::simplify(std::string(rawBuffer, byteSize));
|
||||
|
||||
if (req->readyState() >= HTTP::Request::HEADERS_RECEIVED) {
|
||||
// this can happen with chunked transfers (secondary chunks)
|
||||
// or redirects
|
||||
if (isRedirectStatus(req->responseCode())) {
|
||||
req->responseStart(h);
|
||||
return byteSize;
|
||||
}
|
||||
}
|
||||
|
||||
if (req->readyState() == HTTP::Request::OPENED) {
|
||||
req->responseStart(h);
|
||||
return byteSize;
|
||||
|
||||
@@ -328,6 +328,16 @@ unsigned int Request::responseLength() const
|
||||
return _responseLength;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Request::setSuccess(int code)
|
||||
{
|
||||
_responseStatus = code;
|
||||
_responseReason.clear();
|
||||
if( !isComplete() ) {
|
||||
setReadyState(DONE);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Request::setFailure(int code, const std::string& reason)
|
||||
{
|
||||
|
||||
@@ -224,7 +224,7 @@ protected:
|
||||
virtual void onAlways();
|
||||
|
||||
void setFailure(int code, const std::string& reason);
|
||||
|
||||
void setSuccess(int code);
|
||||
private:
|
||||
friend class Client;
|
||||
friend class Connection;
|
||||
|
||||
@@ -273,7 +273,23 @@ public:
|
||||
d << "\r\n"; // final CRLF to terminate the headers
|
||||
d << contentStr;
|
||||
push(d.str().c_str());
|
||||
|
||||
} else if (path == "/test_redirect") {
|
||||
string contentStr("<html>See <a href=\"wibble\">Here</a></html>");
|
||||
stringstream d;
|
||||
d << "HTTP/1.1 " << 302 << " " << "Found" << "\r\n";
|
||||
d << "Location:" << " http://localhost:2000/was_redirected" << "\r\n";
|
||||
d << "Content-Length:" << contentStr.size() << "\r\n";
|
||||
d << "\r\n"; // final CRLF to terminate the headers
|
||||
d << contentStr;
|
||||
push(d.str().c_str());
|
||||
} else if (path == "/was_redirected") {
|
||||
string contentStr(BODY1);
|
||||
stringstream d;
|
||||
d << "HTTP/1.1 " << 200 << " " << reasonForCode(200) << "\r\n";
|
||||
d << "Content-Length:" << contentStr.size() << "\r\n";
|
||||
d << "\r\n"; // final CRLF to terminate the headers
|
||||
d << contentStr;
|
||||
push(d.str().c_str());
|
||||
} else {
|
||||
TestServerChannel::processRequestHeaders();
|
||||
}
|
||||
@@ -773,6 +789,24 @@ cout << "testing proxy close" << endl;
|
||||
SG_CHECK_EQUAL(tr2->bodyData, string(BODY1));
|
||||
SG_CHECK_EQUAL(tr2->responseBytesReceived(), strlen(BODY1));
|
||||
}
|
||||
|
||||
{
|
||||
cout << "redirect test" << endl;
|
||||
// redirect test
|
||||
testServer.disconnectAll();
|
||||
cl.clearAllConnections();
|
||||
|
||||
TestRequest* tr = new TestRequest("http://localhost:2000/test_redirect");
|
||||
HTTP::Request_ptr own(tr);
|
||||
cl.makeRequest(tr);
|
||||
|
||||
waitForComplete(&cl, tr);
|
||||
SG_CHECK_EQUAL(tr->responseCode(), 200);
|
||||
SG_CHECK_EQUAL(tr->responseReason(), string("OK"));
|
||||
SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1));
|
||||
SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY1));
|
||||
SG_CHECK_EQUAL(tr->bodyData, string(BODY1));
|
||||
}
|
||||
|
||||
cout << "all tests passed ok" << endl;
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -30,7 +30,6 @@ public:
|
||||
|
||||
virtual ~TestServerChannel()
|
||||
{
|
||||
std::cerr << "dtor test server channel" << std::endl;
|
||||
}
|
||||
|
||||
virtual void collectIncomingData(const char* s, int n)
|
||||
@@ -139,8 +138,8 @@ public:
|
||||
|
||||
void sendErrorResponse(int code, bool close, std::string content)
|
||||
{
|
||||
std::cerr << "sending error " << code << " for " << path << std::endl;
|
||||
std::cerr << "\tcontent:" << content << std::endl;
|
||||
// std::cerr << "sending error " << code << " for " << path << std::endl;
|
||||
// std::cerr << "\tcontent:" << content << std::endl;
|
||||
|
||||
std::stringstream headerData;
|
||||
headerData << "HTTP/1.1 " << code << " " << reasonForCode(code) << "\r\n";
|
||||
@@ -168,7 +167,6 @@ public:
|
||||
|
||||
virtual void handleClose (void)
|
||||
{
|
||||
std::cerr << "channel close" << std::endl;
|
||||
NetBufferChannel::handleClose();
|
||||
}
|
||||
|
||||
|
||||
@@ -302,15 +302,18 @@ static char* dosprintf(char* f, ...)
|
||||
char* buf;
|
||||
va_list va;
|
||||
int olen, len = 16;
|
||||
va_start(va, f);
|
||||
while(1) {
|
||||
buf = naAlloc(len);
|
||||
va_start(va, f);
|
||||
olen = vsnprintf(buf, len, f, va);
|
||||
va_list vaCopy;
|
||||
va_copy(vaCopy, va);
|
||||
olen = vsnprintf(buf, len, f, vaCopy);
|
||||
if(olen >= 0 && olen < len) {
|
||||
va_end(va);
|
||||
va_end(vaCopy);
|
||||
return buf;
|
||||
}
|
||||
va_end(va);
|
||||
va_end(vaCopy);
|
||||
naFree(buf);
|
||||
len *= 2;
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ void SGSoundMgr::suspend()
|
||||
for ( auto current = d->_sample_groups.begin();
|
||||
current != d->_sample_groups.end(); ++current ) {
|
||||
SGSampleGroup *sgrp = current->second;
|
||||
sgrp->stop();
|
||||
sgrp->suspend();
|
||||
}
|
||||
_active = false;
|
||||
}
|
||||
|
||||
@@ -83,6 +83,9 @@ SGXmlSound::~SGXmlSound()
|
||||
if (_sample)
|
||||
_sample->stop();
|
||||
|
||||
if (_sgrp && (_name != ""))
|
||||
_sgrp->remove(_name);
|
||||
|
||||
_volume.clear();
|
||||
_pitch.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user