blob: 6cde13b97764dd5f65bc243441c1e9d98cb27e55 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
/*
* Copyright (C) 2012-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "HTTPImageHandler.h"
#include "URL.h"
#include "filesystem/ImageFile.h"
#include "network/WebServer.h"
#include "utils/FileUtils.h"
CHTTPImageHandler::CHTTPImageHandler(const HTTPRequest &request)
: CHTTPFileHandler(request)
{
std::string file;
int responseStatus = MHD_HTTP_BAD_REQUEST;
// resolve the URL into a file path and a HTTP response status
if (m_request.pathUrl.size() > 7)
{
file = m_request.pathUrl.substr(7);
XFILE::CImageFile imageFile;
const CURL pathToUrl(file);
if (imageFile.Exists(pathToUrl) && CFileUtils::CheckFileAccessAllowed(file))
{
responseStatus = MHD_HTTP_OK;
struct __stat64 statBuffer;
if (imageFile.Stat(pathToUrl, &statBuffer) == 0)
{
SetLastModifiedDate(&statBuffer);
SetCanBeCached(true);
}
}
else
responseStatus = MHD_HTTP_NOT_FOUND;
}
// set the file and the HTTP response status
SetFile(file, responseStatus);
}
bool CHTTPImageHandler::CanHandleRequest(const HTTPRequest &request) const
{
return request.pathUrl.find("/image/") == 0;
}
|