Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: address PR comments
  • Loading branch information
chingor13 committed Aug 28, 2019
commit b06a0db92de0d732c6e9bed574eea435e869a719
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,8 @@ public HttpResponse execute() throws IOException {
if (!retryOnExecuteIOException
&& (ioExceptionHandler == null
|| !ioExceptionHandler.handleIOException(this, retryRequest))) {
span.end(OpenCensusUtils.getEndSpanOptions(response == null ? null : response.getStatusCode()));
// static analysis shows response is always null here
span.end(OpenCensusUtils.getEndSpanOptions(null));
throw e;
}
// Save the exception in case the retries do not work and we need to re-throw it later.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ public static EndSpanOptions getEndSpanOptions(@Nullable Integer statusCode) {
return builder.build();
}

static EndSpanOptions getEndSpanOptionsForResponse(@Nullable HttpResponse response) {
if (response != null) {
return getEndSpanOptions(response.getStatusCode());
}
return getEndSpanOptions(null);
}

/**
* Records a new message event which contains the size of the request content. Note that the size
* represents the message size in application layer, i.e., content-length.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1222,9 +1222,9 @@ public void testExecute_curlLogger() throws Exception {
for (String message : recorder.messages()) {
if (message.startsWith("curl")) {
found = true;
assert(message.contains("curl -v --compressed -H 'Accept-Encoding: gzip'"));
assert(message.contains("-H 'User-Agent: Google-HTTP-Java-Client/" + HttpRequest.VERSION + " (gzip)'"));
assert(message.contains("' -- 'http://google.com/#q=a'\"'\"'b'\"'\"'c'"));
assertTrue(message.contains("curl -v --compressed -H 'Accept-Encoding: gzip'"));
assertTrue(message.contains("-H 'User-Agent: Google-HTTP-Java-Client/" + HttpRequest.VERSION + " (gzip)'"));
assertTrue(message.contains("' -- 'http://google.com/#q=a'\"'\"'b'\"'\"'c'"));
}
}
assertTrue(found);
Expand Down Expand Up @@ -1252,10 +1252,10 @@ public void testExecute_curlLoggerWithContentEncoding() throws Exception {
for (String message : recorder.messages()) {
if (message.startsWith("curl")) {
found = true;
assert(message.contains("curl -v --compressed -X POST -H 'Accept-Encoding: gzip'"));
assert(message.contains("-H 'User-Agent: " + HttpRequest.USER_AGENT_SUFFIX + "'"));
assert(message.contains("-H 'Content-Type: text/plain; charset=UTF-8' -H 'Content-Encoding: gzip'"));
assert(message.contains("-d '@-' -- 'http://google.com/#q=a'\"'\"'b'\"'\"'c' << $$$"));
assertTrue(message.contains("curl -v --compressed -X POST -H 'Accept-Encoding: gzip'"));
assertTrue(message.contains("-H 'User-Agent: " + HttpRequest.USER_AGENT_SUFFIX + "'"));
assertTrue(message.contains("-H 'Content-Type: text/plain; charset=UTF-8' -H 'Content-Encoding: gzip'"));
assertTrue(message.contains("-d '@-' -- 'http://google.com/#q=a'\"'\"'b'\"'\"'c' << $$$"));
}
}
assertTrue(found);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright 2019 Google LLC
*
* 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.api.client.http;

import com.google.api.client.testing.http.MockHttpTransport;
Expand Down