mirror of
https://github.com/Fishwaldo/minihttp.git
synced 2025-07-06 04:48:22 +00:00
Do not call _OnRequestDone() and _OnClose() if following a redirect and autofollow is on.
This makes the redirect fully transparent and invisible for the outside.
This commit is contained in:
parent
d8bcc2f830
commit
6fc6bbd1fb
2 changed files with 37 additions and 7 deletions
31
minihttp.cpp
31
minihttp.cpp
|
@ -15,6 +15,7 @@
|
|||
#include <string.h>
|
||||
#include <sstream>
|
||||
#include <cctype>
|
||||
#include <cerrno>
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -207,7 +208,7 @@ void TcpSocket::close(void)
|
|||
if(!SOCKETVALID(_s))
|
||||
return;
|
||||
|
||||
_OnClose();
|
||||
_OnCloseInternal();
|
||||
|
||||
#ifdef _WIN32
|
||||
::closesocket((SOCKET)_s);
|
||||
|
@ -217,6 +218,11 @@ void TcpSocket::close(void)
|
|||
_s = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
void TcpSocket::_OnCloseInternal()
|
||||
{
|
||||
_OnClose();
|
||||
}
|
||||
|
||||
bool TcpSocket::SetNonBlocking(bool nonblock)
|
||||
{
|
||||
_nonblocking = nonblock;
|
||||
|
@ -397,6 +403,12 @@ void HttpSocket::_OnOpen()
|
|||
_chunkedTransfer = false;
|
||||
}
|
||||
|
||||
void HttpSocket::_OnCloseInternal()
|
||||
{
|
||||
if(!IsRedirecting() || _alwaysHandle)
|
||||
_OnClose();
|
||||
}
|
||||
|
||||
bool HttpSocket::_OnUpdate()
|
||||
{
|
||||
if(!TcpSocket::_OnUpdate())
|
||||
|
@ -511,7 +523,8 @@ void HttpSocket::_FinishRequest(void)
|
|||
{
|
||||
if(_inProgress)
|
||||
{
|
||||
_OnRequestDone(); // notify about finished request
|
||||
if(!IsRedirecting() || _alwaysHandle)
|
||||
_OnRequestDone(); // notify about finished request
|
||||
_inProgress = false;
|
||||
_hdrs.clear();
|
||||
}
|
||||
|
@ -665,6 +678,20 @@ bool HttpSocket::_HandleStatus()
|
|||
}
|
||||
}
|
||||
|
||||
bool HttpSocket::IsRedirecting() const
|
||||
{
|
||||
switch(_status)
|
||||
{
|
||||
case 301:
|
||||
case 302:
|
||||
case 303:
|
||||
case 307:
|
||||
case 308:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void HttpSocket::_ParseHeader(void)
|
||||
{
|
||||
|
|
13
minihttp.h
13
minihttp.h
|
@ -47,7 +47,7 @@ public:
|
|||
bool SendBytes(const char *str, unsigned int len);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void _OnCloseInternal();
|
||||
virtual void _OnData(); // data received callback. Internal, should only be overloaded to call _OnRecv()
|
||||
|
||||
virtual void _OnRecv(char *buf, unsigned int size) = 0;
|
||||
|
@ -139,8 +139,10 @@ public:
|
|||
const Request &GetCurrentRequest() const { return _curRequest; }
|
||||
const char *Hdr(const char *h) const;
|
||||
|
||||
protected:
|
||||
bool IsRedirecting() const;
|
||||
|
||||
protected:
|
||||
virtual void _OnCloseInternal();
|
||||
virtual void _OnClose();
|
||||
virtual void _OnData(); // data received callback. Internal, should only be overloaded to call _OnRecv()
|
||||
virtual void _OnRecv(char *buf, unsigned int size) = 0;
|
||||
|
@ -206,7 +208,7 @@ public:
|
|||
void remove(TcpSocket *s);
|
||||
inline size_t size() { return _store.size(); }
|
||||
|
||||
protected:
|
||||
//protected:
|
||||
|
||||
struct SocketSetData
|
||||
{
|
||||
|
@ -219,9 +221,10 @@ protected:
|
|||
Store _store;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
} // end namespace minihttp
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue