added: Request::post_in (PT::Space) for input when application/json content type is used

from the client




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1102 e52654a7-88a9-db11-a3e9-0013d4bc506e
pull/3/head
Tomasz Sowa 5 years ago
parent ca14b1a427
commit 6252a0e732

@ -114,6 +114,7 @@ app.o: ../../../winix/winixd/templates/htmltextstream.h
app.o: ../../../winix/winixd/core/sessionmanager.h compress.h postparser.h
app.o: httpsimpleparser.h plugin.h pluginmsg.h cookieparser.h
app.o: postmultiparser.h acceptencodingparser.h acceptbaseparser.h
app.o: ../../../pikotools/space/jsontospaceparser.h
basethread.o: basethread.h synchro.h
bbcodeparser.o: bbcodeparser.h htmlfilter.h
compress.o: compress.h requesttypes.h

@ -949,9 +949,48 @@ void App::LogAccess()
void App::ReadPostJson()
{
char buffer[1024];
const int buffer_len = sizeof(buffer) / sizeof(char) - 1;
int read_len;
post_json_parser.SetSpace(cur.request->post_in);
post_buffer.clear();
post_buffer.reserve(1024 * 1024 * 5); // IMPROVEME add to config?
cur.request->is_postin_used = true;
do
{
// IMPROVE ME
// we can read to PT::TextBuffer and make a PT::JSONToSpaceParser::Parse(PT::TextBuffer &) method
read_len = FCGX_GetStr(buffer, buffer_len, fcgi_request.in);
if( read_len > 0 )
post_buffer.append(buffer, read_len);
}
while( read_len == buffer_len );
PT::JSONToSpaceParser::Status status = post_json_parser.ParseString(post_buffer.c_str());
post_buffer.clear();
if( status != PT::JSONToSpaceParser::ok )
{
log << log1 << "App: cannot parse the input stream as a JSON object, status: " << (int)status << logend;
cur.request->post_in.Clear();
// return an error (http error of some kind?)
}
}
void App::ReadPostVars()
{
if( cur.request->method == Request::post )
// CHECKME
// what about errors during parsing input?
if( cur.request->method == Request::post || cur.request->method == Request::delete_ )
{
if( IsSubStringNoCase(L"multipart/form-data", cur.request->env_content_type.c_str()) )
{
@ -959,7 +998,14 @@ void App::ReadPostVars()
post_multi_parser.Parse(fcgi_request.in, cur.request->post_tab, cur.request->post_file_tab);
}
else
if( IsSubStringNoCase(L"application/json", cur.request->env_content_type.c_str()) )
{
log << log3 << "App: post content type: application/json" << logend;
ReadPostJson();
}
else
{
// IMPROVE ME may to check a correct content-type header?
post_parser.Parse(fcgi_request.in, cur.request->post_tab);
}
}

@ -59,7 +59,7 @@
#include "cookieparser.h"
#include "postmultiparser.h"
#include "acceptencodingparser.h"
#include "space/jsontospaceparser.h"
namespace Winix
@ -140,6 +140,9 @@ private:
PostParser post_parser;
PostMultiParser post_multi_parser;
PT::JSONToSpaceParser post_json_parser;
std::string post_buffer;
CookieParser cookie_parser;
AcceptEncodingParser accept_encoding_parser;
Compress compress;
@ -191,6 +194,7 @@ private:
void ReadEnvHTTPVariables();
bool SaveEnvHTTPVariable(const char * env);
void ReadEnvRemoteIP();
void ReadPostJson();
void ReadPostVars();
void CheckIE();

@ -93,6 +93,8 @@ void Request::Clear()
post_tab.clear();
post_file_tab.clear();
cookie_tab.clear();
post_in.Clear();
is_postin_used = false;
method = unknown_method;

@ -125,6 +125,8 @@ struct Request
PostTab post_tab;
PostFileTab post_file_tab;
CookieTab cookie_tab;
PT::Space post_in;
bool is_postin_used;// temporarily, before all post variables will be put to post_in
// input headers (without cookies)
// at the moment we are using FastCGI and HTTP headers are prefixed with 'HTTP_' string

@ -145,5 +145,6 @@ main.o: ../../../winix/winixd/core/cookieparser.h
main.o: ../../../winix/winixd/core/postmultiparser.h
main.o: ../../../winix/winixd/core/acceptencodingparser.h
main.o: ../../../winix/winixd/core/acceptbaseparser.h
main.o: ../../../pikotools/space/jsontospaceparser.h
main.o: ../../../winix/winixd/core/plugin.h
main.o: ../../../winix/winixd/core/version.h

Loading…
Cancel
Save