nghttp: Depend on "leader" anchor if js is linked inside head element
This commit is contained in:
parent
1a12a9b397
commit
d3561a63b1
|
@ -30,7 +30,8 @@
|
||||||
|
|
||||||
namespace nghttp2 {
|
namespace nghttp2 {
|
||||||
|
|
||||||
ParserData::ParserData(const std::string &base_uri) : base_uri(base_uri) {}
|
ParserData::ParserData(const std::string &base_uri)
|
||||||
|
: base_uri(base_uri), inside_head(0) {}
|
||||||
|
|
||||||
HtmlParser::HtmlParser(const std::string &base_uri)
|
HtmlParser::HtmlParser(const std::string &base_uri)
|
||||||
: base_uri_(base_uri), parser_ctx_(nullptr), parser_data_(base_uri) {}
|
: base_uri_(base_uri), parser_ctx_(nullptr), parser_data_(base_uri) {}
|
||||||
|
@ -68,6 +69,9 @@ namespace {
|
||||||
void start_element_func(void *user_data, const xmlChar *name,
|
void start_element_func(void *user_data, const xmlChar *name,
|
||||||
const xmlChar **attrs) {
|
const xmlChar **attrs) {
|
||||||
auto parser_data = static_cast<ParserData *>(user_data);
|
auto parser_data = static_cast<ParserData *>(user_data);
|
||||||
|
if (util::strieq(reinterpret_cast<const char *>(name), "head")) {
|
||||||
|
++parser_data->inside_head;
|
||||||
|
}
|
||||||
if (util::strieq(reinterpret_cast<const char *>(name), "link")) {
|
if (util::strieq(reinterpret_cast<const char *>(name), "link")) {
|
||||||
auto rel_attr = get_attr(attrs, "rel");
|
auto rel_attr = get_attr(attrs, "rel");
|
||||||
auto href_attr = get_attr(attrs, "href");
|
auto href_attr = get_attr(attrs, "href");
|
||||||
|
@ -90,8 +94,20 @@ void start_element_func(void *user_data, const xmlChar *name,
|
||||||
if (!src_attr) {
|
if (!src_attr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO if script is inside in head, this should be REQ_LEADERS.
|
if (parser_data->inside_head) {
|
||||||
add_link(parser_data, src_attr, REQ_UNBLOCK_JS);
|
add_link(parser_data, src_attr, REQ_JS);
|
||||||
|
} else {
|
||||||
|
add_link(parser_data, src_attr, REQ_UNBLOCK_JS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
void end_element_func(void *user_data, const xmlChar *name) {
|
||||||
|
auto parser_data = static_cast<ParserData *>(user_data);
|
||||||
|
if (util::strieq(reinterpret_cast<const char *>(name), "head")) {
|
||||||
|
--parser_data->inside_head;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -113,7 +129,7 @@ xmlSAXHandler saxHandler = {
|
||||||
nullptr, // startDocumentSAXFunc
|
nullptr, // startDocumentSAXFunc
|
||||||
nullptr, // endDocumentSAXFunc
|
nullptr, // endDocumentSAXFunc
|
||||||
&start_element_func, // startElementSAXFunc
|
&start_element_func, // startElementSAXFunc
|
||||||
nullptr, // endElementSAXFunc
|
&end_element_func, // endElementSAXFunc
|
||||||
nullptr, // referenceSAXFunc
|
nullptr, // referenceSAXFunc
|
||||||
nullptr, // charactersSAXFunc
|
nullptr, // charactersSAXFunc
|
||||||
nullptr, // ignorableWhitespaceSAXFunc
|
nullptr, // ignorableWhitespaceSAXFunc
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace nghttp2 {
|
||||||
// Lower value has higher priority
|
// Lower value has higher priority
|
||||||
enum RequestPriority {
|
enum RequestPriority {
|
||||||
REQ_CSS = 1,
|
REQ_CSS = 1,
|
||||||
|
REQ_JS,
|
||||||
REQ_UNBLOCK_JS,
|
REQ_UNBLOCK_JS,
|
||||||
REQ_IMG,
|
REQ_IMG,
|
||||||
REQ_OTHERS,
|
REQ_OTHERS,
|
||||||
|
@ -49,6 +50,8 @@ enum RequestPriority {
|
||||||
struct ParserData {
|
struct ParserData {
|
||||||
std::string base_uri;
|
std::string base_uri;
|
||||||
std::vector<std::pair<std::string, RequestPriority>> links;
|
std::vector<std::pair<std::string, RequestPriority>> links;
|
||||||
|
// > 0 if we are inside "head" element.
|
||||||
|
int inside_head;
|
||||||
ParserData(const std::string &base_uri);
|
ParserData(const std::string &base_uri);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -196,6 +196,7 @@ nghttp2_priority_spec Request::resolve_dep(int32_t pri) {
|
||||||
int32_t weight;
|
int32_t weight;
|
||||||
switch (pri) {
|
switch (pri) {
|
||||||
case REQ_CSS:
|
case REQ_CSS:
|
||||||
|
case REQ_JS:
|
||||||
anchor_id = anchors[ANCHOR_LEADERS].stream_id;
|
anchor_id = anchors[ANCHOR_LEADERS].stream_id;
|
||||||
weight = 2;
|
weight = 2;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue