Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: libadblockplus-android/src/org/adblockplus/android/AndroidWebRequest.java

Issue 29346561: Issue 4160 - Return headers in AndroidWebRequest (Closed)
Patch Set: Codestyle fixes #3 Created Sept. 8, 2016, 1:31 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.android; 18 package org.adblockplus.android;
19 19
20 import java.io.BufferedReader; 20 import java.io.BufferedReader;
21 import java.io.InputStreamReader; 21 import java.io.InputStreamReader;
22 import java.net.HttpURLConnection; 22 import java.net.HttpURLConnection;
23 import java.net.URL; 23 import java.net.URL;
24 import java.util.HashSet; 24 import java.util.HashSet;
25 import java.util.LinkedList;
25 import java.util.List; 26 import java.util.List;
27 import java.util.Map;
26 28
27 import org.adblockplus.libadblockplus.AdblockPlusException; 29 import org.adblockplus.libadblockplus.AdblockPlusException;
28 import org.adblockplus.libadblockplus.FilterEngine; 30 import org.adblockplus.libadblockplus.FilterEngine;
29 import org.adblockplus.libadblockplus.HeaderEntry; 31 import org.adblockplus.libadblockplus.HeaderEntry;
30 import org.adblockplus.libadblockplus.ServerResponse; 32 import org.adblockplus.libadblockplus.ServerResponse;
31 import org.adblockplus.libadblockplus.ServerResponse.NsStatus; 33 import org.adblockplus.libadblockplus.ServerResponse.NsStatus;
32 import org.adblockplus.libadblockplus.WebRequest; 34 import org.adblockplus.libadblockplus.WebRequest;
33 35
34 import android.util.Log; 36 import android.util.Log;
35 37
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 else 119 else
118 { 120 {
119 int character; 121 int character;
120 122
121 while ((character = reader.read()) != -1) 123 while ((character = reader.read()) != -1)
122 { 124 {
123 sb.append((char) character); 125 sb.append((char) character);
124 } 126 }
125 } 127 }
126 128
127 connection.disconnect();
128
129 response.setStatus(NsStatus.OK); 129 response.setStatus(NsStatus.OK);
130 response.setResponse(sb.toString()); 130 response.setResponse(sb.toString());
131
132 if (connection.getHeaderFields().size() > 0)
133 {
134 List<HeaderEntry> responseHeaders = new LinkedList<HeaderEntry>();
135 for (Map.Entry<String, List<String>> eachEntry : connection.getHeaderF ields().entrySet())
136 {
137 for (String eachValue : eachEntry.getValue())
138 {
139 if (eachEntry.getKey() != null && eachValue != null)
140 {
141 responseHeaders.add(new HeaderEntry(eachEntry.getKey(), eachValu e));
142 }
143 }
144 }
145 response.setReponseHeaders(responseHeaders);
146 }
147
148 connection.disconnect();
131 } 149 }
132 else 150 else
133 { 151 {
134 response.setStatus(NsStatus.ERROR_FAILURE); 152 response.setStatus(NsStatus.ERROR_FAILURE);
135 } 153 }
136 return response; 154 return response;
137 } 155 }
138 catch (final Throwable t) 156 catch (final Throwable t)
139 { 157 {
140 throw new AdblockPlusException("WebRequest failed", t); 158 throw new AdblockPlusException("WebRequest failed", t);
141 } 159 }
142 } 160 }
143 } 161 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld