mirror of
https://github.com/google/nomulus.git
synced 2025-08-01 15:34:48 +02:00
Add support for empty or null params for createTask() (#1448)
* Add support for null or empty params * Add Null or empty check in CollectionUtils * Remove content type header for empty params in POST request
This commit is contained in:
parent
a569fc586e
commit
5b11ef63e3
6 changed files with 89 additions and 35 deletions
|
@ -98,11 +98,7 @@ class TldFanoutActionTest {
|
|||
}
|
||||
|
||||
private void assertTaskWithoutTld() {
|
||||
cloudTasksHelper.assertTasksEnqueued(
|
||||
QUEUE,
|
||||
new TaskMatcher()
|
||||
.url(ENDPOINT)
|
||||
.header("content-type", "application/x-www-form-urlencoded"));
|
||||
cloudTasksHelper.assertTasksEnqueued(QUEUE, new TaskMatcher().url(ENDPOINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -227,22 +227,20 @@ public class CloudTasksHelper implements Serializable {
|
|||
});
|
||||
headers = headerBuilder.build();
|
||||
ImmutableMultimap.Builder<String, String> paramBuilder = new ImmutableMultimap.Builder<>();
|
||||
String query = null;
|
||||
// Note that UriParameters.parse() does not throw an IAE on a bad query string (e.g. one
|
||||
// where parameters are not properly URL-encoded); it always does a best-effort parse.
|
||||
if (method == HttpMethod.GET) {
|
||||
query = uri.getQuery();
|
||||
} else if (method == HttpMethod.POST) {
|
||||
paramBuilder.putAll(UriParameters.parse(uri.getQuery()));
|
||||
} else if (method == HttpMethod.POST && !task.getAppEngineHttpRequest().getBody().isEmpty()) {
|
||||
assertThat(
|
||||
headers.containsEntry(
|
||||
Ascii.toLowerCase(HttpHeaders.CONTENT_TYPE), MediaType.FORM_DATA.toString()))
|
||||
.isTrue();
|
||||
query = task.getAppEngineHttpRequest().getBody().toString(StandardCharsets.UTF_8);
|
||||
}
|
||||
if (query != null) {
|
||||
// Note that UriParameters.parse() does not throw an IAE on a bad query string (e.g. one
|
||||
// where parameters are not properly URL-encoded); it always does a best-effort parse.
|
||||
paramBuilder.putAll(UriParameters.parse(query));
|
||||
params = paramBuilder.build();
|
||||
paramBuilder.putAll(
|
||||
UriParameters.parse(
|
||||
task.getAppEngineHttpRequest().getBody().toString(StandardCharsets.UTF_8)));
|
||||
}
|
||||
params = paramBuilder.build();
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue