001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 * <p>
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 * <p>
009 * or (per the licensee's choosing)
010 * <p>
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.access.jetty;
015
016import java.util.HashMap;
017import java.util.Iterator;
018import java.util.Map;
019
020import ch.qos.logback.access.common.spi.ServerAdapter;
021import org.eclipse.jetty.http.HttpField;
022import org.eclipse.jetty.http.HttpFields;
023import org.eclipse.jetty.server.Request;
024import org.eclipse.jetty.server.Response;
025
026/**
027 * A Jetty 9.4.x and 10.0.x specific implementation of the {@link ServerAdapter} interface.
028 *
029 * @author S&eacute;bastien Pennec
030 * @author Ceki Gulcu
031 * @author Joakim Erdfelt
032 */
033public class JettyModernServerAdapter extends JettyServerAdapter {
034
035
036    public JettyModernServerAdapter(Request jettyRequest, Response jettyResponse) {
037        super(jettyRequest, jettyResponse);
038    }
039
040    @Override
041    public long getContentLength() {
042
043        return Response.getContentBytesWritten(response);
044        //return response.getHttpChannel().getBytesWritten();
045    }
046
047    @Override
048    public int getStatusCode() {
049        return response.getStatus();
050        //return response.getCommittedMetaData().getStatus();
051    }
052
053    @Override
054    public long getRequestTimestamp() {
055        return Request.getTimeStamp(request);
056    }
057
058    @Override
059    public Map<String, String> buildResponseHeaderMap() {
060        Map<String, String> responseHeaderMap = new HashMap<>();
061        HttpFields.Mutable httpFields = response.getHeaders();
062
063        for(HttpField field: httpFields) {
064            String key = field.getName();
065            String value = field.getValue();
066            responseHeaderMap.put(key, value);
067        }
068
069        return responseHeaderMap;
070    }
071
072}