OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.net; | 5 package org.chromium.net; |
6 | 6 |
7 import android.util.Log; | 7 import android.util.Log; |
8 import android.util.Pair; | 8 import android.util.Pair; |
9 | 9 |
10 import org.chromium.base.CalledByNative; | 10 import org.chromium.base.CalledByNative; |
11 import org.chromium.base.JNINamespace; | 11 import org.chromium.base.JNINamespace; |
12 | 12 |
13 import java.nio.ByteBuffer; | 13 import java.nio.ByteBuffer; |
14 import java.util.ArrayList; | 14 import java.util.ArrayList; |
15 import java.util.Collections; | 15 import java.util.Collections; |
16 import java.util.HashMap; | |
17 import java.util.List; | 16 import java.util.List; |
18 import java.util.Map; | 17 import java.util.Map; |
18 import java.util.TreeMap; | |
19 import java.util.concurrent.Executor; | 19 import java.util.concurrent.Executor; |
20 | 20 |
21 /** | 21 /** |
22 * UrlRequest using Chromium HTTP stack implementation. Could be accessed from | 22 * UrlRequest using Chromium HTTP stack implementation. Could be accessed from |
23 * any thread on Executor. Cancel can be done from any thread. | 23 * any thread on Executor. Cancel can be done from any thread. |
24 * All @CallByNative methods are called on native network thread | 24 * All @CallByNative methods are called on native network thread |
25 * and post tasks with listener calls onto Executor. Upon return from listener | 25 * and post tasks with listener calls onto Executor. Upon return from listener |
26 * callback native request adapter is called on executive thread and posts | 26 * callback native request adapter is called on executive thread and posts |
27 * native tasks to native network thread. Because Cancel could be called from | 27 * native tasks to native network thread. Because Cancel could be called from |
28 * any thread it is protected by mUrlRequestAdapterLock. | 28 * any thread it is protected by mUrlRequestAdapterLock. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 static final class NativeResponseInfo implements ResponseInfo { | 113 static final class NativeResponseInfo implements ResponseInfo { |
114 private final String[] mResponseInfoUrlChain; | 114 private final String[] mResponseInfoUrlChain; |
115 private final int mHttpStatusCode; | 115 private final int mHttpStatusCode; |
116 private final String mHttpStatusText; | 116 private final String mHttpStatusText; |
117 private final HeadersList mAllHeaders = new HeadersList(); | 117 private final HeadersList mAllHeaders = new HeadersList(); |
118 private final boolean mWasCached; | 118 private final boolean mWasCached; |
119 private final String mNegotiatedProtocol; | 119 private final String mNegotiatedProtocol; |
120 private Map<String, List<String>> mResponseHeaders; | |
120 | 121 |
121 NativeResponseInfo(String[] urlChain, int httpStatusCode, | 122 NativeResponseInfo(String[] urlChain, int httpStatusCode, |
122 String httpStatusText, boolean wasCached, | 123 String httpStatusText, boolean wasCached, |
123 String negotiatedProtocol) { | 124 String negotiatedProtocol) { |
124 mResponseInfoUrlChain = urlChain; | 125 mResponseInfoUrlChain = urlChain; |
125 mHttpStatusCode = httpStatusCode; | 126 mHttpStatusCode = httpStatusCode; |
126 mHttpStatusText = httpStatusText; | 127 mHttpStatusText = httpStatusText; |
127 mWasCached = wasCached; | 128 mWasCached = wasCached; |
128 mNegotiatedProtocol = negotiatedProtocol; | 129 mNegotiatedProtocol = negotiatedProtocol; |
129 } | 130 } |
(...skipping 18 matching lines...) Expand all Loading... | |
148 return mHttpStatusText; | 149 return mHttpStatusText; |
149 } | 150 } |
150 | 151 |
151 @Override | 152 @Override |
152 public List<Pair<String, String>> getAllHeadersAsList() { | 153 public List<Pair<String, String>> getAllHeadersAsList() { |
153 return Collections.unmodifiableList(mAllHeaders); | 154 return Collections.unmodifiableList(mAllHeaders); |
154 } | 155 } |
155 | 156 |
156 @Override | 157 @Override |
157 public Map<String, List<String>> getAllHeaders() { | 158 public Map<String, List<String>> getAllHeaders() { |
158 Map<String, List<String>> map = new HashMap<String, List<String>>(); | 159 if (mResponseHeaders != null) { |
160 return mResponseHeaders; | |
161 } | |
162 Map<String, List<String>> map = new TreeMap<String, List<String>>( | |
163 String.CASE_INSENSITIVE_ORDER); | |
159 for (Pair<String, String> entry : mAllHeaders) { | 164 for (Pair<String, String> entry : mAllHeaders) { |
165 List<String> values = new ArrayList<String>(); | |
160 if (map.containsKey(entry.first)) { | 166 if (map.containsKey(entry.first)) { |
miloslav
2015/01/20 15:25:10
There is no null key containing the status line an
xunjieli
2015/01/20 16:12:21
Yes, you are right. There is no null key support.
mef
2015/01/30 16:22:51
I think that's a right thing for CronetUrlRequest,
| |
161 map.get(entry.first).add(entry.second); | 167 values.addAll(map.get(entry.first)); |
162 } else { | |
163 List<String> values = new ArrayList<String>(); | |
164 values.add(entry.second); | |
165 map.put(entry.first, values); | |
166 } | 168 } |
169 values.add(entry.second); | |
170 map.put(entry.first, Collections.unmodifiableList(values)); | |
167 } | 171 } |
168 return Collections.unmodifiableMap(map); | 172 mResponseHeaders = Collections.unmodifiableMap(map); |
173 return mResponseHeaders; | |
169 } | 174 } |
170 | 175 |
171 @Override | 176 @Override |
172 public boolean wasCached() { | 177 public boolean wasCached() { |
173 return mWasCached; | 178 return mWasCached; |
174 } | 179 } |
175 | 180 |
176 @Override | 181 @Override |
177 public String getNegotiatedProtocol() { | 182 public String getNegotiatedProtocol() { |
178 return mNegotiatedProtocol; | 183 return mNegotiatedProtocol; |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 HeadersList headers); | 609 HeadersList headers); |
605 | 610 |
606 private native String nativeGetNegotiatedProtocol(long urlRequestAdapter); | 611 private native String nativeGetNegotiatedProtocol(long urlRequestAdapter); |
607 | 612 |
608 private native String nativeGetHttpStatusText(long urlRequestAdapter); | 613 private native String nativeGetHttpStatusText(long urlRequestAdapter); |
609 | 614 |
610 private native boolean nativeGetWasCached(long urlRequestAdapter); | 615 private native boolean nativeGetWasCached(long urlRequestAdapter); |
611 | 616 |
612 private native long nativeGetTotalReceivedBytes(long urlRequestAdapter); | 617 private native long nativeGetTotalReceivedBytes(long urlRequestAdapter); |
613 } | 618 } |
OLD | NEW |