001/*
002 *  Copyright 2017 Anyware Services
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 */
016package org.ametys.plugins.workspacessite;
017
018import java.util.Enumeration;
019
020import org.apache.cocoon.environment.Request;
021import org.apache.cocoon.environment.Response;
022import org.apache.http.Header;
023import org.apache.http.HttpResponse;
024import org.apache.http.client.methods.HttpUriRequest;
025
026import org.ametys.plugins.site.proxy.BackOfficeRequestProxy;
027
028/**
029 * Handle webdav requests from and to backoffice.
030 */
031public class WebdavProxy implements BackOfficeRequestProxy
032{
033    public void prepareBackOfficeRequest(Request request, HttpUriRequest backOfficeRequest)
034    {
035        String[] headerNames = new String[]{"Lock-Token"};
036        
037        for (String headerName : headerNames)
038        {
039            Enumeration<String> headers = request.getHeaders(headerName);
040            while (headers.hasMoreElements())
041            {
042                String value = headers.nextElement();
043                backOfficeRequest.addHeader(headerName, value);
044            }
045        }
046    }
047    
048    public void handleBackOfficeResponse(Response response, HttpResponse backOfficeResponse)
049    {
050        String[] headerNames = new String[]{"DAV", "Ms-Author-Via", "Lock-Token"};
051                
052        for (String headerName : headerNames)
053        {
054            Header[] headers = backOfficeResponse.getHeaders(headerName);
055            for (Header header : headers)
056            {
057                String value = header.getValue();
058                response.addHeader(headerName, value);
059            }
060        }
061    }
062}