nghttpd: Fix bug that date header field value is not updated
This commit is contained in:
parent
fe17a20f84
commit
c2f49fa478
|
@ -173,7 +173,8 @@ class Sessions {
|
||||||
public:
|
public:
|
||||||
Sessions(struct ev_loop *loop, const Config *config, SSL_CTX *ssl_ctx)
|
Sessions(struct ev_loop *loop, const Config *config, SSL_CTX *ssl_ctx)
|
||||||
: loop_(loop), config_(config), ssl_ctx_(ssl_ctx), callbacks_(nullptr),
|
: loop_(loop), config_(config), ssl_ctx_(ssl_ctx), callbacks_(nullptr),
|
||||||
next_session_id_(1) {
|
next_session_id_(1), tstamp_cached_(ev_now(loop)),
|
||||||
|
cached_date_(util::http_date(tstamp_cached_)) {
|
||||||
nghttp2_session_callbacks_new(&callbacks_);
|
nghttp2_session_callbacks_new(&callbacks_);
|
||||||
|
|
||||||
fill_callback(callbacks_, config_);
|
fill_callback(callbacks_, config_);
|
||||||
|
@ -234,17 +235,25 @@ public:
|
||||||
}
|
}
|
||||||
add_handler(handler.release());
|
add_handler(handler.release());
|
||||||
}
|
}
|
||||||
void update_cached_date() { cached_date_ = util::http_date(time(nullptr)); }
|
void update_cached_date() { cached_date_ = util::http_date(tstamp_cached_); }
|
||||||
const std::string &get_cached_date() const { return cached_date_; }
|
const std::string &get_cached_date() {
|
||||||
|
auto t = ev_now(loop_);
|
||||||
|
if (t != tstamp_cached_) {
|
||||||
|
tstamp_cached_ = t;
|
||||||
|
update_cached_date();
|
||||||
|
}
|
||||||
|
return cached_date_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::set<Http2Handler *> handlers_;
|
std::set<Http2Handler *> handlers_;
|
||||||
std::string cached_date_;
|
|
||||||
struct ev_loop *loop_;
|
struct ev_loop *loop_;
|
||||||
const Config *config_;
|
const Config *config_;
|
||||||
SSL_CTX *ssl_ctx_;
|
SSL_CTX *ssl_ctx_;
|
||||||
nghttp2_session_callbacks *callbacks_;
|
nghttp2_session_callbacks *callbacks_;
|
||||||
int64_t next_session_id_;
|
int64_t next_session_id_;
|
||||||
|
ev_tstamp tstamp_cached_;
|
||||||
|
std::string cached_date_;
|
||||||
};
|
};
|
||||||
|
|
||||||
Stream::Stream(Http2Handler *handler, int32_t stream_id)
|
Stream::Stream(Http2Handler *handler, int32_t stream_id)
|
||||||
|
@ -1280,7 +1289,6 @@ void worker_acceptcb(struct ev_loop *loop, ev_async *w, int revents) {
|
||||||
namespace {
|
namespace {
|
||||||
void run_worker(Worker *worker) {
|
void run_worker(Worker *worker) {
|
||||||
auto loop = worker->sessions->get_loop();
|
auto loop = worker->sessions->get_loop();
|
||||||
worker->sessions->update_cached_date();
|
|
||||||
|
|
||||||
ev_run(loop, 0);
|
ev_run(loop, 0);
|
||||||
}
|
}
|
||||||
|
@ -1616,10 +1624,6 @@ int HttpServer::run() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_->num_worker == 1) {
|
|
||||||
sessions.update_cached_date();
|
|
||||||
}
|
|
||||||
|
|
||||||
ev_run(loop, 0);
|
ev_run(loop, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue