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
113b7842
Commit
113b7842
authored
Aug 20, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http cookie 可以保存更丰富的信息
parent
ae258710
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
9 行增加
和
6 行删除
+9
-6
src/Http/HttpCookieManager.h
+4
-1
src/Http/HttpSession.cpp
+5
-5
没有找到文件。
src/Http/HttpCookieManager.h
查看文件 @
113b7842
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include <memory>
#include <memory>
#include <unordered_map>
#include <unordered_map>
#include "Util/mini.h"
#include "Util/mini.h"
#include "Util/util.h"
#include "Util/TimeTicker.h"
#include "Util/TimeTicker.h"
#include "Network/Socket.h"
#include "Network/Socket.h"
#include "Common/Parser.h"
#include "Common/Parser.h"
...
@@ -47,7 +48,7 @@ class HttpCookieManager;
...
@@ -47,7 +48,7 @@ class HttpCookieManager;
/**
/**
* cookie对象,用于保存cookie的一些相关属性
* cookie对象,用于保存cookie的一些相关属性
*/
*/
class
HttpServerCookie
:
public
map
<
string
,
string
>
,
public
noncopyable
{
class
HttpServerCookie
:
public
AnyStorage
,
public
noncopyable
{
public
:
public
:
typedef
std
::
shared_ptr
<
HttpServerCookie
>
Ptr
;
typedef
std
::
shared_ptr
<
HttpServerCookie
>
Ptr
;
/**
/**
...
@@ -108,6 +109,8 @@ public:
...
@@ -108,6 +109,8 @@ public:
* @return
* @return
*/
*/
std
::
shared_ptr
<
lock_guard
<
mutex
>
>
getLock
();
std
::
shared_ptr
<
lock_guard
<
mutex
>
>
getLock
();
private
:
private
:
string
cookieExpireTime
()
const
;
string
cookieExpireTime
()
const
;
private
:
private
:
...
...
src/Http/HttpSession.cpp
查看文件 @
113b7842
...
@@ -403,7 +403,7 @@ inline void HttpSession::canAccessPath(const string &path_in,bool is_dir,const f
...
@@ -403,7 +403,7 @@ inline void HttpSession::canAccessPath(const string &path_in,bool is_dir,const f
//上次鉴权失败,如果url发生变更,那么也重新鉴权
//上次鉴权失败,如果url发生变更,那么也重新鉴权
if
(
_parser
.
Params
().
empty
()
||
_parser
.
Params
()
==
cookie
->
getUid
())
{
if
(
_parser
.
Params
().
empty
()
||
_parser
.
Params
()
==
cookie
->
getUid
())
{
//url参数未变,那么判断无权限访问
//url参数未变,那么判断无权限访问
callback
(
accessErr
.
empty
()
?
"无权限访问该目录"
:
accessErr
,
nullptr
);
callback
(
accessErr
.
empty
()
?
"无权限访问该目录"
:
accessErr
.
get
<
string
>
()
,
nullptr
);
return
;
return
;
}
}
}
}
...
@@ -427,9 +427,9 @@ inline void HttpSession::canAccessPath(const string &path_in,bool is_dir,const f
...
@@ -427,9 +427,9 @@ inline void HttpSession::canAccessPath(const string &path_in,bool is_dir,const f
//对cookie上锁
//对cookie上锁
auto
lck
=
cookie
->
getLock
();
auto
lck
=
cookie
->
getLock
();
//记录用户能访问的路径
//记录用户能访问的路径
(
*
cookie
)[
kCookiePathKey
]
=
cookie_path
;
(
*
cookie
)[
kCookiePathKey
]
.
set
<
string
>
(
cookie_path
)
;
//记录能否访问
//记录能否访问
(
*
cookie
)[
kAccessErrKey
]
=
errMsg
;
(
*
cookie
)[
kAccessErrKey
]
.
set
<
string
>
(
errMsg
)
;
}
}
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
...
@@ -520,7 +520,7 @@ inline void HttpSession::Handle_Req_GET(int64_t &content_len) {
...
@@ -520,7 +520,7 @@ inline void HttpSession::Handle_Req_GET(int64_t &content_len) {
}
}
auto
headerOut
=
makeHttpHeader
(
bClose
,
strMeun
.
size
());
auto
headerOut
=
makeHttpHeader
(
bClose
,
strMeun
.
size
());
if
(
cookie
){
if
(
cookie
){
headerOut
[
"Set-Cookie"
]
=
cookie
->
getCookie
((
*
cookie
)[
kCookiePathKey
]);
headerOut
[
"Set-Cookie"
]
=
cookie
->
getCookie
((
*
cookie
)[
kCookiePathKey
]
.
get
<
string
>
()
);
}
}
sendResponse
(
errMsg
.
empty
()
?
"200 OK"
:
"401 Unauthorized"
,
headerOut
,
strMeun
);
sendResponse
(
errMsg
.
empty
()
?
"200 OK"
:
"401 Unauthorized"
,
headerOut
,
strMeun
);
throw
SockException
(
bClose
?
Err_shutdown
:
Err_success
,
"close connection after access folder"
);
throw
SockException
(
bClose
?
Err_shutdown
:
Err_success
,
"close connection after access folder"
);
...
@@ -555,7 +555,7 @@ inline void HttpSession::Handle_Req_GET(int64_t &content_len) {
...
@@ -555,7 +555,7 @@ inline void HttpSession::Handle_Req_GET(int64_t &content_len) {
if
(
!
errMsg
.
empty
()){
if
(
!
errMsg
.
empty
()){
auto
headerOut
=
makeHttpHeader
(
bClose
,
errMsg
.
size
());
auto
headerOut
=
makeHttpHeader
(
bClose
,
errMsg
.
size
());
if
(
cookie
){
if
(
cookie
){
headerOut
[
"Set-Cookie"
]
=
cookie
->
getCookie
((
*
cookie
)[
kCookiePathKey
]);
headerOut
[
"Set-Cookie"
]
=
cookie
->
getCookie
((
*
cookie
)[
kCookiePathKey
]
.
get
<
string
>
()
);
}
}
sendResponse
(
"401 Unauthorized"
,
headerOut
,
errMsg
);
sendResponse
(
"401 Unauthorized"
,
headerOut
,
errMsg
);
throw
SockException
(
bClose
?
Err_shutdown
:
Err_success
,
"close connection after access file failed"
);
throw
SockException
(
bClose
?
Err_shutdown
:
Err_success
,
"close connection after access file failed"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论