Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(775)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/HttpRequest.java

Issue 1989963003: Set User-Agent and Accept-Language request headers for PWS requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/HttpRequest.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/HttpRequest.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/HttpRequest.java
index d09ff5e38db2d2c1f17e1504d2586e3ce3042f99..11feaebc25da5862f35b5a06e6bba3dfa8ef125f 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/HttpRequest.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/HttpRequest.java
@@ -18,18 +18,30 @@ import java.net.URL;
* @param <T> The type representing the request payload.
*/
abstract class HttpRequest<T> implements Runnable {
+ // HTTP request header field names
+ private static final String USER_AGENT_HEADER_NAME = "User-Agent";
+ private static final String ACCEPT_LANGUAGE_HEADER_NAME = "Accept-Language";
+
private final URL mUrl;
+ private final String mUserAgent;
+ private final String mAcceptLanguage;
private final HttpRequestCallback<T> mCallback;
/**
* Construct a Request object.
* @param url The URL to make an HTTP request to.
+ * @param userAgent The string to set as the User-Agent request header.
+ * @param acceptLanguage The string to set as the Accept-Language request header.
* @param callback The callback run when the HTTP response is received.
* The callback will be run on the main thread.
* @throws MalformedURLException on invalid url
*/
- public HttpRequest(String url, HttpRequestCallback<T> callback) throws MalformedURLException {
+ public HttpRequest(String url, String userAgent, String acceptLanguage,
+ HttpRequestCallback<T> callback)
+ throws MalformedURLException {
mUrl = new URL(url);
+ mUserAgent = userAgent;
+ mAcceptLanguage = acceptLanguage;
if (!mUrl.getProtocol().equals("http") && !mUrl.getProtocol().equals("https")) {
throw new MalformedURLException("This is not a http or https URL: " + url);
}
@@ -70,6 +82,8 @@ abstract class HttpRequest<T> implements Runnable {
// Make the request
try {
urlConnection = (HttpURLConnection) mUrl.openConnection();
+ urlConnection.setRequestProperty(USER_AGENT_HEADER_NAME, mUserAgent);
+ urlConnection.setRequestProperty(ACCEPT_LANGUAGE_HEADER_NAME, mAcceptLanguage);
writeToUrlConnection(urlConnection);
responseCode = urlConnection.getResponseCode();
inputStream = new BufferedInputStream(urlConnection.getInputStream());

Powered by Google App Engine
This is Rietveld 408576698