2019-08-08 19:01:45 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2020-04-04 20:30:09 +08:00
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by MIT license that can be found in the
|
|
|
|
|
* LICENSE file in the root of the source tree. All contributing project authors
|
|
|
|
|
* may be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
2017-05-05 18:02:54 +08:00
|
|
|
|
|
2019-01-16 14:26:06 +08:00
|
|
|
|
#include <cstdlib>
|
2021-12-17 17:48:05 +08:00
|
|
|
|
#include "Util/base64.h"
|
2017-05-05 18:02:54 +08:00
|
|
|
|
#include "HttpClient.h"
|
2019-06-28 16:48:02 +08:00
|
|
|
|
#include "Common/config.h"
|
2017-05-05 18:02:54 +08:00
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
namespace mediakit {
|
2017-05-05 18:02:54 +08:00
|
|
|
|
|
2018-09-23 21:10:17 +08:00
|
|
|
|
void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) {
|
2018-06-21 14:03:43 +08:00
|
|
|
|
_aliveTicker.resetTime();
|
2019-07-01 18:35:26 +08:00
|
|
|
|
_url = strUrl;
|
2018-09-23 21:10:17 +08:00
|
|
|
|
auto protocol = FindField(strUrl.data(), NULL, "://");
|
2017-05-05 18:02:54 +08:00
|
|
|
|
uint16_t defaultPort;
|
|
|
|
|
bool isHttps;
|
2018-11-27 11:05:44 +08:00
|
|
|
|
if (strcasecmp(protocol.data(), "http") == 0) {
|
2017-05-05 18:02:54 +08:00
|
|
|
|
defaultPort = 80;
|
|
|
|
|
isHttps = false;
|
2018-11-27 11:05:44 +08:00
|
|
|
|
} else if (strcasecmp(protocol.data(), "https") == 0) {
|
2017-05-05 18:02:54 +08:00
|
|
|
|
defaultPort = 443;
|
|
|
|
|
isHttps = true;
|
2018-09-23 21:10:17 +08:00
|
|
|
|
} else {
|
2021-10-13 20:56:22 +08:00
|
|
|
|
auto strErr = StrPrinter << "非法的http url:" << strUrl << endl;
|
2017-05-05 18:02:54 +08:00
|
|
|
|
throw std::invalid_argument(strErr);
|
|
|
|
|
}
|
2018-09-23 21:10:17 +08:00
|
|
|
|
|
2017-05-05 18:02:54 +08:00
|
|
|
|
auto host = FindField(strUrl.data(), "://", "/");
|
|
|
|
|
if (host.empty()) {
|
|
|
|
|
host = FindField(strUrl.data(), "://", NULL);
|
|
|
|
|
}
|
|
|
|
|
_path = FindField(strUrl.data(), host.data(), NULL);
|
|
|
|
|
if (_path.empty()) {
|
|
|
|
|
_path = "/";
|
|
|
|
|
}
|
2021-12-17 17:48:05 +08:00
|
|
|
|
auto pos = host.find('@');
|
|
|
|
|
if (pos != string::npos) {
|
|
|
|
|
//去除?后面的字符串
|
|
|
|
|
auto authStr = host.substr(0, pos);
|
|
|
|
|
host = host.substr(pos + 1, host.size());
|
|
|
|
|
_header.emplace("Authorization", "Basic " + encodeBase64(authStr));
|
|
|
|
|
}
|
2020-11-21 22:16:58 +08:00
|
|
|
|
auto host_header = host;
|
2019-01-03 15:05:52 +08:00
|
|
|
|
uint16_t port = atoi(FindField(host.data(), ":", NULL).data());
|
2017-05-05 18:02:54 +08:00
|
|
|
|
if (port <= 0) {
|
|
|
|
|
//默认端口
|
|
|
|
|
port = defaultPort;
|
|
|
|
|
} else {
|
|
|
|
|
//服务器域名
|
|
|
|
|
host = FindField(host.data(), NULL, ":");
|
|
|
|
|
}
|
2020-11-21 22:16:58 +08:00
|
|
|
|
_header.emplace("Host", host_header);
|
2021-10-16 16:58:03 +08:00
|
|
|
|
_header.emplace("Tools", kServerName);
|
2019-06-13 18:39:57 +08:00
|
|
|
|
_header.emplace("Connection", "keep-alive");
|
|
|
|
|
_header.emplace("Accept", "*/*");
|
|
|
|
|
_header.emplace("Accept-Language", "zh-CN,zh;q=0.8");
|
2021-09-30 16:10:09 +08:00
|
|
|
|
_header.emplace("User-Agent",
|
|
|
|
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36");
|
2018-09-23 21:10:17 +08:00
|
|
|
|
|
|
|
|
|
if (_body && _body->remainSize()) {
|
2019-06-13 18:39:57 +08:00
|
|
|
|
_header.emplace("Content-Length", to_string(_body->remainSize()));
|
|
|
|
|
_header.emplace("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
2017-05-05 18:02:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool bChanged = (_lastHost != host + ":" + to_string(port)) || (_isHttps != isHttps);
|
|
|
|
|
_lastHost = host + ":" + to_string(port);
|
|
|
|
|
_isHttps = isHttps;
|
2018-06-21 14:03:43 +08:00
|
|
|
|
_fTimeOutSec = fTimeOutSec;
|
2018-09-24 00:50:02 +08:00
|
|
|
|
|
2021-09-30 16:10:09 +08:00
|
|
|
|
auto cookies = HttpCookieStorage::Instance().get(_lastHost, _path);
|
2018-09-24 00:50:02 +08:00
|
|
|
|
_StrPrinter printer;
|
2021-09-30 16:10:09 +08:00
|
|
|
|
for (auto &cookie : cookies) {
|
2018-09-24 00:50:02 +08:00
|
|
|
|
printer << cookie->getKey() << "=" << cookie->getVal() << ";";
|
|
|
|
|
}
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (!printer.empty()) {
|
2018-09-24 00:50:02 +08:00
|
|
|
|
printer.pop_back();
|
2019-06-13 18:39:57 +08:00
|
|
|
|
_header.emplace("Cookie", printer);
|
2018-09-24 00:50:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-23 21:10:17 +08:00
|
|
|
|
if (!alive() || bChanged) {
|
|
|
|
|
startConnect(host, port, fTimeOutSec);
|
|
|
|
|
} else {
|
2017-05-05 18:02:54 +08:00
|
|
|
|
SockException ex;
|
2021-12-22 11:33:40 +08:00
|
|
|
|
onConnect_l(ex);
|
2017-05-05 18:02:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-30 16:10:09 +08:00
|
|
|
|
void HttpClient::clear() {
|
2021-12-22 11:33:40 +08:00
|
|
|
|
_url.clear();
|
2021-09-30 16:10:09 +08:00
|
|
|
|
_header.clear();
|
|
|
|
|
_body.reset();
|
|
|
|
|
_method.clear();
|
|
|
|
|
_path.clear();
|
|
|
|
|
_aliveTicker.resetTime();
|
|
|
|
|
_chunkedSplitter.reset();
|
2021-12-22 11:33:40 +08:00
|
|
|
|
_fTimeOutSec = 0;
|
|
|
|
|
clearResponse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpClient::clearResponse() {
|
|
|
|
|
_recvedBodySize = 0;
|
|
|
|
|
_totalBodySize = 0;
|
|
|
|
|
_parser.Clear();
|
|
|
|
|
_chunkedSplitter = nullptr;
|
2021-09-30 16:10:09 +08:00
|
|
|
|
HttpRequestSplitter::reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpClient::setMethod(string method) {
|
|
|
|
|
_method = std::move(method);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpClient::setHeader(HttpHeader header) {
|
|
|
|
|
_header = std::move(header);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HttpClient &HttpClient::addHeader(string key, string val, bool force) {
|
|
|
|
|
if (!force) {
|
|
|
|
|
_header.emplace(std::move(key), std::move(val));
|
|
|
|
|
} else {
|
|
|
|
|
_header[std::move(key)] = std::move(val);
|
|
|
|
|
}
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpClient::setBody(string body) {
|
|
|
|
|
_body.reset(new HttpStringBody(std::move(body)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpClient::setBody(HttpBody::Ptr body) {
|
|
|
|
|
_body = std::move(body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Parser &HttpClient::response() const {
|
|
|
|
|
return _parser;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const string &HttpClient::getUrl() const {
|
|
|
|
|
return _url;
|
|
|
|
|
}
|
2017-05-05 18:02:54 +08:00
|
|
|
|
|
2018-09-23 21:10:17 +08:00
|
|
|
|
void HttpClient::onConnect(const SockException &ex) {
|
2021-12-22 11:33:40 +08:00
|
|
|
|
onConnect_l(ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpClient::onConnect_l(const SockException &ex) {
|
2018-06-21 14:03:43 +08:00
|
|
|
|
_aliveTicker.resetTime();
|
2018-09-23 21:10:17 +08:00
|
|
|
|
if (ex) {
|
|
|
|
|
onDisconnect(ex);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-22 11:33:40 +08:00
|
|
|
|
clearResponse();
|
2018-09-23 21:10:17 +08:00
|
|
|
|
|
2018-06-21 14:03:43 +08:00
|
|
|
|
_StrPrinter printer;
|
|
|
|
|
printer << _method + " " << _path + " HTTP/1.1\r\n";
|
2017-05-05 18:02:54 +08:00
|
|
|
|
for (auto &pr : _header) {
|
2018-09-23 21:10:17 +08:00
|
|
|
|
printer << pr.first + ": ";
|
2018-06-21 14:03:43 +08:00
|
|
|
|
printer << pr.second + "\r\n";
|
2017-05-05 18:02:54 +08:00
|
|
|
|
}
|
2020-04-23 17:50:12 +08:00
|
|
|
|
SockSender::send(printer << "\r\n");
|
2019-05-29 18:08:50 +08:00
|
|
|
|
onFlush();
|
2017-05-05 18:02:54 +08:00
|
|
|
|
}
|
2018-09-23 21:10:17 +08:00
|
|
|
|
|
|
|
|
|
void HttpClient::onRecv(const Buffer::Ptr &pBuf) {
|
|
|
|
|
_aliveTicker.resetTime();
|
2019-03-27 10:01:18 +08:00
|
|
|
|
HttpRequestSplitter::input(pBuf->data(), pBuf->size());
|
2017-05-05 18:02:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-23 21:10:17 +08:00
|
|
|
|
void HttpClient::onErr(const SockException &ex) {
|
2018-11-13 22:50:43 +08:00
|
|
|
|
if (ex.getErrCode() == Err_eof && _totalBodySize < 0) {
|
2018-06-21 14:03:43 +08:00
|
|
|
|
//如果Content-Length未指定 但服务器断开链接
|
|
|
|
|
//则认为本次http请求完成
|
2018-09-23 21:10:17 +08:00
|
|
|
|
onResponseCompleted_l();
|
2018-06-21 14:03:43 +08:00
|
|
|
|
}
|
2018-09-23 21:10:17 +08:00
|
|
|
|
onDisconnect(ex);
|
2017-05-05 18:02:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-19 16:05:38 +08:00
|
|
|
|
ssize_t HttpClient::onRecvHeader(const char *data, size_t len) {
|
2018-09-23 21:10:17 +08:00
|
|
|
|
_parser.Parse(data);
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (_parser.Url() == "302" || _parser.Url() == "301") {
|
2019-07-01 09:53:58 +08:00
|
|
|
|
auto newUrl = _parser["Location"];
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (newUrl.empty()) {
|
|
|
|
|
shutdown(SockException(Err_shutdown, "未找到Location字段(跳转url)"));
|
2019-07-01 09:53:58 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (onRedirectUrl(newUrl, _parser.Url() == "302")) {
|
2019-07-01 20:55:31 +08:00
|
|
|
|
HttpClient::clear();
|
|
|
|
|
setMethod("GET");
|
2021-09-30 16:10:09 +08:00
|
|
|
|
HttpClient::sendRequest(newUrl, _fTimeOutSec);
|
2019-07-01 20:55:31 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-07-01 09:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 18:13:45 +08:00
|
|
|
|
checkCookie(_parser.getHeader());
|
|
|
|
|
_totalBodySize = onResponseHeader(_parser.Url(), _parser.getHeader());
|
2018-09-23 21:10:17 +08:00
|
|
|
|
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (!_parser["Content-Length"].empty()) {
|
2018-11-13 22:50:43 +08:00
|
|
|
|
//有Content-Length字段时忽略onResponseHeader的返回值
|
|
|
|
|
_totalBodySize = atoll(_parser["Content-Length"].data());
|
2018-09-23 21:10:17 +08:00
|
|
|
|
}
|
2018-09-23 21:19:24 +08:00
|
|
|
|
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (_parser["Transfer-Encoding"] == "chunked") {
|
2018-11-13 23:59:06 +08:00
|
|
|
|
//如果Transfer-Encoding字段等于chunked,则认为后续的content是不限制长度的
|
|
|
|
|
_totalBodySize = -1;
|
2021-09-30 16:10:09 +08:00
|
|
|
|
_chunkedSplitter = std::make_shared<HttpChunkedSplitter>([this](const char *data, size_t len) {
|
|
|
|
|
if (len > 0) {
|
2018-11-13 23:59:06 +08:00
|
|
|
|
auto recvedBodySize = _recvedBodySize + len;
|
2021-01-19 16:05:38 +08:00
|
|
|
|
onResponseBody(data, len, recvedBodySize, SIZE_MAX);
|
2018-11-13 23:59:06 +08:00
|
|
|
|
_recvedBodySize = recvedBodySize;
|
2021-09-30 16:10:09 +08:00
|
|
|
|
} else {
|
2018-11-13 23:59:06 +08:00
|
|
|
|
onResponseCompleted_l();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (_totalBodySize == 0) {
|
2018-11-13 22:50:43 +08:00
|
|
|
|
//后续没content,本次http请求结束
|
2018-09-23 21:19:24 +08:00
|
|
|
|
onResponseCompleted_l();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2018-09-23 21:10:17 +08:00
|
|
|
|
|
2018-11-13 22:50:43 +08:00
|
|
|
|
//当_totalBodySize != 0时到达这里,代表后续有content
|
|
|
|
|
//虽然我们在_totalBodySize >0 时知道content的确切大小,
|
2018-09-23 21:10:17 +08:00
|
|
|
|
//但是由于我们没必要等content接收完毕才回调onRecvContent(因为这样浪费内存并且要多次拷贝数据)
|
|
|
|
|
//所以返回-1代表我们接下来分段接收content
|
2018-11-13 22:50:43 +08:00
|
|
|
|
_recvedBodySize = 0;
|
2018-09-23 21:10:17 +08:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-17 18:31:50 +08:00
|
|
|
|
void HttpClient::onRecvContent(const char *data, size_t len) {
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (_chunkedSplitter) {
|
|
|
|
|
_chunkedSplitter->input(data, len);
|
2018-11-13 23:59:06 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-09-23 21:10:17 +08:00
|
|
|
|
auto recvedBodySize = _recvedBodySize + len;
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (_totalBodySize < 0) {
|
2021-01-19 16:05:38 +08:00
|
|
|
|
//不限长度的content,最大支持SIZE_MAX个字节
|
|
|
|
|
onResponseBody(data, len, recvedBodySize, SIZE_MAX);
|
2018-11-13 22:50:43 +08:00
|
|
|
|
_recvedBodySize = recvedBodySize;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//固定长度的content
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (recvedBodySize < (size_t) _totalBodySize) {
|
2018-11-13 22:50:43 +08:00
|
|
|
|
//content还未接收完毕
|
2018-09-23 21:10:17 +08:00
|
|
|
|
onResponseBody(data, len, recvedBodySize, _totalBodySize);
|
|
|
|
|
_recvedBodySize = recvedBodySize;
|
2018-11-13 22:50:43 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//content接收完毕
|
|
|
|
|
onResponseBody(data, _totalBodySize - _recvedBodySize, _totalBodySize, _totalBodySize);
|
2021-09-30 16:10:09 +08:00
|
|
|
|
bool biggerThanExpected = recvedBodySize > (size_t) _totalBodySize;
|
2018-11-13 22:50:43 +08:00
|
|
|
|
onResponseCompleted_l();
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (biggerThanExpected) {
|
2018-11-13 22:50:43 +08:00
|
|
|
|
//声明的content数据比真实的小,那么我们只截取前面部分的并断开链接
|
2019-05-29 18:08:50 +08:00
|
|
|
|
shutdown(SockException(Err_shutdown, "http response content size bigger than expected"));
|
2018-09-23 21:10:17 +08:00
|
|
|
|
}
|
2017-05-05 18:02:54 +08:00
|
|
|
|
}
|
2018-06-21 14:03:43 +08:00
|
|
|
|
|
2019-05-29 18:08:50 +08:00
|
|
|
|
void HttpClient::onFlush() {
|
2018-06-21 14:03:43 +08:00
|
|
|
|
_aliveTicker.resetTime();
|
2021-09-30 16:10:09 +08:00
|
|
|
|
GET_CONFIG(uint32_t, sendBufSize, Http::kSendBufSize);
|
2018-09-23 21:10:17 +08:00
|
|
|
|
while (_body && _body->remainSize() && !isSocketBusy()) {
|
2019-10-27 02:04:51 +08:00
|
|
|
|
auto buffer = _body->readData(sendBufSize);
|
2018-09-23 21:10:17 +08:00
|
|
|
|
if (!buffer) {
|
2018-06-21 14:03:43 +08:00
|
|
|
|
//数据发送结束或读取数据异常
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-09-23 21:10:17 +08:00
|
|
|
|
if (send(buffer) <= 0) {
|
2018-06-21 14:03:43 +08:00
|
|
|
|
//发送数据失败,不需要回滚数据,因为发送前已经通过isSocketBusy()判断socket可写
|
|
|
|
|
//所以发送缓存区肯定未满,该buffer肯定已经写入socket
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpClient::onManager() {
|
2019-02-17 13:35:12 +08:00
|
|
|
|
if (_aliveTicker.elapsedTime() > 3 * 1000 && _totalBodySize < 0 && !_chunkedSplitter) {
|
2018-06-21 14:03:43 +08:00
|
|
|
|
//如果Content-Length未指定 但接收数据超时
|
|
|
|
|
//则认为本次http请求完成
|
2018-09-23 21:10:17 +08:00
|
|
|
|
onResponseCompleted_l();
|
2018-06-21 14:03:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-23 21:10:17 +08:00
|
|
|
|
if (_fTimeOutSec > 0 && _aliveTicker.elapsedTime() > _fTimeOutSec * 1000) {
|
2018-06-21 14:03:43 +08:00
|
|
|
|
//超时
|
2019-05-29 18:08:50 +08:00
|
|
|
|
shutdown(SockException(Err_timeout, "http request timeout"));
|
2018-06-21 14:03:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 22:50:43 +08:00
|
|
|
|
void HttpClient::onResponseCompleted_l() {
|
|
|
|
|
onResponseCompleted();
|
2018-09-23 21:10:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-14 09:59:07 +08:00
|
|
|
|
void HttpClient::checkCookie(HttpClient::HttpHeader &headers) {
|
2018-09-24 00:50:02 +08:00
|
|
|
|
//Set-Cookie: IPTV_SERVER=8E03927B-CC8C-4389-BC00-31DBA7EC7B49;expires=Sun, Sep 23 2018 15:07:31 GMT;path=/index/api/
|
2021-09-30 16:10:09 +08:00
|
|
|
|
for (auto it_set_cookie = headers.find("Set-Cookie"); it_set_cookie != headers.end(); ++it_set_cookie) {
|
|
|
|
|
auto key_val = Parser::parseArgs(it_set_cookie->second, ";", "=");
|
2019-06-13 11:45:13 +08:00
|
|
|
|
HttpCookie::Ptr cookie = std::make_shared<HttpCookie>();
|
|
|
|
|
cookie->setHost(_lastHost);
|
|
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
auto arg_vec = split(it_set_cookie->second, ";");
|
|
|
|
|
for (string &key_val : arg_vec) {
|
2021-09-30 16:10:09 +08:00
|
|
|
|
auto key = FindField(key_val.data(), NULL, "=");
|
|
|
|
|
auto val = FindField(key_val.data(), "=", NULL);
|
2019-06-13 11:45:13 +08:00
|
|
|
|
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (index++ == 0) {
|
|
|
|
|
cookie->setKeyVal(key, val);
|
2019-06-13 11:45:13 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2018-09-25 09:26:23 +08:00
|
|
|
|
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (key == "path") {
|
2019-06-13 11:45:13 +08:00
|
|
|
|
cookie->setPath(val);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-03-14 09:59:07 +08:00
|
|
|
|
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (key == "expires") {
|
|
|
|
|
cookie->setExpires(val, headers["Date"]);
|
2019-06-13 11:45:13 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-03-14 09:59:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-30 16:10:09 +08:00
|
|
|
|
if (!(*cookie)) {
|
2019-06-13 11:45:13 +08:00
|
|
|
|
//无效的cookie
|
2019-03-14 09:59:07 +08:00
|
|
|
|
continue;
|
2018-09-24 00:50:02 +08:00
|
|
|
|
}
|
2019-06-13 11:45:13 +08:00
|
|
|
|
HttpCookieStorage::Instance().set(cookie);
|
2018-09-24 00:50:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-17 17:48:05 +08:00
|
|
|
|
} /* namespace mediakit */
|