| 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_BACKEND_STANDALONE_REQUEST_HPP |
| 23 |
#define DAVIX_BACKEND_STANDALONE_REQUEST_HPP |
| 24 |
|
| 25 |
#include <string> |
| 26 |
#include <status/DavixStatus.hpp> |
| 27 |
|
| 28 |
namespace Davix { |
| 29 |
|
| 30 |
class Uri; |
| 31 |
|
| 32 |
//------------------------------------------------------------------------------ |
| 33 |
// Describe current request state. |
| 34 |
//------------------------------------------------------------------------------ |
| 35 |
enum class RequestState { |
| 36 |
kNotStarted = 0, // request object has been constructed, |
| 37 |
// but startRequest has not been called yet |
| 38 |
|
| 39 |
kStarted, // startRequest has been called |
| 40 |
|
| 41 |
kFinished // request is done, session has been released |
| 42 |
}; |
| 43 |
|
| 44 |
//------------------------------------------------------------------------------ |
| 45 |
// Abstract StandaloneRequest class. Represents a simple, no-magic HTTP request. |
| 46 |
// No redirects, request signing or any other extra features. |
| 47 |
//------------------------------------------------------------------------------ |
| 48 |
class StandaloneRequest { |
| 49 |
public: |
| 50 |
//---------------------------------------------------------------------------- |
| 51 |
// Virtual destructor |
| 52 |
//---------------------------------------------------------------------------- |
| 53 |
virtual ~StandaloneRequest() {} |
| 54 |
|
| 55 |
//---------------------------------------------------------------------------- |
| 56 |
// Get a specific response header |
| 57 |
//---------------------------------------------------------------------------- |
| 58 |
virtual bool getAnswerHeader(const std::string &header_name, std::string &value) const = 0; |
| 59 |
|
| 60 |
//---------------------------------------------------------------------------- |
| 61 |
// Get all response headers |
| 62 |
//---------------------------------------------------------------------------- |
| 63 |
virtual size_t getAnswerHeaders(std::vector<std::pair<std::string, std::string > > & vec_headers) const = 0; |
| 64 |
|
| 65 |
//---------------------------------------------------------------------------- |
| 66 |
// Start request - calling this more than once will not have any effect. |
| 67 |
//---------------------------------------------------------------------------- |
| 68 |
virtual Status startRequest() = 0; |
| 69 |
|
| 70 |
//---------------------------------------------------------------------------- |
| 71 |
// Finish an already started request. |
| 72 |
//---------------------------------------------------------------------------- |
| 73 |
virtual Status endRequest() = 0; |
| 74 |
|
| 75 |
//---------------------------------------------------------------------------- |
| 76 |
// Major read function - read a block of max_size bytes (at max) into buffer. |
| 77 |
//---------------------------------------------------------------------------- |
| 78 |
virtual dav_ssize_t readBlock(char* buffer, dav_size_t max_size, Status& st) = 0; |
| 79 |
|
| 80 |
//---------------------------------------------------------------------------- |
| 81 |
// Check request state |
| 82 |
//---------------------------------------------------------------------------- |
| 83 |
virtual RequestState getState() const = 0; |
| 84 |
|
| 85 |
//---------------------------------------------------------------------------- |
| 86 |
// Get status code - returns 0 if impossible to determine |
| 87 |
//---------------------------------------------------------------------------- |
| 88 |
virtual int getStatusCode() const = 0; |
| 89 |
|
| 90 |
//---------------------------------------------------------------------------- |
| 91 |
// Do not re-use underlying session |
| 92 |
//---------------------------------------------------------------------------- |
| 93 |
virtual void doNotReuseSession() = 0; |
| 94 |
|
| 95 |
//---------------------------------------------------------------------------- |
| 96 |
// Has the underlying session been used before? |
| 97 |
//---------------------------------------------------------------------------- |
| 98 |
virtual bool isRecycledSession() const = 0; |
| 99 |
|
| 100 |
//---------------------------------------------------------------------------- |
| 101 |
// Obtain redirected location, store into the given Uri |
| 102 |
//---------------------------------------------------------------------------- |
| 103 |
virtual Status obtainRedirectedLocation(Uri &out) = 0; |
| 104 |
|
| 105 |
//---------------------------------------------------------------------------- |
| 106 |
// Get session error, if available |
| 107 |
//---------------------------------------------------------------------------- |
| 108 |
virtual std::string getSessionError() const = 0; |
| 109 |
|
| 110 |
//---------------------------------------------------------------------------- |
| 111 |
// Get the standalone request type name |
| 112 |
//---------------------------------------------------------------------------- |
| 113 |
virtual inline std::string getName() const { |
| 114 |
return name; |
| 115 |
}; |
| 116 |
|
| 117 |
protected: |
| 118 |
/// Standalone request type name |
| 119 |
std::string name; |
| 120 |
}; |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
#endif |