[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Review Request: kio_http: fix keepalive timeout parsing
From: "Andreas Hartmetz" <ahartmetz () gmail ! com>
Date: 2011-10-12 23:02:47
Message-ID: 20111012230247.31340.67978 () vidsolbach ! de
[Download RAW message or body]
> On Oct. 12, 2011, 10:58 p.m., Andreas Hartmetz wrote:
> > kioslave/http/http.cpp, line 3107
> > <http://git.reviewboard.kde.org/r/102822/diff/1/?file=38514#file38514line3107>
> >
> > I guess the parser just lowercases the key ("keep-alive"), not the values. \
> > Lowercasing the keys is okay because per the spec they are case-insensitive, and \
> > it has the advantage that you can look up keys in more or less constant time when \
> > using a hashtable. In many cases the values are case sensitive (usernames, \
> > something Base64-encoded for example), so the parser better leaves them alone. So \
> > you need to normalize the case yourself.
Small addition: The values are key-value pairs again here, but that isn't universally \
so in HTTP headers. The header parser simply doesn't know about such details.
- Andreas
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://git.reviewboard.kde.org/r/102822/#review7283
-----------------------------------------------------------
On Oct. 10, 2011, 10:35 p.m., Andrea Iacovitti wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://git.reviewboard.kde.org/r/102822/
> -----------------------------------------------------------
>
> (Updated Oct. 10, 2011, 10:35 p.m.)
>
>
> Review request for kdelibs, Andreas Hartmetz and Dawit Alemayehu.
>
>
> Description
> -------
>
> Keep-alive header can specify multiple, comma-separated, value pairs.
> For example what apache web server normally sends is something like that:
>
> "Keep-Alive: timeout=5, max=99"
>
> Actually kio_http fails to extract timeout value because it assumes
> keep-alive header can contain only a single value pair.
> In the case of example above what it end up to do is
> m_request.keepAliveTimeout = QString("5, max=99").toInt(), that returns 0 (wrong!).
>
>
> Diffs
> -----
>
> kioslave/http/http.cpp 2862707
> kioslave/http/parsinghelpers.cpp fc75d68
>
> Diff: http://git.reviewboard.kde.org/r/102822/diff/diff
>
>
> Testing
> -------
>
> -Patched code compiles
> -Hacked a web server and made tests against following keep-alive header variants:
> "Keep-Alive: timeout=5, max=99"
> "Keep-Alive: Timeout=5, max=99" (uppercase 'T')
> "Keep-Alive: Timeout=5 , max=99" (extra space before comma)
>
>
> Thanks,
>
> Andrea Iacovitti
>
>
[Attachment #3 (text/html)]
<html>
<body>
<div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
<table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 \
solid;"> <tr>
<td>
This is an automatically generated e-mail. To reply, visit:
<a href="http://git.reviewboard.kde.org/r/102822/">http://git.reviewboard.kde.org/r/102822/</a>
</td>
</tr>
</table>
<br />
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;"> <p style="margin-top: 0;">On October 12th, 2011, 10:58 p.m., <b>Andreas \
Hartmetz</b> wrote:</p> <blockquote style="margin-left: 1em; border-left: 2px solid \
#d0d0d0; padding-left: 10px;">
<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;"> <thead>
<tr>
<th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;"> <a \
href="http://git.reviewboard.kde.org/r/102822/diff/1/?file=38514#file38514line3107" \
style="color: black; font-weight: bold; text-decoration: \
underline;">kioslave/http/http.cpp</a> <span style="font-weight: normal;">
(Diff revision 1)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
">endParsing:</pre></td>
</tr>
</tbody>
<tbody>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">3107</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="k">if</span> <span class="p">(</span><span class="n">tIt</span><span \
class="p">.</span><span class="n">next</span><span class="p">().</span><span \
class="n">startsWith</span><span class="p">(</span><span \
class="s">"timeout="</span><span class="p">))</span> <span \
class="p">{</span> <span class="c1">// krazy:exclude=strings</span></pre></td> <th \
bgcolor="#e9eaa8" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">3107</font></th> <td bgcolor="#fdfebc" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "> \
<span class="n">QByteArray</span> <span class="n">ka</span> <span class="o">=</span> \
<span class="n">tIt</span><span class="p">.</span><span class="n">next</span><span \
class="p">().</span><span class="n">trimmed</span><span class="p">().</span><span \
class="n">toLower</span><span class="p">();</span></pre></td> </tr>
</tbody>
</table>
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">I guess the parser just \
lowercases the key ("keep-alive"), not the values. Lowercasing the keys is \
okay because per the spec they are case-insensitive, and it has the advantage that \
you can look up keys in more or less constant time when using a hashtable. In many \
cases the values are case sensitive (usernames, something Base64-encoded for \
example), so the parser better leaves them alone. So you need to normalize the case \
yourself.</pre> </blockquote>
</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Small \
addition: The values are key-value pairs again here, but that isn't universally \
so in HTTP headers. The header parser simply doesn't know about such \
details.</pre> <br />
<p>- Andreas</p>
<br />
<p>On October 10th, 2011, 10:35 p.m., Andrea Iacovitti wrote:</p>
<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" \
style="background-image: \
url('http://git.reviewboard.kde.org/media/rb/images/review_request_box_top_bg.png'); \
background-position: left top; background-repeat: repeat-x; border: 1px black \
solid;"> <tr>
<td>
<div>Review request for kdelibs, Andreas Hartmetz and Dawit Alemayehu.</div>
<div>By Andrea Iacovitti.</div>
<p style="color: grey;"><i>Updated Oct. 10, 2011, 10:35 p.m.</i></p>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" \
style="border: 1px solid #b8b5a0"> <tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">Keep-alive header can specify multiple, comma-separated, value pairs. \
For example what apache web server normally sends is something like that:
"Keep-Alive: timeout=5, max=99"
Actually kio_http fails to extract timeout value because it assumes
keep-alive header can contain only a single value pair.
In the case of example above what it end up to do is
m_request.keepAliveTimeout = QString("5, max=99").toInt(), that returns 0 \
(wrong!). </pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: \
1px solid #b8b5a0"> <tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">-Patched code compiles
-Hacked a web server and made tests against following keep-alive header variants:
"Keep-Alive: timeout=5, max=99"
"Keep-Alive: Timeout=5, max=99" (uppercase 'T')
"Keep-Alive: Timeout=5 , max=99" (extra space before comma)
</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">
<li>kioslave/http/http.cpp <span style="color: grey">(2862707)</span></li>
<li>kioslave/http/parsinghelpers.cpp <span style="color: grey">(fc75d68)</span></li>
</ul>
<p><a href="http://git.reviewboard.kde.org/r/102822/diff/" style="margin-left: \
3em;">View Diff</a></p>
</td>
</tr>
</table>
</div>
</body>
</html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic