Browse Source

parse Accept-Language header to Request::accept_languages table

master
Tomasz Sowa 6 months ago
parent
commit
33e8df11c5
  1. 34
      winixd/core/app.cpp
  2. 3
      winixd/core/app.h
  3. 5
      winixd/core/config.cpp
  4. 10
      winixd/core/config.h
  5. 2
      winixd/core/header.h
  6. 1
      winixd/core/request.cpp
  7. 3
      winixd/core/request.h

34
winixd/core/app.cpp

@ -932,23 +932,43 @@ void App::LogEnvironmentHTTPVariables()
}
void App::ParseAcceptHeader()
void App::ParseAcceptHeader(const wchar_t * header_name, const std::wstring & env, std::vector<HeaderValue> & container, size_t max_len)
{
accept_base_parser.parse(cur.request->env_http_accept, cur.request->accept_mime_types, 16);
accept_base_parser.parse(env, container, max_len);
if( !cur.request->accept_mime_types.empty() )
if( !container.empty() )
{
log << log3 << "App: " << Winix::Header::accept << " header consists of: ";
HeaderValue::log_values(cur.request->accept_mime_types, log);
log << log3 << "App: " << header_name << " header consists of: ";
HeaderValue::log_values(container, log);
log << logend;
}
else
{
log << log3 << "App: there is no " << Winix::Header::accept << " header" << logend;
log << log3 << "App: there is no " << header_name << " header" << logend;
}
}
void App::ParseAcceptHeader()
{
ParseAcceptHeader(
Winix::Header::accept,
cur.request->env_http_accept,
cur.request->accept_mime_types,
config.request_max_accept_fields);
}
void App::ParseAcceptLanguageHeader()
{
ParseAcceptHeader(
Winix::Header::accept_language,
cur.request->env_http_accept_language,
cur.request->accept_languages,
config.request_max_accept_language_fields);
}
/*
* reading the request (without GET parameters in the URL)
@ -973,6 +993,7 @@ void App::ReadRequest()
LogEnvironmentHTTPVariables();
ParseAcceptHeader();
ParseAcceptLanguageHeader();
accept_encoding_parser.ParseAndLog(cur.request->env_http_accept_encoding, log);
cookie_parser.Parse(cur.request->env_http_cookie, cur.request->cookie_tab);
@ -1014,6 +1035,7 @@ void App::ReadEnvVariables()
SetEnv("HTTP_COOKIE", cur.request->env_http_cookie);
SetEnv("HTTP_ACCEPT_ENCODING", cur.request->env_http_accept_encoding);
SetEnv("HTTP_ACCEPT", cur.request->env_http_accept);
SetEnv("HTTP_ACCEPT_LANGUAGE", cur.request->env_http_accept_language);
}

3
winixd/core/app.h

@ -54,7 +54,6 @@
#include "cookieparser.h"
#include "postmultiparser.h"
#include "acceptencodingparser.h"
#include "acceptparser.h"
#include "winixrequest.h"
#include "log/log.h"
#include "filelog.h"
@ -240,7 +239,9 @@ private:
void LogEnvironmentVariables();
void LogEnvironmentHTTPVariables();
void ParseAcceptHeader(const wchar_t * header_name, const std::wstring & env, std::vector<HeaderValue> & container, size_t max_len);
void ParseAcceptHeader();
void ParseAcceptLanguageHeader();
void SetEnv(const char * name, std::wstring & env);
void ReadEnvVariables();

5
winixd/core/config.cpp

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2021, Tomasz Sowa
* Copyright (c) 2008-2022, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -295,6 +295,9 @@ void Config::AssignValues(bool stdout_is_closed)
bin_stream_field = Text(L"bin_stream_field", L"bin_stream");
main_stream_field = Text(L"main_stream_field", L"main_stream");
ezc_frames_field = Text(L"ezc_frames_field", L"ezc_frames");
request_max_accept_fields = Size(L"request_max_accept_fields", 8);
request_max_accept_language_fields = Size(L"request_max_accept_language_fields", 8);
account_need_email_verification = Bool(L"account_need_email_verification", true);
reset_password_code_expiration_time = Long(L"reset_password_code_expiration_time", 86400);

10
winixd/core/config.h

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2021, Tomasz Sowa
* Copyright (c) 2008-2022, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -709,6 +709,14 @@ public:
// default: ezc_frames
std::wstring ezc_frames_field;
// max Accept header mime types to be parsed in a request
// default: 8
size_t request_max_accept_fields;
// max Accept-Language languages to be parsed in a request
// default: 8
size_t request_max_accept_language_fields;
// when true then when a user want to create a new account
// he has to provide his email and a message will be sent back to him
// with a link to activate the account

2
winixd/core/header.h

@ -50,12 +50,14 @@ public:
*/
static constexpr const wchar_t * content_type = L"Content-Type";
static constexpr const wchar_t * accept = L"Accept";
static constexpr const wchar_t * accept_language = L"Accept-Language";
/*
* headers' names lower case
*/
static constexpr const wchar_t * content_type_lc = L"content-type";
static constexpr const wchar_t * accept_lc = L"accept";
static constexpr const wchar_t * accept_language_lc = L"accept-language";
/*
* headers' values

1
winixd/core/request.cpp

@ -121,6 +121,7 @@ void Request::Clear()
env_http_user_agent.clear();
env_http_accept_encoding.clear();
env_http_accept.clear();
env_http_accept_language.clear();
env_fcgi_role.clear();
env_content_type.clear();
env_https.clear();

3
winixd/core/request.h

@ -191,6 +191,7 @@ public:
std::wstring env_http_user_agent;
std::wstring env_http_accept_encoding;
std::wstring env_http_accept;
std::wstring env_http_accept_language;
std::wstring env_fcgi_role;
std::wstring env_content_type;
std::wstring env_https;
@ -332,6 +333,8 @@ public:
// at the beginning those with higher priority
std::vector<HeaderValue> accept_mime_types;
// at the beginning those with higher priority
std::vector<HeaderValue> accept_languages;
// request status
// !! CHANGE ME it'll be better to use ordinary http result codes

Loading…
Cancel
Save