001/**
002 * Copyright 2015 DuraSpace, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.fcrepo.client;
018
019import java.net.URI;
020
021import org.apache.http.client.config.RequestConfig;
022import org.apache.http.client.methods.HttpRequestBase;
023
024/**
025 * Builds a HEAD request to retrieve resource headers.
026 * 
027 * @author bbpennel
028 */
029public class HeadBuilder extends
030        RequestBuilder {
031
032    /**
033     * Instantiate builder
034     * 
035     * @param uri uri request will be issued to
036     * @param client the client
037     */
038    public HeadBuilder(final URI uri, final FcrepoClient client) {
039        super(uri, client);
040        this.request = HttpMethods.HEAD.createRequest(targetUri);
041    }
042
043    @Override
044    protected HttpRequestBase createRequest() {
045        return HttpMethods.HEAD.createRequest(targetUri);
046    }
047
048    /**
049     * Disable following redirects.
050     *
051     * @return this builder
052     */
053    public HeadBuilder disableRedirects() {
054        request.setConfig(RequestConfig.custom().setRedirectsEnabled(false).build());
055        return this;
056    }
057}