Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
a44ab25d
Commit
a44ab25d
authored
Nov 30, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
整理http文件服务器相关代码
parent
ee528b2b
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
81 行增加
和
50 行删除
+81
-50
src/Http/HttpFileManager.cpp
+0
-0
src/Http/HttpFileManager.h
+80
-0
src/Http/HttpSession.cpp
+0
-0
src/Http/HttpSession.h
+1
-50
没有找到文件。
src/Http/HttpFileManager.cpp
0 → 100644
查看文件 @
a44ab25d
差异被折叠。
点击展开。
src/Http/HttpFileManager.h
0 → 100644
查看文件 @
a44ab25d
/*
* MIT License
*
* Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef ZLMEDIAKIT_HTTPFILEMANAGER_H
#define ZLMEDIAKIT_HTTPFILEMANAGER_H
#include "HttpBody.h"
#include "HttpCookie.h"
#include "Common/Parser.h"
#include "Network/TcpSession.h"
#include "Util/function_traits.h"
namespace
mediakit
{
class
HttpResponseInvokerImp
{
public
:
typedef
std
::
function
<
void
(
const
string
&
codeOut
,
const
StrCaseMap
&
headerOut
,
const
HttpBody
::
Ptr
&
body
)
>
HttpResponseInvokerLambda0
;
typedef
std
::
function
<
void
(
const
string
&
codeOut
,
const
StrCaseMap
&
headerOut
,
const
string
&
body
)
>
HttpResponseInvokerLambda1
;
HttpResponseInvokerImp
(){}
~
HttpResponseInvokerImp
(){}
template
<
typename
C
>
HttpResponseInvokerImp
(
const
C
&
c
)
:
HttpResponseInvokerImp
(
typename
function_traits
<
C
>::
stl_function_type
(
c
))
{}
HttpResponseInvokerImp
(
const
HttpResponseInvokerLambda0
&
lambda
);
HttpResponseInvokerImp
(
const
HttpResponseInvokerLambda1
&
lambda
);
void
operator
()(
const
string
&
codeOut
,
const
StrCaseMap
&
headerOut
,
const
HttpBody
::
Ptr
&
body
)
const
;
void
operator
()(
const
string
&
codeOut
,
const
StrCaseMap
&
headerOut
,
const
string
&
body
)
const
;
void
responseFile
(
const
StrCaseMap
&
requestHeader
,
const
StrCaseMap
&
responseHeader
,
const
string
&
filePath
)
const
;
operator
bool
();
private
:
HttpResponseInvokerLambda0
_lambad
;
};
/**
* 该对象用于控制http静态文件夹服务器的访问权限
*/
class
HttpFileManager
{
public
:
typedef
function
<
void
(
const
string
&
status_code
,
const
string
&
content_type
,
const
StrCaseMap
&
responseHeader
,
const
HttpBody
::
Ptr
&
body
)
>
invoker
;
/**
* 访问文件或文件夹
* @param sender 事件触发者
* @param parser http请求
* @param cb 回调对象
*/
static
void
onAccessPath
(
TcpSession
&
sender
,
Parser
&
parser
,
const
invoker
&
cb
);
private
:
HttpFileManager
()
=
delete
;
~
HttpFileManager
()
=
delete
;
};
}
#endif //ZLMEDIAKIT_HTTPFILEMANAGER_H
src/Http/HttpSession.cpp
查看文件 @
a44ab25d
差异被折叠。
点击展开。
src/Http/HttpSession.h
查看文件 @
a44ab25d
...
...
@@ -27,46 +27,19 @@
#define SRC_HTTP_HTTPSESSION_H_
#include <functional>
#include "Common/config.h"
#include "Common/Parser.h"
#include "Network/TcpSession.h"
#include "Network/TcpServer.h"
#include "Rtmp/RtmpMediaSource.h"
#include "Rtmp/FlvMuxer.h"
#include "HttpRequestSplitter.h"
#include "WebSocketSplitter.h"
#include "HttpCookieManager.h"
#include "HttpBody.h"
#include "Util/function_traits.h"
#include "HttpFileManager.h"
using
namespace
std
;
using
namespace
toolkit
;
namespace
mediakit
{
/**
* 该类实现与老代码的兼容适配
*/
class
HttpResponseInvokerImp
{
public
:
typedef
std
::
function
<
void
(
const
string
&
codeOut
,
const
StrCaseMap
&
headerOut
,
const
HttpBody
::
Ptr
&
body
)
>
HttpResponseInvokerLambda0
;
typedef
std
::
function
<
void
(
const
string
&
codeOut
,
const
StrCaseMap
&
headerOut
,
const
string
&
body
)
>
HttpResponseInvokerLambda1
;
HttpResponseInvokerImp
(){}
~
HttpResponseInvokerImp
(){}
template
<
typename
C
>
HttpResponseInvokerImp
(
const
C
&
c
)
:
HttpResponseInvokerImp
(
typename
function_traits
<
C
>::
stl_function_type
(
c
))
{}
HttpResponseInvokerImp
(
const
HttpResponseInvokerLambda0
&
lambda
);
HttpResponseInvokerImp
(
const
HttpResponseInvokerLambda1
&
lambda
);
void
operator
()(
const
string
&
codeOut
,
const
StrCaseMap
&
headerOut
,
const
HttpBody
::
Ptr
&
body
)
const
;
void
operator
()(
const
string
&
codeOut
,
const
StrCaseMap
&
headerOut
,
const
string
&
body
)
const
;
void
responseFile
(
const
StrCaseMap
&
requestHeader
,
const
StrCaseMap
&
responseHeader
,
const
string
&
filePath
)
const
;
operator
bool
();
private
:
HttpResponseInvokerLambda0
_lambad
;
};
class
HttpSession
:
public
TcpSession
,
public
FlvMuxer
,
public
HttpRequestSplitter
,
...
...
@@ -88,9 +61,7 @@ public:
virtual
void
onRecv
(
const
Buffer
::
Ptr
&
)
override
;
virtual
void
onError
(
const
SockException
&
err
)
override
;
virtual
void
onManager
()
override
;
static
string
urlDecode
(
const
string
&
str
);
static
const
char
*
get_mime_type
(
const
char
*
name
);
protected
:
//FlvMuxer override
void
onWrite
(
const
Buffer
::
Ptr
&
data
)
override
;
...
...
@@ -145,26 +116,6 @@ private:
void
sendResponse
(
const
char
*
pcStatus
,
bool
bClose
,
const
char
*
pcContentType
=
nullptr
,
const
HttpSession
::
KeyValue
&
header
=
HttpSession
::
KeyValue
(),
const
HttpBody
::
Ptr
&
body
=
nullptr
,
bool
set_content_len
=
true
);
/**
* 判断http客户端是否有权限访问文件的逻辑步骤
*
* 1、根据http请求头查找cookie,找到进入步骤3
* 2、根据http url参数(如果没有根据ip+端口号)查找cookie,如果还是未找到cookie则进入步骤5
* 3、cookie标记是否有权限访问文件,如果有权限,直接返回文件
* 4、cookie中记录的url参数是否跟本次url参数一致,如果一致直接返回客户端错误码
* 5、触发kBroadcastHttpAccess事件
* @param path 文件或目录
* @param is_dir path是否为目录
* @param callback 有权限或无权限的回调
*/
void
canAccessPath
(
const
string
&
path
,
bool
is_dir
,
const
function
<
void
(
const
string
&
errMsg
,
const
HttpServerCookie
::
Ptr
&
cookie
)
>
&
callback
);
/**
* 获取用户唯一识别id
* 有url参数返回参数,无参数返回ip+端口号
* @return
*/
string
getClientUid
();
//设置socket标志
void
setSocketFlags
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论