Skip to content

Commit e5239c6

Browse files
committed
Several changes:
- Added user-agent property to head-matter and documented it. - Removed obsolete TODOs
1 parent 42a9ce4 commit e5239c6

File tree

6 files changed

+60
-8
lines changed

6 files changed

+60
-8
lines changed

src/Wt/WTable.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ std::unique_ptr<WTableRow> WTable::removeRow(int row)
145145
result->setTable(nullptr);
146146

147147
for (auto &cell : result->cells_)
148-
widgetRemoved(cell.get(), false); // TODO(Roel): why false?
148+
widgetRemoved(cell.get(), false);
149149

150150
return result;
151151
}

src/Wt/WTableRow.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ std::unique_ptr<WTableCell> WTableRow::removeColumn(int column)
6969
cells_[i]->column_ = i;
7070

7171
if (table_)
72-
table_->widgetRemoved(result.get(), false); // TODO(Roel): why false?
72+
table_->widgetRemoved(result.get(), false);
7373

7474
return result;
7575
}

src/web/Configuration.C

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ void EntryPoint::setPath(const std::string& path)
182182
path_ = path;
183183
}
184184

185+
HeadMatter::HeadMatter(std::string contents,
186+
std::string userAgent)
187+
: contents_(contents),
188+
userAgent_(userAgent)
189+
{ }
190+
185191
Configuration::Configuration(const std::string& applicationPath,
186192
const std::string& appRoot,
187193
const std::string& configurationFile,
@@ -878,12 +884,15 @@ void Configuration::readApplicationSettings(xml_node<> *app)
878884
for (unsigned i = 0; i < headMatters.size(); ++i) {
879885
xml_node<> *headMatter = headMatters[i];
880886

887+
std::string userAgent;
888+
attributeValue(headMatter, "user-agent", userAgent);
889+
881890
std::stringstream ss;
882891
for (xml_node<> *r = headMatter->first_node(); r;
883892
r = r->next_sibling()) {
884893
rapidxml::print(static_cast<std::ostream&>(ss), *r);
885894
}
886-
headMatter_ = ss.str();
895+
headMatter_.push_back(HeadMatter(ss.str(), userAgent));
887896
}
888897
}
889898

src/web/Configuration.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ typedef std::vector<EntryPoint> EntryPointList;
7070

7171
#endif // WT_TARGET_JAVA
7272

73+
class WT_API HeadMatter {
74+
public:
75+
HeadMatter(std::string contents,
76+
std::string userAgent);
77+
78+
const std::string& contents() const { return contents_; }
79+
const std::string& userAgent() const { return userAgent_; }
80+
81+
private:
82+
std::string contents_;
83+
std::string userAgent_;
84+
};
85+
7386
class WT_API Configuration
7487
{
7588
public:
@@ -132,7 +145,7 @@ class WT_API Configuration
132145
#endif // WT_TARGET_JAVA
133146

134147
const std::vector<MetaHeader>& metaHeaders() const { return metaHeaders_; }
135-
const std::string &headMatter() const { return headMatter_; }
148+
const std::vector<HeadMatter>& headMatter() const { return headMatter_; }
136149
SessionPolicy sessionPolicy() const;
137150
int numProcesses() const;
138151
int numThreads() const;
@@ -253,7 +266,7 @@ class WT_API Configuration
253266

254267
std::vector<BootstrapEntry> bootstrapConfig_;
255268
std::vector<MetaHeader> metaHeaders_;
256-
std::string headMatter_;
269+
std::vector<HeadMatter> headMatter_;
257270

258271
bool connectorSlashException_;
259272
bool connectorNeedReadBody_;

src/web/WebRenderer.C

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,22 @@ std::string WebRenderer::headDeclarations() const
19121912

19131913
const Configuration& conf = session_.env().server()->configuration();
19141914

1915+
const std::vector<HeadMatter>& headMatters = conf.headMatter();
1916+
for (unsigned i = 0; i < headMatters.size(); ++i) {
1917+
const HeadMatter& m = headMatters[i];
1918+
1919+
bool add = true;
1920+
if (!m.userAgent().empty()) {
1921+
std::string s = session_.env().userAgent();
1922+
std::regex expr(m.userAgent());
1923+
if (!std::regex_search(s, expr))
1924+
add = false;
1925+
}
1926+
1927+
if (add)
1928+
result << m.contents();
1929+
}
1930+
19151931
const std::vector<MetaHeader>& confMetaHeaders = conf.metaHeaders();
19161932
std::vector<MetaHeader> metaHeaders;
19171933

@@ -1953,8 +1969,6 @@ std::string WebRenderer::headDeclarations() const
19531969
}
19541970
}
19551971

1956-
result << conf.headMatter();
1957-
19581972
for (unsigned i = 0; i < metaHeaders.size(); ++i) {
19591973
const MetaHeader& m = metaHeaders[i];
19601974

wt_config.xml.in

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,26 @@
518518
user-agent, using a regular expression. You can have multiple
519519
set-meta-headers definitions.
520520

521-
-->
521+
Deprecated: use <head-matter> instead.
522+
522523
<meta-headers user-agent=".*MSIE.*">
523524
<meta name="robots" content="noindex" />
524525
</meta-headers>
526+
-->
527+
528+
<!-- Configure <head> matter
529+
530+
The user-agent allows optional filtering based on the
531+
user-agent, using a regular expression. You can have multiple
532+
head-matter definitions.
533+
534+
All contents will be inserted into the <head> tag
535+
verbatim. This could be useful for setting <meta> tags or
536+
<link> tags that are global for the entire application.
537+
-->
538+
<head-matter user-agent=".*MSIE.*">
539+
<meta name="robots" content="noindex" />
540+
</head-matter>
525541

526542
<!-- Runtime Properties
527543

0 commit comments

Comments
 (0)