Java Code Examples for com.google.api.client.http.HttpContent#getLength()
The following examples show how to use
com.google.api.client.http.HttpContent#getLength() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GoogleApiClientSigner.java From oauth1-signer-java with MIT License | 5 votes |
public void sign(HttpRequest request) throws IOException { URI uri = request.getUrl().toURI(); String method = request.getRequestMethod(); String payload = null; HttpContent content = request.getContent(); if (null != content && content.getLength() > 0) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); content.writeTo(outputStream); payload = outputStream.toString(charset.name()); } String authorizationHeader = OAuth.getAuthorizationHeader(uri, method, payload, charset, consumerKey, signingKey); request.getHeaders().setAuthorization(authorizationHeader); }
Example 2
Source File: HttpRequestContent.java From google-api-java-client with Apache License 2.0 | 5 votes |
@Override public void writeTo(OutputStream out) throws IOException { Writer writer = new OutputStreamWriter(out, getCharset()); // write method and URL writer.write(request.getRequestMethod()); writer.write(" "); writer.write(request.getUrl().build()); writer.write(" "); writer.write(HTTP_VERSION); writer.write(NEWLINE); // write headers HttpHeaders headers = new HttpHeaders(); headers.fromHttpHeaders(request.getHeaders()); headers.setAcceptEncoding(null).setUserAgent(null) .setContentEncoding(null).setContentType(null).setContentLength(null); // analyze the content HttpContent content = request.getContent(); if (content != null) { headers.setContentType(content.getType()); // NOTE: batch does not support gzip encoding long contentLength = content.getLength(); if (contentLength != -1) { headers.setContentLength(contentLength); } } HttpHeaders.serializeHeadersForMultipartRequests(headers, null, null, writer); // HTTP headers are always terminated with an empty line; RFC 7230 ยง3 writer.write(NEWLINE); writer.flush(); // write content if (content != null) { content.writeTo(out); } }
Example 3
Source File: URLFetchUtils.java From appengine-gcs-client with Apache License 2.0 | 5 votes |
HTTPRequestInfo(HttpRequest req) { method = req.getRequestMethod(); url = req.getUrl().toURL(); long myLength; HttpContent content = req.getContent(); try { myLength = content == null ? -1 : content.getLength(); } catch (IOException e) { myLength = -1; } length = myLength; h1 = req.getHeaders(); h2 = null; }