001package com.box.sdk; 002 003import java.io.ByteArrayInputStream; 004import java.io.IOException; 005import java.io.InputStream; 006import java.io.OutputStream; 007import java.net.HttpURLConnection; 008import java.net.MalformedURLException; 009import java.net.ProtocolException; 010import java.net.URL; 011import java.security.KeyManagementException; 012import java.security.NoSuchAlgorithmException; 013import java.util.ArrayList; 014import java.util.List; 015import java.util.Map; 016import java.util.logging.Level; 017import java.util.logging.Logger; 018import javax.net.ssl.HttpsURLConnection; 019import javax.net.ssl.SSLContext; 020import javax.net.ssl.SSLParameters; 021import javax.net.ssl.SSLSocketFactory; 022 023import com.box.sdk.http.HttpHeaders; 024import com.box.sdk.http.HttpMethod; 025 026 027/** 028 * Used to make HTTP requests to the Box API. 029 * 030 * <p>All requests to the REST API are sent using this class or one of its subclasses. This class wraps {@link 031 * HttpURLConnection} in order to provide a simpler interface that can automatically handle various conditions specific 032 * to Box's API. Requests will be authenticated using a {@link BoxAPIConnection} (if one is provided), so it isn't 033 * necessary to add authorization headers. Requests can also be sent more than once, unlike with HttpURLConnection. If 034 * an error occurs while sending a request, it will be automatically retried (with a back off delay) up to the maximum 035 * number of times set in the BoxAPIConnection.</p> 036 * 037 * <p>Specifying a body for a BoxAPIRequest is done differently than it is with HttpURLConnection. Instead of writing to 038 * an OutputStream, the request is provided an {@link InputStream} which will be read when the {@link #send} method is 039 * called. This makes it easy to retry requests since the stream can automatically reset and reread with each attempt. 040 * If the stream cannot be reset, then a new stream will need to be provided before each call to send. There is also a 041 * convenience method for specifying the body as a String, which simply wraps the String with an InputStream.</p> 042 */ 043public class BoxAPIRequest { 044 private static final Logger LOGGER = Logger.getLogger(BoxAPIRequest.class.getName()); 045 private static final int BUFFER_SIZE = 8192; 046 private static final int MAX_REDIRECTS = 3; 047 private static SSLSocketFactory sslSocketFactory; 048 049 private final BoxAPIConnection api; 050 private final List<RequestHeader> headers; 051 private final String method; 052 053 private URL url; 054 private BackoffCounter backoffCounter; 055 private int connectTimeout; 056 private int readTimeout; 057 private InputStream body; 058 private long bodyLength; 059 private Map<String, List<String>> requestProperties; 060 private int numRedirects; 061 private boolean followRedirects = true; 062 private boolean shouldAuthenticate; 063 064 static { 065 // Setup the SSL context manually to force newer TLS version on legacy Java environments 066 // This is necessary because Java 7 uses TLSv1.0 by default, but the Box API will need 067 // to deprecate this protocol in the future. To prevent clients from breaking, we must 068 // ensure that they are using TLSv1.1 or greater! 069 SSLContext sc = null; 070 try { 071 sc = SSLContext.getDefault(); 072 SSLParameters params = sc.getDefaultSSLParameters(); 073 boolean supportsNewTLS = false; 074 for (String protocol : params.getProtocols()) { 075 if (protocol.compareTo("TLSv1") > 0) { 076 supportsNewTLS = true; 077 break; 078 } 079 } 080 if (!supportsNewTLS) { 081 // Try to upgrade to a higher TLS version 082 sc = null; 083 sc = SSLContext.getInstance("TLSv1.1"); 084 sc.init(null, null, new java.security.SecureRandom()); 085 sc = SSLContext.getInstance("TLSv1.2"); 086 sc.init(null, null, new java.security.SecureRandom()); 087 } 088 } catch (NoSuchAlgorithmException ex) { 089 if (sc == null) { 090 LOGGER.warning("Unable to set up SSL context for HTTPS! This may result in the inability " 091 + " to connect to the Box API."); 092 } 093 if (sc != null && sc.getProtocol().equals("TLSv1")) { 094 // Could not find a good version of TLS 095 LOGGER.warning("Using deprecated TLSv1 protocol, which will be deprecated by the Box API! Upgrade " 096 + "to a newer version of Java as soon as possible."); 097 } 098 } catch (KeyManagementException ex) { 099 LOGGER.warning("Exception when initializing SSL Context! This may result in the inabilty to connect to " 100 + "the Box API"); 101 sc = null; 102 } 103 104 if (sc != null) { 105 sslSocketFactory = sc.getSocketFactory(); 106 } 107 108 } 109 110 /** 111 * Constructs an unauthenticated BoxAPIRequest. 112 * @param url the URL of the request. 113 * @param method the HTTP method of the request. 114 */ 115 public BoxAPIRequest(URL url, String method) { 116 this(null, url, method); 117 } 118 119 /** 120 * Constructs an authenticated BoxAPIRequest using a provided BoxAPIConnection. 121 * @param api an API connection for authenticating the request. 122 * @param url the URL of the request. 123 * @param method the HTTP method of the request. 124 */ 125 public BoxAPIRequest(BoxAPIConnection api, URL url, String method) { 126 this.api = api; 127 this.url = url; 128 this.method = method; 129 this.headers = new ArrayList<RequestHeader>(); 130 if (api != null) { 131 Map<String, String> customHeaders = api.getHeaders(); 132 if (customHeaders != null) { 133 for (String header : customHeaders.keySet()) { 134 this.addHeader(header, customHeaders.get(header)); 135 } 136 } 137 this.headers.add(new RequestHeader("X-Box-UA", api.getBoxUAHeader())); 138 } 139 this.backoffCounter = new BackoffCounter(new Time()); 140 this.shouldAuthenticate = true; 141 if (api != null) { 142 this.connectTimeout = api.getConnectTimeout(); 143 this.readTimeout = api.getReadTimeout(); 144 } else { 145 this.connectTimeout = BoxGlobalSettings.getConnectTimeout(); 146 this.readTimeout = BoxGlobalSettings.getReadTimeout(); 147 } 148 149 this.addHeader("Accept-Encoding", "gzip"); 150 this.addHeader("Accept-Charset", "utf-8"); 151 152 } 153 154 /** 155 * Constructs an authenticated BoxAPIRequest using a provided BoxAPIConnection. 156 * @param api an API connection for authenticating the request. 157 * @param url the URL of the request. 158 * @param method the HTTP method of the request. 159 */ 160 public BoxAPIRequest(BoxAPIConnection api, URL url, HttpMethod method) { 161 this(api, url, method.name()); 162 } 163 164 /** 165 * Constructs an request, using URL and HttpMethod. 166 * @param url the URL of the request. 167 * @param method the HTTP method of the request. 168 */ 169 public BoxAPIRequest(URL url, HttpMethod method) { 170 this(url, method.name()); 171 } 172 173 /** 174 * Adds an HTTP header to this request. 175 * @param key the header key. 176 * @param value the header value. 177 */ 178 public void addHeader(String key, String value) { 179 if (key.equals("As-User")) { 180 for (int i = 0; i < this.headers.size(); i++) { 181 if (this.headers.get(i).getKey().equals("As-User")) { 182 this.headers.remove(i); 183 } 184 } 185 } 186 if (key.equals("X-Box-UA")) { 187 throw new IllegalArgumentException("Altering the X-Box-UA header is not permitted"); 188 } 189 this.headers.add(new RequestHeader(key, value)); 190 } 191 192 /** 193 * Sets a Connect timeout for this request in milliseconds. 194 * @param timeout the timeout in milliseconds. 195 */ 196 public void setConnectTimeout(int timeout) { 197 this.connectTimeout = timeout; 198 } 199 200 /** 201 * Gets the connect timeout for the request. 202 * @return the request connection timeout. 203 */ 204 public int getConnectTimeout() { 205 return this.connectTimeout; 206 } 207 208 /** 209 * Sets a read timeout for this request in milliseconds. 210 * @param timeout the timeout in milliseconds. 211 */ 212 public void setReadTimeout(int timeout) { 213 this.readTimeout = timeout; 214 } 215 216 /** 217 * Gets the read timeout for the request. 218 * @return the request's read timeout. 219 */ 220 public int getReadTimeout() { 221 return this.readTimeout; 222 } 223 224 /** 225 * Sets whether or not to follow redirects (i.e. Location header) 226 * @param followRedirects true to follow, false to not follow 227 */ 228 public void setFollowRedirects(boolean followRedirects) { 229 this.followRedirects = followRedirects; 230 } 231 232 /** 233 * Gets the stream containing contents of this request's body. 234 * 235 * <p>Note that any bytes that read from the returned stream won't be sent unless the stream is reset back to its 236 * initial position.</p> 237 * 238 * @return an InputStream containing the contents of this request's body. 239 */ 240 public InputStream getBody() { 241 return this.body; 242 } 243 244 /** 245 * Sets the request body to the contents of an InputStream. 246 * 247 * <p>The stream must support the {@link InputStream#reset} method if auto-retry is used or if the request needs to 248 * be resent. Otherwise, the body must be manually set before each call to {@link #send}.</p> 249 * 250 * @param stream an InputStream containing the contents of the body. 251 */ 252 public void setBody(InputStream stream) { 253 this.body = stream; 254 } 255 256 /** 257 * Sets the request body to the contents of an InputStream. 258 * 259 * <p>Providing the length of the InputStream allows for the progress of the request to be monitored when calling 260 * {@link #send(ProgressListener)}.</p> 261 * 262 * <p> See {@link #setBody(InputStream)} for more information on setting the body of the request.</p> 263 * 264 * @param stream an InputStream containing the contents of the body. 265 * @param length the expected length of the stream. 266 */ 267 public void setBody(InputStream stream, long length) { 268 this.bodyLength = length; 269 this.body = stream; 270 } 271 272 /** 273 * Sets the request body to the contents of a String. 274 * 275 * <p>If the contents of the body are large, then it may be more efficient to use an {@link InputStream} instead of 276 * a String. Using a String requires that the entire body be in memory before sending the request.</p> 277 * 278 * @param body a String containing the contents of the body. 279 */ 280 public void setBody(String body) { 281 byte[] bytes = body.getBytes(StandardCharsets.UTF_8); 282 this.bodyLength = bytes.length; 283 this.body = new ByteArrayInputStream(bytes); 284 } 285 286 /** 287 * Gets the URL from the request. 288 * 289 * @return a URL containing the URL of the request. 290 */ 291 public URL getUrl() { 292 return this.url; 293 } 294 295 /** 296 * Gets the http method from the request. 297 * 298 * @return http method 299 */ 300 public String getMethod() { 301 return this.method; 302 } 303 304 /** 305 * Get headers as list of RequestHeader objects. 306 * @return headers as list of RequestHeader objects 307 */ 308 protected List<RequestHeader> getHeaders() { 309 return this.headers; 310 } 311 312 /** 313 * Sends this request and returns a BoxAPIResponse containing the server's response. 314 * 315 * <p>The type of the returned BoxAPIResponse will be based on the content type returned by the server, allowing it 316 * to be cast to a more specific type. For example, if it's known that the API call will return a JSON response, 317 * then it can be cast to a {@link BoxJSONResponse} like so:</p> 318 * 319 * <pre>BoxJSONResponse response = (BoxJSONResponse) request.sendWithoutRetry();</pre> 320 * 321 * @throws BoxAPIException if the server returns an error code or if a network error occurs. 322 * @return a {@link BoxAPIResponse} containing the server's response. 323 */ 324 public BoxAPIResponse sendWithoutRetry() { 325 return this.trySend(null); 326 } 327 328 /** 329 * Sends this request and returns a BoxAPIResponse containing the server's response. 330 * 331 * <p>The type of the returned BoxAPIResponse will be based on the content type returned by the server, allowing it 332 * to be cast to a more specific type. For example, if it's known that the API call will return a JSON response, 333 * then it can be cast to a {@link BoxJSONResponse} like so:</p> 334 * 335 * <pre>BoxJSONResponse response = (BoxJSONResponse) request.send();</pre> 336 * 337 * <p>If the server returns an error code or if a network error occurs, then the request will be automatically 338 * retried. If the maximum number of retries is reached and an error still occurs, then a {@link BoxAPIException} 339 * will be thrown.</p> 340 * 341 * <p> See {@link #send} for more information on sending requests.</p> 342 * 343 * @throws BoxAPIException if the server returns an error code or if a network error occurs. 344 * @return a {@link BoxAPIResponse} containing the server's response. 345 */ 346 public BoxAPIResponse send() { 347 return this.send(null); 348 } 349 350 /** 351 * Sends this request while monitoring its progress and returns a BoxAPIResponse containing the server's response. 352 * 353 * <p>The type of the returned BoxAPIResponse will be based on the content type returned by the server, allowing it 354 * to be cast to a more specific type. For example, if it's known that the API call will return a JSON response, 355 * then it can be cast to a {@link BoxJSONResponse} like so:</p> 356 * 357 * <p>If the server returns an error code or if a network error occurs, then the request will be automatically 358 * retried. If the maximum number of retries is reached and an error still occurs, then a {@link BoxAPIException} 359 * will be thrown.</p> 360 * 361 * <p>A ProgressListener is generally only useful when the size of the request is known beforehand. If the size is 362 * unknown, then the ProgressListener will be updated for each byte sent, but the total number of bytes will be 363 * reported as 0.</p> 364 * 365 * <p> See {@link #send} for more information on sending requests.</p> 366 * 367 * @param listener a listener for monitoring the progress of the request. 368 * @throws BoxAPIException if the server returns an error code or if a network error occurs. 369 * @return a {@link BoxAPIResponse} containing the server's response. 370 */ 371 public BoxAPIResponse send(ProgressListener listener) { 372 if (this.api == null) { 373 this.backoffCounter.reset(BoxGlobalSettings.getMaxRequestAttempts()); 374 } else { 375 this.backoffCounter.reset(this.api.getMaxRequestAttempts()); 376 } 377 378 while (this.backoffCounter.getAttemptsRemaining() > 0) { 379 try { 380 return this.trySend(listener); 381 } catch (BoxAPIException apiException) { 382 if (!this.backoffCounter.decrement() || !isResponseRetryable(apiException.getResponseCode())) { 383 throw apiException; 384 } 385 386 LOGGER.log(Level.WARNING, "Retrying request due to transient error status=%d body=%s", 387 new Object[] {apiException.getResponseCode(), apiException.getResponse()}); 388 389 try { 390 this.resetBody(); 391 } catch (IOException ioException) { 392 throw apiException; 393 } 394 395 try { 396 this.backoffCounter.waitBackoff(); 397 } catch (InterruptedException interruptedException) { 398 Thread.currentThread().interrupt(); 399 throw apiException; 400 } 401 } 402 } 403 404 throw new RuntimeException(); 405 } 406 407 /** 408 * Returns a String containing the URL, HTTP method, headers and body of this request. 409 * @return a String containing information about this request. 410 */ 411 @Override 412 public String toString() { 413 String lineSeparator = System.getProperty("line.separator"); 414 StringBuilder builder = new StringBuilder(); 415 builder.append("Request"); 416 builder.append(lineSeparator); 417 builder.append(this.method); 418 builder.append(' '); 419 builder.append(this.url.toString()); 420 builder.append(lineSeparator); 421 422 if (this.requestProperties != null) { 423 424 for (Map.Entry<String, List<String>> entry : this.requestProperties.entrySet()) { 425 List<String> nonEmptyValues = new ArrayList<String>(); 426 for (String value : entry.getValue()) { 427 if (value != null && value.trim().length() != 0) { 428 nonEmptyValues.add(value); 429 } 430 } 431 432 if (nonEmptyValues.size() == 0) { 433 continue; 434 } 435 436 builder.append(entry.getKey()); 437 builder.append(": "); 438 for (String value : nonEmptyValues) { 439 builder.append(value); 440 builder.append(", "); 441 } 442 443 builder.delete(builder.length() - 2, builder.length()); 444 builder.append(lineSeparator); 445 } 446 } 447 448 String bodyString = this.bodyToString(); 449 if (bodyString != null) { 450 builder.append(lineSeparator); 451 builder.append(bodyString); 452 } 453 454 return builder.toString().trim(); 455 } 456 457 /** 458 * Returns a String representation of this request's body used in {@link #toString}. This method returns 459 * null by default. 460 * 461 * <p>A subclass may want override this method if the body can be converted to a String for logging or debugging 462 * purposes.</p> 463 * 464 * @return a String representation of this request's body. 465 */ 466 protected String bodyToString() { 467 return null; 468 } 469 470 /** 471 * Writes the body of this request to an HttpURLConnection. 472 * 473 * <p>Subclasses overriding this method must remember to close the connection's OutputStream after writing.</p> 474 * 475 * @param connection the connection to which the body should be written. 476 * @param listener an optional listener for monitoring the write progress. 477 * @throws BoxAPIException if an error occurs while writing to the connection. 478 */ 479 protected void writeBody(HttpURLConnection connection, ProgressListener listener) { 480 if (this.body == null) { 481 return; 482 } 483 484 connection.setDoOutput(true); 485 try { 486 OutputStream output = connection.getOutputStream(); 487 if (listener != null) { 488 output = new ProgressOutputStream(output, listener, this.bodyLength); 489 } 490 int b = this.body.read(); 491 while (b != -1) { 492 output.write(b); 493 b = this.body.read(); 494 } 495 output.close(); 496 } catch (IOException e) { 497 throw new BoxAPIException("Couldn't connect to the Box API due to a network error.", e); 498 } 499 } 500 501 /** 502 * Resets the InputStream containing this request's body. 503 * 504 * <p>This method will be called before each attempt to resend the request, giving subclasses an opportunity to 505 * reset any streams that need to be read when sending the body.</p> 506 * 507 * @throws IOException if the stream cannot be reset. 508 */ 509 protected void resetBody() throws IOException { 510 if (this.body != null) { 511 this.body.reset(); 512 } 513 } 514 515 void setBackoffCounter(BackoffCounter counter) { 516 this.backoffCounter = counter; 517 } 518 519 private BoxAPIResponse trySend(ProgressListener listener) { 520 if (this.api != null) { 521 RequestInterceptor interceptor = this.api.getRequestInterceptor(); 522 if (interceptor != null) { 523 BoxAPIResponse response = interceptor.onRequest(this); 524 if (response != null) { 525 return response; 526 } 527 } 528 } 529 530 HttpURLConnection connection = this.createConnection(); 531 532 if (connection instanceof HttpsURLConnection) { 533 HttpsURLConnection httpsConnection = (HttpsURLConnection) connection; 534 535 if (sslSocketFactory != null) { 536 httpsConnection.setSSLSocketFactory(sslSocketFactory); 537 } 538 } 539 540 if (this.bodyLength > 0) { 541 connection.setFixedLengthStreamingMode((int) this.bodyLength); 542 connection.setDoOutput(true); 543 } 544 545 if (this.api != null) { 546 if (this.shouldAuthenticate) { 547 connection.addRequestProperty(HttpHeaders.AUTHORIZATION, "Bearer " + this.api.lockAccessToken()); 548 } 549 connection.setRequestProperty("User-Agent", this.api.getUserAgent()); 550 if (this.api.getProxy() != null) { 551 if (this.api.getProxyUsername() != null && this.api.getProxyPassword() != null) { 552 String usernameAndPassword = this.api.getProxyUsername() + ":" + this.api.getProxyPassword(); 553 String encoded = new String(Base64.encode(usernameAndPassword.getBytes())); 554 connection.addRequestProperty("Proxy-Authorization", "Basic " + encoded); 555 } 556 } 557 558 if (this.api instanceof SharedLinkAPIConnection) { 559 SharedLinkAPIConnection sharedItemAPI = (SharedLinkAPIConnection) this.api; 560 String sharedLink = sharedItemAPI.getSharedLink(); 561 String boxAPIValue = "shared_link=" + sharedLink; 562 String sharedLinkPassword = sharedItemAPI.getSharedLinkPassword(); 563 if (sharedLinkPassword != null) { 564 boxAPIValue += "&shared_link_password=" + sharedLinkPassword; 565 } 566 connection.addRequestProperty("BoxApi", boxAPIValue); 567 } 568 } 569 570 this.requestProperties = connection.getRequestProperties(); 571 572 int responseCode; 573 try { 574 this.writeBody(connection, listener); 575 576 // Ensure that we're connected in case writeBody() didn't write anything. 577 try { 578 connection.connect(); 579 } catch (IOException e) { 580 throw new BoxAPIException("Couldn't connect to the Box API due to a network error.", e); 581 } 582 583 this.logRequest(connection); 584 585 // We need to manually handle redirects by creating a new HttpURLConnection so that connection pooling 586 // happens correctly. There seems to be a bug in Oracle's Java implementation where automatically handled 587 // redirects will not keep the connection alive. 588 try { 589 responseCode = connection.getResponseCode(); 590 } catch (IOException e) { 591 throw new BoxAPIException("Couldn't connect to the Box API due to a network error.", e); 592 } 593 } finally { 594 if (this.api != null && this.shouldAuthenticate) { 595 this.api.unlockAccessToken(); 596 } 597 } 598 599 if (isResponseRedirect(responseCode)) { 600 return this.handleRedirect(connection, listener); 601 } 602 603 String contentType = connection.getContentType(); 604 BoxAPIResponse response; 605 if (contentType == null) { 606 response = new BoxAPIResponse(connection); 607 } else if (contentType.contains("application/json")) { 608 response = new BoxJSONResponse(connection); 609 } else { 610 response = new BoxAPIResponse(connection); 611 } 612 613 return response; 614 } 615 616 private BoxAPIResponse handleRedirect(HttpURLConnection connection, ProgressListener listener) { 617 if (this.numRedirects >= MAX_REDIRECTS) { 618 throw new BoxAPIException("The Box API responded with too many redirects."); 619 } 620 this.numRedirects++; 621 622 // Even though the redirect response won't have a body, we need to read the InputStream so that Java will put 623 // the connection back in the connection pool. 624 try { 625 InputStream stream = connection.getInputStream(); 626 byte[] buffer = new byte[8192]; 627 int n = stream.read(buffer); 628 while (n != -1) { 629 n = stream.read(buffer); 630 } 631 stream.close(); 632 } catch (IOException e) { 633 throw new BoxAPIException("Couldn't connect to the Box API due to a network error.", e); 634 } 635 636 String redirect = connection.getHeaderField("Location"); 637 try { 638 this.url = new URL(redirect); 639 } catch (MalformedURLException e) { 640 throw new BoxAPIException("The Box API responded with an invalid redirect.", e); 641 } 642 643 if (this.followRedirects) { 644 return this.trySend(listener); 645 } else { 646 BoxRedirectResponse redirectResponse = new BoxRedirectResponse(); 647 redirectResponse.setRedirectURL(this.url); 648 return redirectResponse; 649 } 650 } 651 652 private void logRequest(HttpURLConnection connection) { 653 if (LOGGER.isLoggable(Level.FINE)) { 654 LOGGER.log(Level.FINE, this.toString()); 655 } 656 } 657 658 private HttpURLConnection createConnection() { 659 HttpURLConnection connection = null; 660 661 try { 662 if (this.api == null || this.api.getProxy() == null) { 663 connection = (HttpURLConnection) this.url.openConnection(); 664 } else { 665 connection = (HttpURLConnection) this.url.openConnection(this.api.getProxy()); 666 } 667 } catch (IOException e) { 668 throw new BoxAPIException("Couldn't connect to the Box API due to a network error.", e); 669 } 670 671 try { 672 connection.setRequestMethod(this.method); 673 } catch (ProtocolException e) { 674 throw new BoxAPIException("Couldn't connect to the Box API because the request's method was invalid.", e); 675 } 676 677 connection.setConnectTimeout(this.connectTimeout); 678 connection.setReadTimeout(this.readTimeout); 679 680 // Don't allow HttpURLConnection to automatically redirect because it messes up the connection pool. See the 681 // trySend(ProgressListener) method for how we handle redirects. 682 connection.setInstanceFollowRedirects(false); 683 684 for (RequestHeader header : this.headers) { 685 connection.addRequestProperty(header.getKey(), header.getValue()); 686 } 687 688 return connection; 689 } 690 691 void shouldAuthenticate(boolean shouldAuthenticate) { 692 this.shouldAuthenticate = shouldAuthenticate; 693 } 694 695 /** 696 * 697 * @param responseCode HTTP error code of the response 698 * @return true if the response is one that should be retried, otherwise false 699 */ 700 public static boolean isResponseRetryable(int responseCode) { 701 return (responseCode >= 500 || responseCode == 429); 702 } 703 private static boolean isResponseRedirect(int responseCode) { 704 return (responseCode == 301 || responseCode == 302); 705 } 706 707 /** 708 * Class for mapping a request header and value. 709 */ 710 public final class RequestHeader { 711 private final String key; 712 private final String value; 713 714 /** 715 * Construct a request header from header key and value. 716 * @param key header name 717 * @param value header value 718 */ 719 public RequestHeader(String key, String value) { 720 this.key = key; 721 this.value = value; 722 } 723 724 /** 725 * Get header key. 726 * @return http header name 727 */ 728 public String getKey() { 729 return this.key; 730 } 731 732 /** 733 * Get header value. 734 * @return http header value 735 */ 736 public String getValue() { 737 return this.value; 738 } 739 } 740}