.Core: HttpRequest fix

git-svn-id: svn://ultimatepp.org/upp/trunk@4964 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-05-17 11:44:39 +00:00
parent 3135cd0bf8
commit 0d291220fa
3 changed files with 102 additions and 108 deletions

View file

@ -659,13 +659,11 @@ void HttpRequest::Finish()
#endif
}
Close();
if(cookies)
CopyCookies();
CopyCookies();
if(status_code == 401 && !IsNull(username)) {
String authenticate = header["www-authenticate"];
if(authenticate.GetCount() && redirect_count++ < max_redirects) {
LLOG("HTTP auth digest");
CopyCookies();
Digest(CalculateDigest(authenticate));
Start();
return;
@ -676,7 +674,6 @@ void HttpRequest::Finish()
if(url.GetCount() && redirect_count++ < max_redirects) {
LLOG("--- HTTP redirect " << url);
Url(url);
CopyCookies();
Start();
retry_count = 0;
return;

View file

@ -343,7 +343,6 @@ class HttpRequest : public TcpSocket {
void ReadingChunkHeader();
void Finish();
bool IsRequestTimeout();
void CopyCookies();
void HttpError(const char *s);
@ -390,8 +389,6 @@ public:
HttpRequest& AddHeaders(const String& h) { request_headers.Cat(h); return *this; }
HttpRequest& Header(const char *id, const String& data);
HttpRequest& Cookie(const String& cookie) { return Header("Cookie", cookie); }
HttpRequest& Cookies(bool b = true) { cookies = b; }
HttpRequest& StdHeaders(bool sh) { std_headers = sh; return *this; }
HttpRequest& NoStdHeaders() { return StdHeaders(false); }

View file

@ -1,101 +1,101 @@
#include "SSL.h"
#define LLOG(x) // DLOG(x)
NAMESPACE_UPP
static int64 UPP_SSL_alloc = 0;
static void *SslAlloc(size_t size)
{
LLOG("Alloc " << size);
size_t alloc = size + sizeof(int64);
int64 *aptr = (int64 *)MemoryAllocSz(alloc);
*aptr++ = (int64)alloc;
LLOG("UPP_SSL_MALLOC(" << (int64)size << ", alloc " << alloc << ") -> " << FormatIntHex(aptr) << ", total = " << UPP_SSL_alloc);
return aptr;
}
static void SslFree(void *ptr)
{
if(!ptr)
return;
int64 *aptr = (int64 *)ptr - 1;
UPP_SSL_alloc -= *aptr;
LLOG("UPP_SSL_FREE(" << ptr << ", alloc " << *aptr << "), total = " << UPP_SSL_alloc);
MemoryFree(aptr);
}
static void *SslRealloc(void *ptr, size_t size)
{
if(!ptr)
return NULL;
int64 *aptr = (int64 *)ptr - 1;
if((int64)(size + sizeof(int64)) <= *aptr) {
LLOG("UPP_SSL_REALLOC(" << ptr << ", " << (int64)size << ", alloc " << *aptr << ") -> keep same block");
return ptr;
}
size_t newalloc = size + sizeof(int64);
int64 *newaptr = (int64 *)MemoryAllocSz(newalloc);
if(!newaptr) {
LLOG("UPP_SSL_REALLOC(" << ptr << ", " << (int64)size << ", alloc " << newalloc << ") -> fail");
return NULL;
}
*newaptr++ = newalloc;
memcpy(newaptr, ptr, min<int>(*aptr - sizeof(int64), size));
UPP_SSL_alloc += newalloc - *aptr;
LLOG("UPP_SSL_REALLOC(" << ptr << ", " << (int64)size << ", alloc " << newalloc << ") -> "
<< FormatIntHex(newaptr) << ", total = " << UPP_SSL_alloc);
MemoryFree(aptr);
return newaptr;
}
void TcpSocketInit();
INITBLOCK
{
LLOG("SSL init");
TcpSocketInit();
MemoryIgnoreLeaksBlock __;
CRYPTO_set_mem_functions(SslAlloc, SslRealloc, SslFree);
SSL_library_init();
SSL_load_error_strings();
}
EXITBLOCK
{
CONF_modules_unload(1);
EVP_cleanup();
ENGINE_cleanup();
CRYPTO_cleanup_all_ex_data();
ERR_remove_state(0);
ERR_free_strings();
}
#ifdef _MULTITHREADED
static thread__ bool sThreadInit;
static thread__ void (*sPrevExit)();
static void sslExitThread()
{
ERR_remove_state(0);
if(sPrevExit)
(*sPrevExit)();
}
void SslInitThread()
{
if(sThreadInit || Thread::IsMain())
return;
sThreadInit = true;
sPrevExit = Thread::AtExit(sslExitThread);
}
#else
void SslInitThread() {}
#endif
END_UPP_NAMESPACE
#include "SSL.h"
#define LLOG(x) // DLOG(x)
NAMESPACE_UPP
static int64 UPP_SSL_alloc = 0;
static void *SslAlloc(size_t size)
{
LLOG("Alloc " << size);
size_t alloc = size + sizeof(int64);
int64 *aptr = (int64 *)MemoryAllocSz(alloc);
*aptr++ = (int64)alloc;
LLOG("UPP_SSL_MALLOC(" << (int64)size << ", alloc " << alloc << ") -> " << FormatIntHex(aptr) << ", total = " << UPP_SSL_alloc);
return aptr;
}
static void SslFree(void *ptr)
{
if(!ptr)
return;
int64 *aptr = (int64 *)ptr - 1;
UPP_SSL_alloc -= *aptr;
LLOG("UPP_SSL_FREE(" << ptr << ", alloc " << *aptr << "), total = " << UPP_SSL_alloc);
MemoryFree(aptr);
}
static void *SslRealloc(void *ptr, size_t size)
{
if(!ptr)
return NULL;
int64 *aptr = (int64 *)ptr - 1;
if((int64)(size + sizeof(int64)) <= *aptr) {
LLOG("UPP_SSL_REALLOC(" << ptr << ", " << (int64)size << ", alloc " << *aptr << ") -> keep same block");
return ptr;
}
size_t newalloc = size + sizeof(int64);
int64 *newaptr = (int64 *)MemoryAllocSz(newalloc);
if(!newaptr) {
LLOG("UPP_SSL_REALLOC(" << ptr << ", " << (int64)size << ", alloc " << newalloc << ") -> fail");
return NULL;
}
*newaptr++ = newalloc;
memcpy(newaptr, ptr, min<int>((int)(*aptr - sizeof(int64)), size));
UPP_SSL_alloc += newalloc - *aptr;
LLOG("UPP_SSL_REALLOC(" << ptr << ", " << (int64)size << ", alloc " << newalloc << ") -> "
<< FormatIntHex(newaptr) << ", total = " << UPP_SSL_alloc);
MemoryFree(aptr);
return newaptr;
}
void TcpSocketInit();
INITBLOCK
{
LLOG("SSL init");
TcpSocketInit();
MemoryIgnoreLeaksBlock __;
CRYPTO_set_mem_functions(SslAlloc, SslRealloc, SslFree);
SSL_library_init();
SSL_load_error_strings();
}
EXITBLOCK
{
CONF_modules_unload(1);
EVP_cleanup();
ENGINE_cleanup();
CRYPTO_cleanup_all_ex_data();
ERR_remove_state(0);
ERR_free_strings();
}
#ifdef _MULTITHREADED
static thread__ bool sThreadInit;
static thread__ void (*sPrevExit)();
static void sslExitThread()
{
ERR_remove_state(0);
if(sPrevExit)
(*sPrevExit)();
}
void SslInitThread()
{
if(sThreadInit || Thread::IsMain())
return;
sThreadInit = true;
sPrevExit = Thread::AtExit(sslExitThread);
}
#else
void SslInitThread() {}
#endif
END_UPP_NAMESPACE