| 1 |
/* |
| 2 |
* This File is part of Davix, The IO library for HTTP based protocols |
| 3 |
* Copyright (C) CERN 2019 |
| 4 |
* Author: Georgios Bitzes <[email protected]> |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 2.1 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this library; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef DAVIX_CORE_REDIRECTION_RESOLVER_HPP |
| 23 |
#define DAVIX_CORE_REDIRECTION_RESOLVER_HPP |
| 24 |
|
| 25 |
#include <map> |
| 26 |
#include <set> |
| 27 |
#include <mutex> |
| 28 |
#include <utils/davix_uri.hpp> |
| 29 |
#include <memory> |
| 30 |
#include <libs/alibxx/containers/cache.hpp> |
| 31 |
|
| 32 |
namespace Davix { |
| 33 |
|
| 34 |
class RedirectionResolver { |
| 35 |
public: |
| 36 |
RedirectionResolver(bool active); |
| 37 |
|
| 38 |
// add cached redirection |
| 39 |
void addRedirection(const std::string & method, const Uri & origin, std::shared_ptr<Uri> dest); |
| 40 |
|
| 41 |
// try to find cached redirection, resolve a full redirection chain |
| 42 |
std::shared_ptr<Uri> redirectionResolve(const std::string & method, const Uri & origin); |
| 43 |
|
| 44 |
// check if redirections are active |
| 45 |
bool isActive() const; |
| 46 |
|
| 47 |
// clean redirections |
| 48 |
void redirectionClean(const std::string & method, const Uri & origin); |
| 49 |
void redirectionClean(const Uri & origin); |
| 50 |
|
| 51 |
private: |
| 52 |
using redirectionKey = std::pair<std::string, std::string>; |
| 53 |
|
| 54 |
///< Boolean guarding the redirection cache |
| 55 |
bool active; |
| 56 |
|
| 57 |
///< Redirection pool |
| 58 |
Davix::Cache<redirectionKey, Uri> redirCache; |
| 59 |
|
| 60 |
// resolve a full redirection chain (with redirection loop protection in-place) |
| 61 |
std::shared_ptr<Uri> redirectionResolve(const std::string& method, const Uri& origin, std::set<redirectionKey>& visited); |
| 62 |
|
| 63 |
// resolve a single redirection chunk |
| 64 |
std::shared_ptr<Uri> resolveSingle(const std::string & method, const Uri & origin); |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
#endif |