mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-09-26 07:35:39 +00:00
Fix for [HER-1603?focusedCommentId=22557] browsers based on WebKit (Safari,
iPhone Safari, Chrome) use a screwy 'Accept' header that if taken literally
means they prefer 'application/xml' content. Thus trying to view web UI in
these browsers results in seeing the XML version, without element markup
* BaseResource.java
override getPreferredVariant() to bump up preference level of text/html for
any client can accept it
* EngineResource.java, JobResource.java
inherit from BaseResource
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of the Heritrix web crawler (crawler.archive.org).
|
||||
*
|
||||
* Licensed to the Internet Archive (IA) by one or more individual
|
||||
* contributors.
|
||||
*
|
||||
* The IA 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.
|
||||
*/
|
||||
|
||||
package org.archive.crawler.restlet;
|
||||
|
||||
import org.restlet.Context;
|
||||
import org.restlet.data.MediaType;
|
||||
import org.restlet.data.Preference;
|
||||
import org.restlet.data.Request;
|
||||
import org.restlet.data.Response;
|
||||
import org.restlet.resource.Resource;
|
||||
import org.restlet.resource.Variant;
|
||||
|
||||
/**
|
||||
* Abstract {@code Resource} with common shared functionality.
|
||||
*
|
||||
* @contributor nlevitt
|
||||
*/
|
||||
public abstract class BaseResource extends Resource {
|
||||
|
||||
public BaseResource(Context ctx, Request req, Response res) {
|
||||
super(ctx, req, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* If client can accept text/html, always prefer it. WebKit-based browsers
|
||||
* claim to want application/xml, but we don't want to give it to them. See
|
||||
* {@link https://webarchive.jira.com/browse/HER-1603}
|
||||
*/
|
||||
public Variant getPreferredVariant() {
|
||||
for (Preference<MediaType> mediaTypePreference: getRequest().getClientInfo().getAcceptedMediaTypes()) {
|
||||
if (mediaTypePreference.getMetadata().equals(MediaType.TEXT_HTML)) {
|
||||
mediaTypePreference.setQuality(Float.MAX_VALUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return super.getPreferredVariant();
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,6 @@ import org.restlet.data.MediaType;
|
||||
import org.restlet.data.Request;
|
||||
import org.restlet.data.Response;
|
||||
import org.restlet.resource.Representation;
|
||||
import org.restlet.resource.Resource;
|
||||
import org.restlet.resource.ResourceException;
|
||||
import org.restlet.resource.Variant;
|
||||
import org.restlet.resource.WriterRepresentation;
|
||||
@@ -56,7 +55,7 @@ import org.xml.sax.SAXException;
|
||||
*
|
||||
* @contributor gojomo
|
||||
*/
|
||||
public class EngineResource extends Resource {
|
||||
public class EngineResource extends BaseResource {
|
||||
|
||||
public EngineResource(Context ctx, Request req, Response res) {
|
||||
super(ctx, req, res);
|
||||
|
||||
@@ -57,7 +57,6 @@ import org.restlet.data.Request;
|
||||
import org.restlet.data.Response;
|
||||
import org.restlet.data.Status;
|
||||
import org.restlet.resource.Representation;
|
||||
import org.restlet.resource.Resource;
|
||||
import org.restlet.resource.ResourceException;
|
||||
import org.restlet.resource.Variant;
|
||||
import org.restlet.resource.WriterRepresentation;
|
||||
@@ -69,7 +68,7 @@ import org.xml.sax.SAXException;
|
||||
*
|
||||
* @contributor gojomo
|
||||
*/
|
||||
public class JobResource extends Resource {
|
||||
public class JobResource extends BaseResource {
|
||||
public static final IOFileFilter EDIT_FILTER =
|
||||
FileUtils.getRegexFileFilter(".*\\.((c?xml)|(txt))$");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user