Files
gerrit/gerrit-gwtui/src/main/java/com/google/gerrit/client/rpc/HttpResponse.java
Shawn Pearce 38df42f051 Inline Edit: Acquire content and type in one request
BinaryResult can return X-FYI-Content-Type header with the
real content type. Use this inside of FileContentUtil to
send back the actual type in one request.

By using a single request the server only needs to load
object data into memory once, to determine type and to
stream the content to the client.

Move base64 decoding into RestApi. The format is very
predictable from the server and can be applied to any
REST API call made from the browser.

Change-Id: I3b6c83efd0eb76148a3ac3e50cd2e3e4c37f08c5
2015-01-06 11:33:46 -08:00

57 lines
1.6 KiB
Java

// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.client.rpc;
import com.google.gwt.http.client.Response;
/** Wraps decoded server reply with HTTP headers. */
public class HttpResponse<T> {
private final Response httpResponse;
private final String contentType;
private final T result;
HttpResponse(Response httpResponse, String contentType, T result) {
this.httpResponse = httpResponse;
this.contentType = contentType;
this.result = result;
}
/** HTTP status code, always in the 2xx family. */
public int getStatusCode() {
return httpResponse.getStatusCode();
}
/**
* Content type supplied by the server.
*
* This helper simplifies the common {@code getHeader("Content-Type")} case.
*/
public String getContentType() {
return contentType;
}
/** Lookup an arbitrary reply header. */
public String getHeader(String header) {
if ("Content-Type".equals(header)) {
return contentType;
}
return httpResponse.getHeader(header);
}
public T getResult() {
return result;
}
}