More fixes for chunked encoding.
This commit is contained in:
parent
f0b36a0e36
commit
baeacc6d9e
1 changed files with 24 additions and 12 deletions
|
@ -124,10 +124,11 @@ void HTTP::Parser::SendResponse(std::string code, std::string message, Socket::C
|
||||||
void HTTP::Parser::Proxy(Socket::Connection & from, Socket::Connection & to){
|
void HTTP::Parser::Proxy(Socket::Connection & from, Socket::Connection & to){
|
||||||
SendResponse("200", "OK", to);
|
SendResponse("200", "OK", to);
|
||||||
if (getChunks){
|
if (getChunks){
|
||||||
int proxyingChunk = 0;
|
unsigned int proxyingChunk = 0;
|
||||||
while (to.connected() && from.connected()){
|
while (to.connected() && from.connected()){
|
||||||
if ((from.Received().size() && (from.Received().size() > 2 || *(from.Received().get().rbegin()) == '\n')) || from.spool()){
|
if ((from.Received().size() && (from.Received().size() > 1 || *(from.Received().get().rbegin()) == '\n')) || from.spool()){
|
||||||
if (proxyingChunk){
|
if (proxyingChunk){
|
||||||
|
while (proxyingChunk && from.Received().size()){
|
||||||
unsigned int toappend = from.Received().get().size();
|
unsigned int toappend = from.Received().get().size();
|
||||||
if (toappend > proxyingChunk){
|
if (toappend > proxyingChunk){
|
||||||
toappend = proxyingChunk;
|
toappend = proxyingChunk;
|
||||||
|
@ -138,15 +139,22 @@ void HTTP::Parser::Proxy(Socket::Connection & from, Socket::Connection & to){
|
||||||
from.Received().get().clear();
|
from.Received().get().clear();
|
||||||
}
|
}
|
||||||
proxyingChunk -= toappend;
|
proxyingChunk -= toappend;
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
//Make sure the received data ends in a newline (\n).
|
//Make sure the received data ends in a newline (\n).
|
||||||
if ( *(from.Received().get().rbegin()) != '\n'){
|
if ( *(from.Received().get().rbegin()) != '\n'){
|
||||||
if (from.Received().size() > 1){
|
if (from.Received().size() > 1){
|
||||||
|
//make a copy of the first part
|
||||||
std::string tmp = from.Received().get();
|
std::string tmp = from.Received().get();
|
||||||
|
//clear the first part, wiping it from the partlist
|
||||||
from.Received().get().clear();
|
from.Received().get().clear();
|
||||||
|
from.Received().size();
|
||||||
|
//take the now first (was second) part, insert the stored part in front of it
|
||||||
from.Received().get().insert(0, tmp);
|
from.Received().get().insert(0, tmp);
|
||||||
}else{
|
}else{
|
||||||
Util::sleep(100);
|
Util::sleep(100);
|
||||||
|
}
|
||||||
|
if ( *(from.Received().get().rbegin()) != '\n'){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,10 +282,14 @@ void HTTP::Parser::SetVar(std::string i, std::string v){
|
||||||
/// \return True if a whole request or response was read, false otherwise.
|
/// \return True if a whole request or response was read, false otherwise.
|
||||||
bool HTTP::Parser::Read(Socket::Connection & conn){
|
bool HTTP::Parser::Read(Socket::Connection & conn){
|
||||||
//Make sure the received data ends in a newline (\n).
|
//Make sure the received data ends in a newline (\n).
|
||||||
if ( *(conn.Received().get().rbegin()) != '\n'){
|
while ( *(conn.Received().get().rbegin()) != '\n'){
|
||||||
if (conn.Received().size() > 1){
|
if (conn.Received().size() > 1){
|
||||||
|
//make a copy of the first part
|
||||||
std::string tmp = conn.Received().get();
|
std::string tmp = conn.Received().get();
|
||||||
|
//clear the first part, wiping it from the partlist
|
||||||
conn.Received().get().clear();
|
conn.Received().get().clear();
|
||||||
|
conn.Received().size();
|
||||||
|
//take the now first (was second) part, insert the stored part in front of it
|
||||||
conn.Received().get().insert(0, tmp);
|
conn.Received().get().insert(0, tmp);
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue