Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty string cannot be passed in HttpTrigger query string #683

Open
lucyzhang929 opened this issue Nov 28, 2022 · 0 comments · May be fixed by #694
Open

Empty string cannot be passed in HttpTrigger query string #683

lucyzhang929 opened this issue Nov 28, 2022 · 0 comments · May be fixed by #694

Comments

@lucyzhang929
Copy link
Contributor

Repro steps

  1. Run the following function from templates:
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<Optional<String>> 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();
        }
    }
}
  1. Send the following request: 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: Azure/azure-functions-powershell-worker#895

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants