From c92a3316562db2708f3958dca79343d6a0ca29f3 Mon Sep 17 00:00:00 2001 From: gotty Date: Tue, 4 Jul 2017 13:59:45 +0000 Subject: [PATCH] [LIB-8] Add header X-Requested-By to HTTP requests git-svn-id: https://svn.hedgecode.org/lib/snooker-score-api/trunk@130 fb0bcced-7025-49ed-a12f-f98bce993226 --- src/main/java/org/hedgecode/snooker/request/AbstractRequester.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/hedgecode/snooker/request/AbstractRequester.java b/src/main/java/org/hedgecode/snooker/request/AbstractRequester.java index db8e5eb..d4ec2db 100644 --- a/src/main/java/org/hedgecode/snooker/request/AbstractRequester.java +++ b/src/main/java/org/hedgecode/snooker/request/AbstractRequester.java @@ -34,6 +34,9 @@ public abstract class AbstractRequester implements Requester { protected static final String API_SNOOKER_URL = "http://api.snooker.org/"; protected static final Charset API_SNOOKER_CHARSET = StandardCharsets.UTF_8; + private static final String API_SNOOKER_HEADER_NAME = "X-Requested-By"; + private static final String API_SNOOKER_HEADER_VALUE = "Hedgecode"; + protected abstract String getRequestUrl(int id) throws RequestException; protected abstract String getRequestUrl(RequestParams params) throws RequestException; @@ -57,6 +60,9 @@ public abstract class AbstractRequester implements Requester { try { URL url = new URL(requestUrl); URLConnection urlConnection = url.openConnection(); + urlConnection.setRequestProperty( + API_SNOOKER_HEADER_NAME, API_SNOOKER_HEADER_VALUE + ); BufferedReader br = new BufferedReader( new InputStreamReader( urlConnection.getInputStream(), API_SNOOKER_CHARSET -- 2.10.0