Azure / Azure/azure-functions-java-worker

Empty string cannot be passed in HttpTrigger query string

Đang mở
#683 0 bình luận 0 reaction 1 người được giao Được @kamperiadis nhận Xem trên GitHub
area:java-functions Break Change Enhancement needs-discussion New Feature reviewed
Ngôn ngữ chính
Java
Star
103
Fork
74
Merge trung bình
4 ngày 8 giờ
Pull request đã merge (30 ngày)
2

Mô tả

#### Repro steps

1. Run the following function from templates:
```java
package com.function;

import java.util.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;

/**
* Azure Functions with HTTP Trigger.
*/
public class HttpTriggerJava1 {
/**
* This function listens at endpoint "/api/HttpTriggerJava1". Two ways to invoke it using "curl" command in bash:
* 1. curl -d "HTTP Body" {your host}/api/HttpTriggerJava1
* 2. curl {your host}/api/HttpTriggerJava1?name=HTTP%20Query
*/
@FunctionName("HttpTriggerJava1")
public HttpResponseMessage run(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage> request,
final ExecutionContext context) {
context.getLogger().info("Java HTTP trigger processed a request.");

// Parse query parameter
String query = request.getQueryParameters().get("name");
String name = request.getBody().orElse(query);

if (name == null) {
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
} else {
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
}
}
}
```
2. Send the following request: [http://localhost:7071/api/HttpTriggerJava1?name=](http://localhost:7071/api/HttpTriggerJava1?name=)

#### Expected behavior
`name` should be set to an empty string and the function should return "Hello, "

#### Actual behavior
`name` is set to null and the function returns "Please pass a name on the query string or in the request body"

#### Known workarounds
None

#### Related information
Similar issue in PowerShell worker: https://github.com/Azure/azure-functions-powershell-worker/issues/895

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.