View | Details | Raw Unified | Return to bug 47364
Collapse All | Expand All

(-)java/org/apache/catalina/connector/Request.java (-2 / +21 lines)
Lines 29-37 Link Here
29
import java.util.Collection;
29
import java.util.Collection;
30
import java.util.Enumeration;
30
import java.util.Enumeration;
31
import java.util.HashMap;
31
import java.util.HashMap;
32
import java.util.HashSet;
32
import java.util.Iterator;
33
import java.util.Iterator;
33
import java.util.Locale;
34
import java.util.Locale;
34
import java.util.Map;
35
import java.util.Map;
36
import java.util.Set;
35
import java.util.TimeZone;
37
import java.util.TimeZone;
36
import java.util.TreeMap;
38
import java.util.TreeMap;
37
39
Lines 94-104 Link Here
94
96
95
    // ----------------------------------------------------------- Constructors
97
    // ----------------------------------------------------------- Constructors
96
98
99
    private static final Set<String> internalAttributeNames =
100
        new HashSet<String>();
101
    private static final Set<String> sslAttributeNames = new HashSet<String>();
97
102
98
    static {
103
    static {
99
        // Ensure that classes are loaded for SM
104
        // Ensure that classes are loaded for SM
100
        new StringCache.ByteEntry();
105
        new StringCache.ByteEntry();
101
        new StringCache.CharEntry();
106
        new StringCache.CharEntry();
107
        
108
        // Populate the lists of internal attribute names
109
        internalAttributeNames.add(Globals.DISPATCHER_TYPE_ATTR);
110
        internalAttributeNames.add(Globals.DISPATCHER_REQUEST_PATH_ATTR);
111
        internalAttributeNames.add(Globals.ASYNC_SUPPORTED_ATTR);
112
        sslAttributeNames.add(Globals.CERTIFICATES_ATTR);
113
        sslAttributeNames.add(Globals.CIPHER_SUITE_ATTR);
114
        sslAttributeNames.add(Globals.KEY_SIZE_ATTR);
115
        sslAttributeNames.add(Globals.SSL_SESSION_ID_ATTR);
116
        sslAttributeNames.add(Globals.SSL_SESSION_MGR_ATTR);
102
    }
117
    }
103
118
104
    public Request() {
119
    public Request() {
Lines 922-931 Link Here
922
     * empty <code>Enumeration</code> if there are none.
937
     * empty <code>Enumeration</code> if there are none.
923
     */
938
     */
924
    public Enumeration<String> getAttributeNames() {
939
    public Enumeration<String> getAttributeNames() {
940
        Set<String> names = new HashSet<String>();
941
        names.addAll(attributes.keySet());
942
        names.addAll(internalAttributeNames);
943
        names.addAll(coyoteRequest.getAttributes().keySet());
925
        if (isSecure()) {
944
        if (isSecure()) {
926
            getAttribute(Globals.CERTIFICATES_ATTR);
945
            names.addAll(sslAttributeNames);
927
        }
946
        }
928
        return new Enumerator<String>(attributes.keySet(), true);
947
        return new Enumerator<String>(names, false);
929
    }
948
    }
930
949
931
950
(-)test/org/apache/catalina/connector/TestRequest.java (+61 lines)
Lines 191-194 Link Here
191
        }
191
        }
192
        
192
        
193
    }
193
    }
194
195
    /**
196
     * Test case for https://issues.apache.org/bugzilla/show_bug.cgi?id=47364.
197
     * Responses to request.getAttributeNames() do not include the internal
198
     * Tomcat attributes
199
     */
200
    public void testBug47364() throws Exception {
201
        Bug47364Client client = new Bug47364Client();
202
        client.doRequest();
203
        assertTrue(client.isResponseBodyOK());
204
    }
205
    
206
    private static class Bug47364Servlet extends HttpServlet {
207
208
        private static final long serialVersionUID = 1L;
209
210
        @Override
211
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
212
                throws ServletException, IOException {
213
            PrintWriter out = resp.getWriter();
214
            Enumeration<String> names = req.getAttributeNames();
215
            while (names.hasMoreElements()) {
216
                out.println(names.nextElement());
217
            }
218
        }
219
        
220
    }
221
222
    private class Bug47364Client extends SimpleHttpClient {
223
224
        private void doRequest() throws Exception {
225
            Tomcat tomcat = getTomcatInstance();
226
            Connector connector =
227
                new Connector("org.apache.coyote.http11.Http11NioProtocol");
228
            connector.setPort(getNextPort());
229
            tomcat.getService().addConnector(connector);
230
            
231
            StandardContext root = tomcat.addContext("", TEMP_DIR);
232
            Tomcat.addServlet(root, "Bug47364", new Bug47364Servlet());
233
            root.addServletMapping("/test", "Bug47364");
234
            tomcat.start();
235
            
236
            setPort(connector.getPort());
237
            
238
            String[] request = new String[1];
239
            request[0] = "GET /test HTTP/1.0" + CRLF + CRLF;
240
            connect();
241
            setRequest(request);
242
            processRequest(); // blocks until response has been read
243
            
244
            // Close the connection
245
            disconnect();
246
        }
247
        
248
        @Override
249
        public boolean isResponseBodyOK() {
250
            return getResponseBody().contains(
251
                    "org.apache.tomcat.sendfile.support");
252
        }
253
        
254
    }
194
}
255
}

Return to bug 47364