1/* 2 * Copyright (C) 2014 Square, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package com.squareup.okhttp.internal.http; 17 18import com.squareup.okhttp.Headers; 19import com.squareup.okhttp.MediaType; 20import com.squareup.okhttp.ResponseBody; 21import okio.BufferedSource; 22 23public final class RealResponseBody extends ResponseBody { 24 private final Headers headers; 25 private final BufferedSource source; 26 27 public RealResponseBody(Headers headers, BufferedSource source) { 28 this.headers = headers; 29 this.source = source; 30 } 31 32 @Override public MediaType contentType() { 33 String contentType = headers.get("Content-Type"); 34 return contentType != null ? MediaType.parse(contentType) : null; 35 } 36 37 @Override public long contentLength() { 38 return OkHeaders.contentLength(headers); 39 } 40 41 @Override public BufferedSource source() { 42 return source; 43 } 44} 45