From bcd246076540a8353fa55fc0a5e19343c1a2dbc9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 14 Aug 2015 13:03:08 +0200 Subject: Implement package search service mockup --- web/apache/request | 12 ++--- web/apache/request.cxx | 125 ++++++++----------------------------------------- 2 files changed, 26 insertions(+), 111 deletions(-) (limited to 'web/apache') diff --git a/web/apache/request b/web/apache/request index 59d4600..88b38a9 100644 --- a/web/apache/request +++ b/web/apache/request @@ -43,6 +43,11 @@ namespace web int flush (); + // Get request path. + // + virtual const path_type& + path (); + // Get request body data stream. // virtual std::istream& @@ -93,12 +98,6 @@ namespace web void parse_parameters (const char* args); - static void - mime_url_encode (const char* v, std::ostream& o); - - static std::string - mime_url_decode (const char* b, const char* e, bool trim = false); - bool get_write_state () const noexcept {return write_state_;} @@ -129,6 +128,7 @@ namespace web std::unique_ptr out_; std::unique_ptr in_buf_; std::unique_ptr in_; + path_type path_; std::unique_ptr parameters_; std::unique_ptr cookies_; std::unique_ptr form_data_; diff --git a/web/apache/request.cxx b/web/apache/request.cxx index 7727b35..497d2d6 100644 --- a/web/apache/request.cxx +++ b/web/apache/request.cxx @@ -14,18 +14,20 @@ #include // unique_ptr #include #include +#include #include #include // move() #include #include +#include + using namespace std; namespace web { namespace apache { - istream& request:: content () { @@ -46,10 +48,25 @@ namespace web return *in_; } + const path& request:: + path () + { + if (path_.empty ()) + { + path_ = path_type (rec_->uri); + + // Module request handler can not be called if URI is empty. + // + assert (!path_.empty ()); + } + + return path_; + } + const name_values& request:: parameters () { - if (!parameters_) + if (parameters_ == nullptr) { parameters_.reset (new name_values ()); @@ -70,7 +87,7 @@ namespace web const name_values& request:: cookies () { - if (!cookies_) + if (cookies_ == nullptr) { cookies_.reset (new name_values ()); @@ -264,107 +281,5 @@ namespace web n = e ? e + 1 : 0; } } - - void request:: - mime_url_encode (const char* v, ostream& o) - { - char f (o.fill ()); - ios_base::fmtflags g (o.flags ()); - o << hex << uppercase << right << setfill ('0'); - - char c; - - while ((c = *v++) != '\0') - { - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || - (c >= '0' && c <= '9')) - { - o << c; - } - else - switch (c) - { - case ' ': o << '+'; break; - case '.': - case '_': - case '-': - case '~': o << c; break; - default: - { - o << "%" << setw (2) << static_cast (c); - break; - } - } - } - - o.flags (g); - o.fill (f); - } - - string request:: - mime_url_decode (const char* b, const char* e, bool trim) - { - if (trim) - { - b += strspn (b, " "); - - if (b >= e) - return string (); - - while (*--e == ' '); - ++e; - } - - string value; - value.reserve (e - b); - - char bf[3]; - bf[2] = '\0'; - - while (b != e) - { - char c (*b++); - - switch (c) - { - case '+': - { - value.append (" "); - break; - } - case '%': - { - if (*b == '\0' || b[1] == '\0') - { - throw invalid_argument ( - "::web::apache::request::mime_url_decode short"); - } - - *bf = *b; - bf[1] = b[1]; - - char* ebf (nullptr); - size_t vl (strtoul (bf, &ebf, 16)); - - if (*ebf != '\0') - { - throw invalid_argument ( - "::web::apache::request::mime_url_decode wrong"); - } - - value.append (1, static_cast (vl)); - b += 2; - break; - } - default: - { - value.append (1, c); - break; - } - } - } - - return value; - } } } -- cgit v1.1