kodi
HTTPPythonHandler.h
1 /*
2  * Copyright (C) 2015-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "XBDateTime.h"
12 #include "addons/IAddon.h"
13 #include "addons/Webinterface.h"
14 #include "network/httprequesthandler/IHTTPRequestHandler.h"
15 
17 {
18 public:
20  ~CHTTPPythonHandler() override = default;
21 
22  IHTTPRequestHandler* Create(const HTTPRequest &request) const override { return new CHTTPPythonHandler(request); }
23  bool CanHandleRequest(const HTTPRequest &request) const override;
24  bool CanHandleRanges() const override { return false; }
25  bool CanBeCached() const override { return false; }
26  bool GetLastModifiedDate(CDateTime &lastModified) const override;
27 
28  MHD_RESULT HandleRequest() override;
29 
30  HttpResponseRanges GetResponseData() const override { return m_responseRanges; }
31 
32  std::string GetRedirectUrl() const override { return m_redirectUrl; }
33 
34  int GetPriority() const override { return 3; }
35 
36 protected:
37  explicit CHTTPPythonHandler(const HTTPRequest &request);
38 
39  bool appendPostData(const char *data, size_t size) override;
40 
41 private:
42  std::string m_scriptPath;
43  ADDON::AddonPtr m_addon;
44  CDateTime m_lastModified;
45 
46  std::string m_requestData;
47  std::string m_responseData;
48  HttpResponseRanges m_responseRanges;
49 
50  std::string m_redirectUrl;
51 };
Definition: IHTTPRequestHandler.h:66
bool GetLastModifiedDate(CDateTime &lastModified) const override
Returns the last modification date of the response data.
Definition: HTTPPythonHandler.cpp:227
IHTTPRequestHandler * Create(const HTTPRequest &request) const override
Creates a new HTTP request handler for the given request.
Definition: HTTPPythonHandler.h:22
bool CanHandleRanges() const override
Whether the HTTP response could also be provided in ranges.
Definition: HTTPPythonHandler.h:24
Definition: HTTPPythonHandler.h:16
HttpResponseRanges GetResponseData() const override
Returns the ranges with raw data belonging to the response.
Definition: HTTPPythonHandler.h:30
DateTime class, which uses FileTime as it's base.
Definition: XBDateTime.h:63
std::string GetRedirectUrl() const override
Returns the URL to which the request should be redirected.
Definition: HTTPPythonHandler.h:32
MHD_RESULT HandleRequest() override
Handles the HTTP request.
Definition: HTTPPythonHandler.cpp:119
int GetPriority() const override
Returns the priority of the HTTP request handler.
Definition: HTTPPythonHandler.h:34
bool CanBeCached() const override
Whether the HTTP response can be cached.
Definition: HTTPPythonHandler.h:25
Definition: IHTTPRequestHandler.h:85
bool CanHandleRequest(const HTTPRequest &request) const override
Checks if the HTTP request handler can handle the given request.
Definition: HTTPPythonHandler.cpp:102