blob: e4f5f1cc4f61e8c6cde0e330ba6d2f8c3334f191 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Coverage Report</title>
<link title="Style" type="text/css" rel="stylesheet" href="css/main.css"/>
<script type="text/javascript" src="js/popup.js"></script>
</head>
<body>
<h5>Coverage Report - com.google.enterprise.adaptor.HttpExchanges</h5>
<div class="separator">&nbsp;</div>
<table class="report">
<thead><tr> <td class="heading">Classes in this File</td> <td class="heading"><a class="dfn" href="help.html" onclick="popupwindow('help.html'); return false;">Line Coverage</a></td> <td class="heading"><a class="dfn" href="help.html" onclick="popupwindow('help.html'); return false;">Branch Coverage</a></td> <td class="heading"><a class="dfn" href="help.html" onclick="popupwindow('help.html'); return false;">Complexity</a></td></tr></thead>
<tr><td><a href="com.google.enterprise.adaptor.HttpExchanges.html">HttpExchanges</a></td><td><table cellpadding="0px" cellspacing="0px" class="percentgraph"><tr class="percentgraph"><td align="right" class="percentgraph" width="40">8</td><td class="percentgraph"><div class="percentgraph"><div class="greenbar" style="width:93px"><span class="text">110/118</span></div></div></td></tr></table></td><td><table cellpadding="0px" cellspacing="0px" class="percentgraph"><tr class="percentgraph"><td align="right" class="percentgraph" width="40">2</td><td class="percentgraph"><div class="percentgraph"><div class="greenbar" style="width:95px"><span class="text">40/42</span></div></div></td></tr></table></td><td class="value"><span class="hidden">2.45;</span>2.45</td></tr>
<tr><td><a href="com.google.enterprise.adaptor.HttpExchanges.html">HttpExchanges$1</a></td><td><table cellpadding="0px" cellspacing="0px" class="percentgraph"><tr class="percentgraph"><td align="right" class="percentgraph" width="40">0</td><td class="percentgraph"><div class="percentgraph"><div class="greenbar" style="width:100px"><span class="text">4/4</span></div></div></td></tr></table></td><td><table cellpadding="0px" cellspacing="0px" class="percentgraph"><tr class="percentgraph"><td align="right" class="percentgraph" width="40"><a class="dfn" href="help.html" onclick="popupwindow('help.html'); return false;">N/A</a></td><td class="percentgraph"><div class="percentgraph"><div class="na" style="width:100px"><span class="text"><a class="dfn" href="help.html" onclick="popupwindow('help.html'); return false;">N/A</a></span></div></div></td></tr></table></td><td class="value"><span class="hidden">2.45;</span>2.45</td></tr>
<tr><td><a href="com.google.enterprise.adaptor.HttpExchanges.html">HttpExchanges$2</a></td><td><table cellpadding="0px" cellspacing="0px" class="percentgraph"><tr class="percentgraph"><td align="right" class="percentgraph" width="40">0</td><td class="percentgraph"><div class="percentgraph"><div class="greenbar" style="width:100px"><span class="text">4/4</span></div></div></td></tr></table></td><td><table cellpadding="0px" cellspacing="0px" class="percentgraph"><tr class="percentgraph"><td align="right" class="percentgraph" width="40"><a class="dfn" href="help.html" onclick="popupwindow('help.html'); return false;">N/A</a></td><td class="percentgraph"><div class="percentgraph"><div class="na" style="width:100px"><span class="text"><a class="dfn" href="help.html" onclick="popupwindow('help.html'); return false;">N/A</a></span></div></div></td></tr></table></td><td class="value"><span class="hidden">2.45;</span>2.45</td></tr>
<tr><td><a href="com.google.enterprise.adaptor.HttpExchanges.html">HttpExchanges$3</a></td><td><table cellpadding="0px" cellspacing="0px" class="percentgraph"><tr class="percentgraph"><td align="right" class="percentgraph" width="40">0</td><td class="percentgraph"><div class="percentgraph"><div class="greenbar" style="width:100px"><span class="text">4/4</span></div></div></td></tr></table></td><td><table cellpadding="0px" cellspacing="0px" class="percentgraph"><tr class="percentgraph"><td align="right" class="percentgraph" width="40"><a class="dfn" href="help.html" onclick="popupwindow('help.html'); return false;">N/A</a></td><td class="percentgraph"><div class="percentgraph"><div class="na" style="width:100px"><span class="text"><a class="dfn" href="help.html" onclick="popupwindow('help.html'); return false;">N/A</a></span></div></div></td></tr></table></td><td class="value"><span class="hidden">2.45;</span>2.45</td></tr>
<tr><td><a href="com.google.enterprise.adaptor.HttpExchanges.html">HttpExchanges$4</a></td><td><table cellpadding="0px" cellspacing="0px" class="percentgraph"><tr class="percentgraph"><td align="right" class="percentgraph" width="40">0</td><td class="percentgraph"><div class="percentgraph"><div class="greenbar" style="width:100px"><span class="text">2/2</span></div></div></td></tr></table></td><td><table cellpadding="0px" cellspacing="0px" class="percentgraph"><tr class="percentgraph"><td align="right" class="percentgraph" width="40"><a class="dfn" href="help.html" onclick="popupwindow('help.html'); return false;">N/A</a></td><td class="percentgraph"><div class="percentgraph"><div class="na" style="width:100px"><span class="text"><a class="dfn" href="help.html" onclick="popupwindow('help.html'); return false;">N/A</a></span></div></div></td></tr></table></td><td class="value"><span class="hidden">2.45;</span>2.45</td></tr>
</table>
<div class="separator">&nbsp;</div>
<table cellspacing="0" cellpadding="0" class="src">
<tr> <td class="numLine">&nbsp;1</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">// Copyright 2011 Google Inc. All Rights Reserved.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;2</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">//</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;3</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">// Licensed under the Apache License, Version 2.0 (the "License");</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;4</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">// you may not use this file except in compliance with the License.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;5</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">// You may obtain a copy of the License at</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;6</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">//</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;7</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">// http://www.apache.org/licenses/LICENSE-2.0</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;8</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">//</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;9</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">// Unless required by applicable law or agreed to in writing, software</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;10</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">// distributed under the License is distributed on an "AS IS" BASIS,</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;11</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;12</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">// See the License for the specific language governing permissions and</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;13</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">// limitations under the License.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;14</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;15</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">package</span> com.google.enterprise.adaptor;</pre></td></tr>
<tr> <td class="numLine">&nbsp;16</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;17</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> com.google.common.annotations.VisibleForTesting;</pre></td></tr>
<tr> <td class="numLine">&nbsp;18</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> com.sun.net.httpserver.HttpExchange;</pre></td></tr>
<tr> <td class="numLine">&nbsp;19</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> com.sun.net.httpserver.HttpsServer;</pre></td></tr>
<tr> <td class="numLine">&nbsp;20</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;21</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.io.IOException;</pre></td></tr>
<tr> <td class="numLine">&nbsp;22</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.io.OutputStream;</pre></td></tr>
<tr> <td class="numLine">&nbsp;23</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.io.UnsupportedEncodingException;</pre></td></tr>
<tr> <td class="numLine">&nbsp;24</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.net.HttpURLConnection;</pre></td></tr>
<tr> <td class="numLine">&nbsp;25</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.net.URI;</pre></td></tr>
<tr> <td class="numLine">&nbsp;26</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.net.URISyntaxException;</pre></td></tr>
<tr> <td class="numLine">&nbsp;27</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.net.URLDecoder;</pre></td></tr>
<tr> <td class="numLine">&nbsp;28</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.nio.charset.Charset;</pre></td></tr>
<tr> <td class="numLine">&nbsp;29</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.text.DateFormat;</pre></td></tr>
<tr> <td class="numLine">&nbsp;30</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.text.SimpleDateFormat;</pre></td></tr>
<tr> <td class="numLine">&nbsp;31</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.ArrayList;</pre></td></tr>
<tr> <td class="numLine">&nbsp;32</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.Collection;</pre></td></tr>
<tr> <td class="numLine">&nbsp;33</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.Collections;</pre></td></tr>
<tr> <td class="numLine">&nbsp;34</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.Date;</pre></td></tr>
<tr> <td class="numLine">&nbsp;35</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.LinkedList;</pre></td></tr>
<tr> <td class="numLine">&nbsp;36</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.List;</pre></td></tr>
<tr> <td class="numLine">&nbsp;37</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.Locale;</pre></td></tr>
<tr> <td class="numLine">&nbsp;38</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.Map;</pre></td></tr>
<tr> <td class="numLine">&nbsp;39</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.TimeZone;</pre></td></tr>
<tr> <td class="numLine">&nbsp;40</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.TreeMap;</pre></td></tr>
<tr> <td class="numLine">&nbsp;41</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.logging.Level;</pre></td></tr>
<tr> <td class="numLine">&nbsp;42</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.logging.Logger;</pre></td></tr>
<tr> <td class="numLine">&nbsp;43</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="keyword">import</span> java.util.zip.GZIPOutputStream;</pre></td></tr>
<tr> <td class="numLine">&nbsp;44</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;45</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment">/** Utility class for working with {@link HttpExchange}s. */</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;46</td> <td class="nbHitsCovered">&nbsp;8</td> <td class="src"><pre class="src">&nbsp;<span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">class</span> HttpExchanges {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;47</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> Logger log</pre></td></tr>
<tr> <td class="numLine">&nbsp;48</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; = Logger.getLogger(HttpExchanges.<span class="keyword">class</span>.getName());</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;49</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> TimeZone GMT = TimeZone.getTimeZone(<span class="string">"GMT"</span>);</pre></td></tr>
<tr> <td class="numLine">&nbsp;50</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;51</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Default encoding to encode simple response messages.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;52</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;53</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> Charset ENCODING = Charset.forName(<span class="string">"UTF-8"</span>);</pre></td></tr>
<tr> <td class="numLine">&nbsp;54</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;55</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// DateFormats are relatively expensive to create, and cannot be used from</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;56</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// multiple threads</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;57</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/** RFC 822 date format, as updated by RFC 1123. */</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;58</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> ThreadLocal&lt;DateFormat&gt; dateFormatRfc1123</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;59</td> <td class="nbHitsCovered">&nbsp;5</td> <td class="src"><pre class="src">&nbsp; = <span class="keyword">new</span> ThreadLocal&lt;DateFormat&gt;() {</pre></td></tr>
<tr> <td class="numLine">&nbsp;60</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; @Override</pre></td></tr>
<tr> <td class="numLine">&nbsp;61</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">protected</span> DateFormat initialValue() {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;62</td> <td class="nbHitsCovered">&nbsp;4</td> <td class="src"><pre class="src">&nbsp; DateFormat df = <span class="keyword">new</span> SimpleDateFormat(</pre></td></tr>
<tr> <td class="numLine">&nbsp;63</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="string">"EEE, dd MMM yyyy HH:mm:ss zzz"</span>, Locale.ENGLISH);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;64</td> <td class="nbHitsCovered">&nbsp;4</td> <td class="src"><pre class="src">&nbsp; df.setTimeZone(GMT);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;65</td> <td class="nbHitsCovered">&nbsp;4</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span> df;</pre></td></tr>
<tr> <td class="numLine">&nbsp;66</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;67</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; };</pre></td></tr>
<tr> <td class="numLine">&nbsp;68</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/** RFC 1036 date format. */</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;69</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> ThreadLocal&lt;DateFormat&gt; dateFormatRfc1036</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;70</td> <td class="nbHitsCovered">&nbsp;3</td> <td class="src"><pre class="src">&nbsp; = <span class="keyword">new</span> ThreadLocal&lt;DateFormat&gt;() {</pre></td></tr>
<tr> <td class="numLine">&nbsp;71</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; @Override</pre></td></tr>
<tr> <td class="numLine">&nbsp;72</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">protected</span> DateFormat initialValue() {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;73</td> <td class="nbHitsCovered">&nbsp;2</td> <td class="src"><pre class="src">&nbsp; DateFormat df = <span class="keyword">new</span> SimpleDateFormat(</pre></td></tr>
<tr> <td class="numLine">&nbsp;74</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="string">"EEEE, dd-MMM-yy HH:mm:ss zzz"</span>, Locale.ENGLISH);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;75</td> <td class="nbHitsCovered">&nbsp;2</td> <td class="src"><pre class="src">&nbsp; df.setTimeZone(GMT);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;76</td> <td class="nbHitsCovered">&nbsp;2</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span> df;</pre></td></tr>
<tr> <td class="numLine">&nbsp;77</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;78</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; };</pre></td></tr>
<tr> <td class="numLine">&nbsp;79</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/** ANSI C's {@code asctime()} format. */</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;80</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> ThreadLocal&lt;DateFormat&gt; dateFormatAsctime</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;81</td> <td class="nbHitsCovered">&nbsp;3</td> <td class="src"><pre class="src">&nbsp; = <span class="keyword">new</span> ThreadLocal&lt;DateFormat&gt;() {</pre></td></tr>
<tr> <td class="numLine">&nbsp;82</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; @Override</pre></td></tr>
<tr> <td class="numLine">&nbsp;83</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">protected</span> DateFormat initialValue() {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;84</td> <td class="nbHitsCovered">&nbsp;2</td> <td class="src"><pre class="src">&nbsp; DateFormat df = <span class="keyword">new</span> SimpleDateFormat(</pre></td></tr>
<tr> <td class="numLine">&nbsp;85</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="string">"EEE MMM d HH:mm:ss yyyy"</span>, Locale.ENGLISH);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;86</td> <td class="nbHitsCovered">&nbsp;2</td> <td class="src"><pre class="src">&nbsp; df.setTimeZone(GMT);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;87</td> <td class="nbHitsCovered">&nbsp;2</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span> df;</pre></td></tr>
<tr> <td class="numLine">&nbsp;88</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;89</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; };</pre></td></tr>
<tr> <td class="numLine">&nbsp;90</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/** The various date formats as required by RFC 2616 3.3.1. */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;91</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> List&lt;ThreadLocal&lt;DateFormat&gt;&gt; dateFormatsRfc2616;</pre></td></tr>
<tr> <td class="numLine">&nbsp;92</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;93</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * When thread-local value is not {@code null}, signals that {@link #handle}</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;94</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * should abort immediately with an error. This is a hack required because the</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;95</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * HttpServer can't handle the Executor rejecting execution of a runnable.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;96</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;97</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">static</span> <span class="keyword">final</span> ThreadLocal&lt;Object&gt; abortImmediately</pre></td></tr>
<tr> <td class="numLine">&nbsp;98</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; = <span class="keyword">new</span> ThreadLocal&lt;Object&gt;();</pre></td></tr>
<tr> <td class="numLine">&nbsp;99</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;100</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">static</span> {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;101</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; List&lt;ThreadLocal&lt;DateFormat&gt;&gt; tmpList</pre></td></tr>
<tr> <td class="numLine">&nbsp;102</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; = <span class="keyword">new</span> ArrayList&lt;ThreadLocal&lt;DateFormat&gt;&gt;();</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;103</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; tmpList.add(dateFormatRfc1123);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;104</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; tmpList.add(dateFormatRfc1036);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;105</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; tmpList.add(dateFormatAsctime);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;106</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; dateFormatsRfc2616 = Collections.unmodifiableList(tmpList);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;107</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;108</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;109</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// Prevent initialization.</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;110</td> <td class="nbHitsUncovered">&nbsp;0</td> <td class="src"><pre class="src"><span class="srcUncovered">&nbsp; <span class="keyword">private</span> HttpExchanges() {}</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;111</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;112</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/** Clear ThreadLocal state to test construction of those variables */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;113</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; @VisibleForTesting</pre></td></tr>
<tr> <td class="numLine">&nbsp;114</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">static</span> <span class="keyword">void</span> resetThread() {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;115</td> <td class="nbHitsCovered">&nbsp;4</td> <td class="src"><pre class="src">&nbsp; dateFormatRfc1123.remove();</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;116</td> <td class="nbHitsCovered">&nbsp;4</td> <td class="src"><pre class="src">&nbsp; dateFormatRfc1036.remove();</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;117</td> <td class="nbHitsCovered">&nbsp;4</td> <td class="src"><pre class="src">&nbsp; dateFormatAsctime.remove();</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;118</td> <td class="nbHitsCovered">&nbsp;4</td> <td class="src"><pre class="src">&nbsp; abortImmediately.remove();</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;119</td> <td class="nbHitsCovered">&nbsp;4</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;120</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;121</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;122</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Best-effort attempt to reform the identical URI the client used to</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;123</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * contact the server.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;124</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;125</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">public</span> <span class="keyword">static</span> URI getRequestUri(HttpExchange ex) {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;126</td> <td class="nbHitsCovered">&nbsp;111</td> <td class="src"><pre class="src">&nbsp; String host = ex.getRequestHeaders().getFirst(<span class="string">"Host"</span>);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;127</td> <td class="nbHitsUncovered"><a title="Line 127: Conditional coverage 50% (1/2).">&nbsp;111</a></td> <td class="src"><pre class="src"><span class="srcUncovered">&nbsp;<a title="Line 127: Conditional coverage 50% (1/2)."> <span class="keyword">if</span> (host == <span class="keyword">null</span>) {</a></span></pre></td></tr>
<tr> <td class="numLine">&nbsp;128</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// Client must be using HTTP/1.0</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;129</td> <td class="nbHitsUncovered">&nbsp;0</td> <td class="src"><pre class="src"><span class="srcUncovered">&nbsp; log.warning(</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;130</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="string">"Request did not provide Host header, using 'localhost' as hostname"</span>);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;131</td> <td class="nbHitsUncovered">&nbsp;0</td> <td class="src"><pre class="src"><span class="srcUncovered">&nbsp; <span class="keyword">int</span> port = ex.getHttpContext().getServer().getAddress().getPort();</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;132</td> <td class="nbHitsUncovered">&nbsp;0</td> <td class="src"><pre class="src"><span class="srcUncovered">&nbsp; host = <span class="string">"localhost:"</span> + port;</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;133</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;134</td> <td class="nbHitsCovered"><a title="Line 134: Conditional coverage 100% (2/2).">&nbsp;111</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 134: Conditional coverage 100% (2/2)."> String protocol = (ex.getHttpContext().getServer() <span class="keyword">instanceof</span> HttpsServer)</a></pre></td></tr>
<tr> <td class="numLine">&nbsp;135</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; ? <span class="string">"https"</span> : <span class="string">"http"</span>;</pre></td></tr>
<tr> <td class="numLine">&nbsp;136</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; URI base;</pre></td></tr>
<tr> <td class="numLine">&nbsp;137</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">try</span> {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;138</td> <td class="nbHitsCovered">&nbsp;111</td> <td class="src"><pre class="src">&nbsp; base = <span class="keyword">new</span> URI(protocol, host, <span class="string">"/"</span>, <span class="keyword">null</span>, <span class="keyword">null</span>);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;139</td> <td class="nbHitsUncovered">&nbsp;0</td> <td class="src"><pre class="src"><span class="srcUncovered">&nbsp; } <span class="keyword">catch</span> (URISyntaxException e) {</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;140</td> <td class="nbHitsUncovered">&nbsp;0</td> <td class="src"><pre class="src"><span class="srcUncovered">&nbsp; <span class="keyword">throw</span> <span class="keyword">new</span> IllegalStateException(e);</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;141</td> <td class="nbHitsCovered">&nbsp;111</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;142</td> <td class="nbHitsCovered">&nbsp;111</td> <td class="src"><pre class="src">&nbsp; URI requestedUri = ex.getRequestURI();</pre></td></tr>
<tr> <td class="numLine">&nbsp;143</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// If uri is already absolute (e.g., a proxy is involved), then this</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;144</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// does nothing, otherwise it resolves the URI for us based on who we</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;145</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// think we are</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;146</td> <td class="nbHitsCovered">&nbsp;111</td> <td class="src"><pre class="src">&nbsp; requestedUri = base.resolve(requestedUri);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;147</td> <td class="nbHitsCovered">&nbsp;111</td> <td class="src"><pre class="src">&nbsp; log.log(Level.FINER, <span class="string">"Resolved original URI to: {0}"</span>, requestedUri);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;148</td> <td class="nbHitsCovered">&nbsp;111</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span> requestedUri;</pre></td></tr>
<tr> <td class="numLine">&nbsp;149</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;150</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;151</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;152</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Sends response to GSA. Should only be used when the request method is</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;153</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * HEAD.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;154</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;155</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">static</span> <span class="keyword">void</span> respondToHead(HttpExchange ex, <span class="keyword">int</span> code,</pre></td></tr>
<tr> <td class="numLine">&nbsp;156</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; String contentType) <span class="keyword">throws</span> IOException {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;157</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; ex.getResponseHeaders().set(<span class="string">"Transfer-Encoding"</span>, <span class="string">"chunked"</span>);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;158</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; respond(ex, code, contentType, (<span class="keyword">byte</span>[]) <span class="keyword">null</span>);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;159</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;160</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;161</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;162</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Sends cheaply-generated response message to GSA. This is intended for use</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;163</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * with pre-build, canned messages. It automatically handles not sending the</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;164</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * actual content when the request method is HEAD. If the content requires</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;165</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * a moderate amount of work to produce, then you should manually call</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;166</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * {@link #respond} or {@link #respondToHead} depending on the situation.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;167</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;168</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">static</span> <span class="keyword">void</span> cannedRespond(HttpExchange ex, <span class="keyword">int</span> code, Translation response)</pre></td></tr>
<tr> <td class="numLine">&nbsp;169</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">throws</span> IOException {</pre></td></tr>
<tr> <td class="numLine">&nbsp;170</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// TODO(ejona): use exchange to decide on response language</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;171</td> <td class="nbHitsCovered">&nbsp;50</td> <td class="src"><pre class="src">&nbsp; cannedRespond(ex, code, <span class="string">"text/plain"</span>, response.toString());</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;172</td> <td class="nbHitsCovered">&nbsp;49</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;173</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;174</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;175</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Sends cheaply-generated response message to GSA. This is intended for use</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;176</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * with pre-build, canned messages. It automatically handles not sending the</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;177</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * actual content when the request method is HEAD. If the content requires</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;178</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * a moderate amount of work to produce, then you should manually call</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;179</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * {@link #respond} or {@link #respondToHead} depending on the situation.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;180</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;181</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">static</span> <span class="keyword">void</span> cannedRespond(HttpExchange ex, <span class="keyword">int</span> code, Translation response,</pre></td></tr>
<tr> <td class="numLine">&nbsp;182</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; Object... params) <span class="keyword">throws</span> IOException {</pre></td></tr>
<tr> <td class="numLine">&nbsp;183</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// TODO(ejona): use exchange to decide on response language</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;184</td> <td class="nbHitsCovered">&nbsp;14</td> <td class="src"><pre class="src">&nbsp; cannedRespond(ex, code, <span class="string">"text/plain"</span>, response.toString(params));</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;185</td> <td class="nbHitsCovered">&nbsp;14</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;186</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;187</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> cannedRespond(HttpExchange ex, <span class="keyword">int</span> code,</pre></td></tr>
<tr> <td class="numLine">&nbsp;188</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; String contentType, String response) <span class="keyword">throws</span> IOException {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;189</td> <td class="nbHitsCovered"><a title="Line 189: Conditional coverage 100% (2/2).">&nbsp;64</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 189: Conditional coverage 100% (2/2)."> <span class="keyword">if</span> (<span class="string">"HEAD"</span>.equals(ex.getRequestMethod())) {</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;190</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; respondToHead(ex, code, contentType);</pre></td></tr>
<tr> <td class="numLine">&nbsp;191</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; } <span class="keyword">else</span> {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;192</td> <td class="nbHitsCovered">&nbsp;63</td> <td class="src"><pre class="src">&nbsp; respond(ex, code, contentType, response.getBytes(ENCODING));</pre></td></tr>
<tr> <td class="numLine">&nbsp;193</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;194</td> <td class="nbHitsCovered">&nbsp;63</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;195</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;196</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;197</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Sends headers and configures {@code ex} for (possibly) sending content.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;198</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Completing the request is the caller's responsibility.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;199</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;200</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">static</span> <span class="keyword">void</span> startResponse(HttpExchange ex, <span class="keyword">int</span> code,</pre></td></tr>
<tr> <td class="numLine">&nbsp;201</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; String contentType, <span class="keyword">boolean</span> hasBody) <span class="keyword">throws</span> IOException {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;202</td> <td class="nbHitsCovered">&nbsp;147</td> <td class="src"><pre class="src">&nbsp; log.finest(<span class="string">"Starting response"</span>);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;203</td> <td class="nbHitsCovered"><a title="Line 203: Conditional coverage 100% (2/2).">&nbsp;147</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 203: Conditional coverage 100% (2/2)."> <span class="keyword">if</span> (contentType != <span class="keyword">null</span>) {</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;204</td> <td class="nbHitsCovered">&nbsp;99</td> <td class="src"><pre class="src">&nbsp; ex.getResponseHeaders().set(<span class="string">"Content-Type"</span>, contentType);</pre></td></tr>
<tr> <td class="numLine">&nbsp;205</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;206</td> <td class="nbHitsCovered"><a title="Line 206: Conditional coverage 100% (2/2).">&nbsp;147</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 206: Conditional coverage 100% (2/2)."> <span class="keyword">if</span> (!hasBody) {</a></pre></td></tr>
<tr> <td class="numLine">&nbsp;207</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// No body. Required for HEAD requests</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;208</td> <td class="nbHitsCovered">&nbsp;10</td> <td class="src"><pre class="src">&nbsp; ex.sendResponseHeaders(code, -1);</pre></td></tr>
<tr> <td class="numLine">&nbsp;209</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; } <span class="keyword">else</span> {</pre></td></tr>
<tr> <td class="numLine">&nbsp;210</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// Chuncked encoding</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;211</td> <td class="nbHitsCovered">&nbsp;137</td> <td class="src"><pre class="src">&nbsp; ex.sendResponseHeaders(code, 0);</pre></td></tr>
<tr> <td class="numLine">&nbsp;212</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;213</td> <td class="nbHitsCovered">&nbsp;147</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;214</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;215</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;216</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Sends response to GSA. Should not be used directly if the request method</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;217</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * is HEAD.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;218</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;219</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">static</span> <span class="keyword">void</span> respond(HttpExchange ex, <span class="keyword">int</span> code, String contentType,</pre></td></tr>
<tr> <td class="numLine">&nbsp;220</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">byte</span> response[]) <span class="keyword">throws</span> IOException {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;221</td> <td class="nbHitsCovered"><a title="Line 221: Conditional coverage 100% (2/2).">&nbsp;100</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 221: Conditional coverage 100% (2/2)."> startResponse(ex, code, contentType, response != <span class="keyword">null</span>);</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;222</td> <td class="nbHitsCovered"><a title="Line 222: Conditional coverage 100% (2/2).">&nbsp;100</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 222: Conditional coverage 100% (2/2)."> <span class="keyword">if</span> (response != <span class="keyword">null</span>) {</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;223</td> <td class="nbHitsCovered">&nbsp;92</td> <td class="src"><pre class="src">&nbsp; OutputStream responseBody = ex.getResponseBody();</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;224</td> <td class="nbHitsCovered">&nbsp;92</td> <td class="src"><pre class="src">&nbsp; log.finest(<span class="string">"before writing response"</span>);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;225</td> <td class="nbHitsCovered">&nbsp;92</td> <td class="src"><pre class="src">&nbsp; responseBody.write(response);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;226</td> <td class="nbHitsCovered">&nbsp;92</td> <td class="src"><pre class="src">&nbsp; responseBody.flush();</pre></td></tr>
<tr> <td class="numLine">&nbsp;227</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// This shouldn't be needed, but without it one developer had trouble</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;228</td> <td class="nbHitsCovered">&nbsp;91</td> <td class="src"><pre class="src">&nbsp; responseBody.close();</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;229</td> <td class="nbHitsCovered">&nbsp;91</td> <td class="src"><pre class="src">&nbsp; log.finest(<span class="string">"after writing response"</span>);</pre></td></tr>
<tr> <td class="numLine">&nbsp;230</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;231</td> <td class="nbHitsCovered">&nbsp;99</td> <td class="src"><pre class="src">&nbsp; ex.close();</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;232</td> <td class="nbHitsCovered">&nbsp;99</td> <td class="src"><pre class="src">&nbsp; log.finest(<span class="string">"after closing exchange"</span>);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;233</td> <td class="nbHitsCovered">&nbsp;99</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;234</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;235</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;236</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Redirect client to {@code location}. The client should retrieve the</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;237</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * referred location via GET, independent of the method of this request.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;238</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;239</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> sendRedirect(HttpExchange ex, URI location)</pre></td></tr>
<tr> <td class="numLine">&nbsp;240</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">throws</span> IOException {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;241</td> <td class="nbHitsCovered">&nbsp;3</td> <td class="src"><pre class="src">&nbsp; ex.getResponseHeaders().set(<span class="string">"Location"</span>, location.toString());</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;242</td> <td class="nbHitsCovered">&nbsp;3</td> <td class="src"><pre class="src">&nbsp; respond(ex, HttpURLConnection.HTTP_SEE_OTHER, <span class="keyword">null</span>, <span class="keyword">null</span>);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;243</td> <td class="nbHitsCovered">&nbsp;3</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;244</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;245</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;246</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Parses multi-valued header fields that can also be represented as</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;247</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * comma-separated lists. Leading and trailing whitespace is removed from each</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;248</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * value. This is the required format for any repeated header, as specified in</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;249</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * RFC 2616 Section 4.2.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;250</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> *</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;251</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * @return list of split and cleaned values, or {@code null} if no such</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;252</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * headers were specified</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;253</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;254</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">static</span> List&lt;String&gt; splitHeaderValues(List&lt;String&gt; values) {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;255</td> <td class="nbHitsCovered"><a title="Line 255: Conditional coverage 100% (2/2).">&nbsp;42</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 255: Conditional coverage 100% (2/2)."> <span class="keyword">if</span> (values == <span class="keyword">null</span>) {</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;256</td> <td class="nbHitsCovered">&nbsp;40</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span> <span class="keyword">null</span>;</pre></td></tr>
<tr> <td class="numLine">&nbsp;257</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;258</td> <td class="nbHitsCovered">&nbsp;2</td> <td class="src"><pre class="src">&nbsp; List&lt;String&gt; parsed = <span class="keyword">new</span> ArrayList&lt;String&gt;(values.size());</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;259</td> <td class="nbHitsCovered"><a title="Line 259: Conditional coverage 100% (2/2).">&nbsp;2</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 259: Conditional coverage 100% (2/2)."> <span class="keyword">for</span> (String value : values) {</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;260</td> <td class="nbHitsCovered">&nbsp;2</td> <td class="src"><pre class="src">&nbsp; String[] parts = value.split(<span class="string">","</span>, -1);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;261</td> <td class="nbHitsCovered"><a title="Line 261: Conditional coverage 100% (2/2).">&nbsp;5</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 261: Conditional coverage 100% (2/2)."> <span class="keyword">for</span> (String part : parts) {</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;262</td> <td class="nbHitsCovered">&nbsp;3</td> <td class="src"><pre class="src">&nbsp; parsed.add(part.trim());</pre></td></tr>
<tr> <td class="numLine">&nbsp;263</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;264</td> <td class="nbHitsCovered">&nbsp;2</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;265</td> <td class="nbHitsCovered">&nbsp;2</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span> Collections.unmodifiableList(parsed);</pre></td></tr>
<tr> <td class="numLine">&nbsp;266</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;267</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;268</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;269</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * If the client supports it, set the correct headers and streams to provide</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;270</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * GZIPed response data to the client. Because the content may become</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;271</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * compressed, users of this method should generally use a {@code</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;272</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * responseLength} of {@code 0} when calling {@link</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;273</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * HttpExchange#sendResponseHeaders}. The exception is when responding to a</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;274</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * HEAD request, in which {@code -1} is required.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;275</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;276</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> enableCompressionIfSupported(HttpExchange ex)</pre></td></tr>
<tr> <td class="numLine">&nbsp;277</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">throws</span> IOException {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;278</td> <td class="nbHitsCovered">&nbsp;18</td> <td class="src"><pre class="src">&nbsp; Collection&lt;String&gt; encodings</pre></td></tr>
<tr> <td class="numLine">&nbsp;279</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; = splitHeaderValues(ex.getRequestHeaders().get(<span class="string">"Accept-Encoding"</span>));</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;280</td> <td class="nbHitsCovered"><a title="Line 280: Conditional coverage 100% (2/2).">&nbsp;18</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 280: Conditional coverage 100% (2/2)."> <span class="keyword">if</span> (encodings == <span class="keyword">null</span>) {</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;281</td> <td class="nbHitsCovered">&nbsp;16</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span>;</pre></td></tr>
<tr> <td class="numLine">&nbsp;282</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;283</td> <td class="nbHitsCovered"><a title="Line 283: Conditional coverage 100% (2/2).">&nbsp;2</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 283: Conditional coverage 100% (2/2)."> <span class="keyword">if</span> (encodings.contains(<span class="string">"gzip"</span>)) {</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;284</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; log.finer(<span class="string">"Enabling gzip compression for response"</span>);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;285</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; ex.getResponseHeaders().set(<span class="string">"Content-Encoding"</span>, <span class="string">"gzip"</span>);</pre></td></tr>
<tr> <td class="numLine">&nbsp;286</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// Although the documentation states that getResponseBody() can only be</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;287</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// called after sendResponseHeaders(), this is not actually the case.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;288</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// Being able to call getResponseBody() before sendResponseHeaders() is</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;289</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// the only way for filters to function and so is supported even though</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;290</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// the documentation says otherwise.</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;291</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">final</span> OutputStream os = ex.getResponseBody();</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;292</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; ex.setStreams(<span class="keyword">null</span>, <span class="keyword">new</span> AbstractLazyOutputStream() {</pre></td></tr>
<tr> <td class="numLine">&nbsp;293</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; @Override</pre></td></tr>
<tr> <td class="numLine">&nbsp;294</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">protected</span> OutputStream retrieveOs() <span class="keyword">throws</span> IOException {</pre></td></tr>
<tr> <td class="numLine">&nbsp;295</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// Creating the GZIPOutputStream must happen after sendResponseHeaders</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;296</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// since the constructor writes data to the provided OutputStream.</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;297</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span> <span class="keyword">new</span> GZIPOutputStream(os);</pre></td></tr>
<tr> <td class="numLine">&nbsp;298</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;299</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; });</pre></td></tr>
<tr> <td class="numLine">&nbsp;300</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;301</td> <td class="nbHitsCovered">&nbsp;2</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;302</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;303</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;304</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Retrieves and parses the If-Modified-Since from the request, returning null</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;305</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * if there was no such header or there was an error.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;306</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;307</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">public</span> <span class="keyword">static</span> Date getIfModifiedSince(HttpExchange ex) {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;308</td> <td class="nbHitsCovered">&nbsp;19</td> <td class="src"><pre class="src">&nbsp; String ifModifiedSince</pre></td></tr>
<tr> <td class="numLine">&nbsp;309</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; = ex.getRequestHeaders().getFirst(<span class="string">"If-Modified-Since"</span>);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;310</td> <td class="nbHitsCovered"><a title="Line 310: Conditional coverage 100% (2/2).">&nbsp;19</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 310: Conditional coverage 100% (2/2)."> <span class="keyword">if</span> (ifModifiedSince == <span class="keyword">null</span>) {</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;311</td> <td class="nbHitsCovered">&nbsp;8</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span> <span class="keyword">null</span>;</pre></td></tr>
<tr> <td class="numLine">&nbsp;312</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;313</td> <td class="nbHitsCovered"><a title="Line 313: Conditional coverage 100% (2/2).">&nbsp;11</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 313: Conditional coverage 100% (2/2)."> <span class="keyword">for</span> (ThreadLocal&lt;DateFormat&gt; threadLocal : dateFormatsRfc2616) {</a></pre></td></tr>
<tr> <td class="numLine">&nbsp;314</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">try</span> {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;315</td> <td class="nbHitsCovered">&nbsp;16</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span> threadLocal.get().parse(ifModifiedSince);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;316</td> <td class="nbHitsCovered">&nbsp;6</td> <td class="src"><pre class="src">&nbsp; } <span class="keyword">catch</span> (java.text.ParseException e) {</pre></td></tr>
<tr> <td class="numLine">&nbsp;317</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// Ignore and try another format. We expect only to encounter the first</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;318</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">// format, however (the other formats are pre-HTTP/1.1).</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;319</td> <td class="nbHitsCovered">&nbsp;6</td> <td class="src"><pre class="src">&nbsp; log.log(Level.FINE, <span class="string">"Exception when parsing If-Modified-Since"</span>, e);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;320</td> <td class="nbHitsCovered">&nbsp;6</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;321</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;322</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; log.log(Level.WARNING, <span class="string">"Could not parse If-Modified-Since: {0}"</span>,</pre></td></tr>
<tr> <td class="numLine">&nbsp;323</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; ifModifiedSince);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;324</td> <td class="nbHitsCovered">&nbsp;1</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span> <span class="keyword">null</span>;</pre></td></tr>
<tr> <td class="numLine">&nbsp;325</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;326</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;327</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;328</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Determines if the headers have already been sent for the exchange.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;329</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> *</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;330</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * &lt;p&gt;This implementation currently uses an imperfect heuristic, but should</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;331</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * work well in most cases. It checks to see if the Date header is present,</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;332</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * which is added during {@link HttpExchange#sendResponseHeaders}.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;333</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;334</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> headersSent(HttpExchange ex) {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;335</td> <td class="nbHitsCovered"><a title="Line 335: Conditional coverage 100% (2/2).">&nbsp;15</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 335: Conditional coverage 100% (2/2)."> <span class="keyword">return</span> ex.getResponseHeaders().getFirst(<span class="string">"Date"</span>) != <span class="keyword">null</span>;</a></pre></td></tr>
<tr> <td class="numLine">&nbsp;336</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;337</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;338</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> setLastModified(HttpExchange ex, Date lastModified) {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;339</td> <td class="nbHitsCovered">&nbsp;10</td> <td class="src"><pre class="src">&nbsp; ex.getResponseHeaders().set(<span class="string">"Last-Modified"</span>,</pre></td></tr>
<tr> <td class="numLine">&nbsp;340</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; dateFormatRfc1123.get().format(lastModified));</pre></td></tr>
<tr> <td class="numLine">&nbsp;341</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;342</td> <td class="nbHitsCovered">&nbsp;10</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;343</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLine">&nbsp;344</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="comment">/**</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;345</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * Parse request GET query parameters of {@code ex} into its parts, correctly</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;346</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * taking into account {@code charset}. The encoding of the GET parameters is</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;347</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * not specified in the request parameters, so it must be negotiated elsewhere</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;348</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * (i.e., via hard-coding). ISO 8859-1 (Latin-1) and UTF-8 are the only</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;349</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * commonly used encodings for query parameters.</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;350</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> *</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;351</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * @param ex exchange whose request query string is to be parsed</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;352</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * @param charset character set used during encoding</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;353</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> * @return fully-decoded parameter values</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;354</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;<span class="comment"> */</span></pre></td></tr>
<tr> <td class="numLine">&nbsp;355</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">public</span> <span class="keyword">static</span> Map&lt;String, List&lt;String&gt;&gt; parseQueryParameters(HttpExchange ex,</pre></td></tr>
<tr> <td class="numLine">&nbsp;356</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; Charset charset) {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;357</td> <td class="nbHitsCovered">&nbsp;26</td> <td class="src"><pre class="src">&nbsp; String queryString = ex.getRequestURI().getRawQuery();</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;358</td> <td class="nbHitsUncovered"><a title="Line 358: Conditional coverage 75% (3/4) [each condition: 100%, 50%].">&nbsp;26</a></td> <td class="src"><pre class="src"><span class="srcUncovered">&nbsp;<a title="Line 358: Conditional coverage 75% (3/4) [each condition: 100%, 50%]."> <span class="keyword">if</span> (queryString == <span class="keyword">null</span> || queryString.isEmpty()) {</a></span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;359</td> <td class="nbHitsCovered">&nbsp;17</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span> Collections.emptyMap();</pre></td></tr>
<tr> <td class="numLine">&nbsp;360</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;361</td> <td class="nbHitsCovered">&nbsp;9</td> <td class="src"><pre class="src">&nbsp; Map&lt;String, List&lt;String&gt;&gt; parsedParams</pre></td></tr>
<tr> <td class="numLine">&nbsp;362</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; = <span class="keyword">new</span> TreeMap&lt;String, List&lt;String&gt;&gt;();</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;363</td> <td class="nbHitsCovered"><a title="Line 363: Conditional coverage 100% (2/2).">&nbsp;21</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 363: Conditional coverage 100% (2/2)."> <span class="keyword">for</span> (String param : queryString.split(<span class="string">"&amp;"</span>)) {</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;364</td> <td class="nbHitsCovered">&nbsp;12</td> <td class="src"><pre class="src">&nbsp; String[] parts = param.split(<span class="string">"="</span>, 2);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;365</td> <td class="nbHitsCovered">&nbsp;12</td> <td class="src"><pre class="src">&nbsp; String key = parts[0];</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;366</td> <td class="nbHitsCovered"><a title="Line 366: Conditional coverage 100% (2/2).">&nbsp;12</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 366: Conditional coverage 100% (2/2)."> String value = parts.length == 2 ? parts[1] : <span class="string">""</span>;</a></pre></td></tr>
<tr> <td class="numLine">&nbsp;367</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; <span class="keyword">try</span> {</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;368</td> <td class="nbHitsCovered">&nbsp;12</td> <td class="src"><pre class="src">&nbsp; key = URLDecoder.decode(key, charset.name());</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;369</td> <td class="nbHitsCovered">&nbsp;12</td> <td class="src"><pre class="src">&nbsp; value = URLDecoder.decode(value, charset.name());</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;370</td> <td class="nbHitsUncovered">&nbsp;0</td> <td class="src"><pre class="src"><span class="srcUncovered">&nbsp; } <span class="keyword">catch</span> (UnsupportedEncodingException e) {</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;371</td> <td class="nbHitsUncovered">&nbsp;0</td> <td class="src"><pre class="src"><span class="srcUncovered">&nbsp; <span class="keyword">throw</span> <span class="keyword">new</span> AssertionError(e);</span></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;372</td> <td class="nbHitsCovered">&nbsp;12</td> <td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;373</td> <td class="nbHitsCovered">&nbsp;12</td> <td class="src"><pre class="src">&nbsp; List&lt;String&gt; values = parsedParams.get(key);</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;374</td> <td class="nbHitsCovered"><a title="Line 374: Conditional coverage 100% (2/2).">&nbsp;12</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 374: Conditional coverage 100% (2/2)."> <span class="keyword">if</span> (values == <span class="keyword">null</span>) {</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;375</td> <td class="nbHitsCovered">&nbsp;10</td> <td class="src"><pre class="src">&nbsp; values = <span class="keyword">new</span> LinkedList&lt;String&gt;();</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;376</td> <td class="nbHitsCovered">&nbsp;10</td> <td class="src"><pre class="src">&nbsp; parsedParams.put(key, values);</pre></td></tr>
<tr> <td class="numLine">&nbsp;377</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;378</td> <td class="nbHitsCovered">&nbsp;12</td> <td class="src"><pre class="src">&nbsp; values.add(value);</pre></td></tr>
<tr> <td class="numLine">&nbsp;379</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;380</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;381</td> <td class="nbHitsCovered"><a title="Line 381: Conditional coverage 100% (2/2).">&nbsp;9</a></td> <td class="src"><pre class="src">&nbsp;<a title="Line 381: Conditional coverage 100% (2/2)."> <span class="keyword">for</span> (Map.Entry&lt;String, List&lt;String&gt;&gt; me : parsedParams.entrySet()) {</a></pre></td></tr>
<tr> <td class="numLineCover">&nbsp;382</td> <td class="nbHitsCovered">&nbsp;10</td> <td class="src"><pre class="src">&nbsp; me.setValue(Collections.unmodifiableList(me.getValue()));</pre></td></tr>
<tr> <td class="numLine">&nbsp;383</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLineCover">&nbsp;384</td> <td class="nbHitsCovered">&nbsp;9</td> <td class="src"><pre class="src">&nbsp; <span class="keyword">return</span> Collections.unmodifiableMap(parsedParams);</pre></td></tr>
<tr> <td class="numLine">&nbsp;385</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp; }</pre></td></tr>
<tr> <td class="numLine">&nbsp;386</td> <td class="nbHits">&nbsp;</td>
<td class="src"><pre class="src">&nbsp;}</pre></td></tr>
</table>
<div class="footer">Report generated by <a href="http://cobertura.sourceforge.net/" target="_top">Cobertura</a> 1.9.4.1.</div>
</body>
</html>