From f7105a2773048be8229b80ca74a889c9b15348b6 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 15 Nov 2010 17:01:23 +0000 Subject: [PATCH] HADOOP-6496. HttpServer sends wrong content-type for CSS files (and others). Contributed by Todd Lipcon. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1035353 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 3 ++ build.xml | 7 ++-- .../org/apache/hadoop/http/HttpServer.java | 33 ++++++++++++++++--- .../hadoop/http/HttpServerFunctionalTest.java | 10 ++---- .../apache/hadoop/http/TestHttpServer.java | 25 ++++++++++++++ src/test/test-webapps/static/test.css | 21 ++++++++++++ src/test/test-webapps/test/.gitignore | 14 ++++++++ 7 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 src/test/test-webapps/static/test.css create mode 100644 src/test/test-webapps/test/.gitignore diff --git a/CHANGES.txt b/CHANGES.txt index 17c96c4f39..1b2cf168cb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -328,6 +328,9 @@ Trunk (unreleased changes) HADOOP-6899 RawLocalFileSystem#setWorkingDir() does not work for relative names (Sanjay Radia) + HADOOP-6496. HttpServer sends wrong content-type for CSS files + (and others). (Todd Lipcon via tomwhite) + Release 0.21.1 - Unreleased IMPROVEMENTS diff --git a/build.xml b/build.xml index 5418939b4a..5218a0d38c 100644 --- a/build.xml +++ b/build.xml @@ -79,7 +79,7 @@ - + @@ -206,6 +206,7 @@ + @@ -661,7 +662,9 @@ - + + + "))); } + @Test public void testContentTypes() throws Exception { + // Static CSS files should have text/css + URL cssUrl = new URL(baseUrl, "/static/test.css"); + HttpURLConnection conn = (HttpURLConnection)cssUrl.openConnection(); + conn.connect(); + assertEquals(200, conn.getResponseCode()); + assertEquals("text/css", conn.getContentType()); + + // Servlets should have text/html with proper encoding + URL servletUrl = new URL(baseUrl, "/echo?a=b"); + conn = (HttpURLConnection)servletUrl.openConnection(); + conn.connect(); + assertEquals(200, conn.getResponseCode()); + assertEquals("text/html; charset=utf-8", conn.getContentType()); + + // We should ignore parameters for mime types - ie a parameter + // ending in .css should not change mime type + servletUrl = new URL(baseUrl, "/echo?a=b.css"); + conn = (HttpURLConnection)servletUrl.openConnection(); + conn.connect(); + assertEquals(200, conn.getResponseCode()); + assertEquals("text/html; charset=utf-8", conn.getContentType()); + } + /** * Dummy filter that mimics as an authentication filter. Obtains user identity * from the request parameter user.name. Wraps around the request so that diff --git a/src/test/test-webapps/static/test.css b/src/test/test-webapps/static/test.css new file mode 100644 index 0000000000..ae4382869a --- /dev/null +++ b/src/test/test-webapps/static/test.css @@ -0,0 +1,21 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Test CSS file for content type handling - empty, since we just check + * returned content type! + */ diff --git a/src/test/test-webapps/test/.gitignore b/src/test/test-webapps/test/.gitignore new file mode 100644 index 0000000000..ae1e83eeb3 --- /dev/null +++ b/src/test/test-webapps/test/.gitignore @@ -0,0 +1,14 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.