Skip to content

Commit 8268b26

Browse files
author
Caitlin Bales (MSFT)
committed
Add response code to headers
1 parent ac403fa commit 8268b26

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/main/java/com/microsoft/graph/http/UrlConnection.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.OutputStream;
3030
import java.net.HttpURLConnection;
3131
import java.net.ProtocolException;
32+
import java.util.ArrayList;
3233
import java.util.HashMap;
3334
import java.util.List;
3435
import java.util.Map;
@@ -110,7 +111,20 @@ public int getResponseCode() throws IOException {
110111
}
111112

112113
public Map<String, List<String>> getResponseHeaders() {
113-
return connection.getHeaderFields();
114+
// Copy unmodifiable map to hashmap
115+
HashMap<String, List<String>> headerFields = new HashMap<>();
116+
headerFields.putAll(connection.getHeaderFields());
117+
118+
// Add the response code
119+
List<String> list = new ArrayList<>();
120+
try {
121+
list.add(String.format("%d", connection.getResponseCode()));
122+
} catch (IOException e) {
123+
throw new IllegalArgumentException("Invalid connection response code: ", e);
124+
}
125+
126+
headerFields.put("responseCode", list);
127+
return headerFields;
114128
}
115129

116130
@Override

0 commit comments

Comments
 (0)