Return response headers

Report a typo

Complete the code to return the response headers.

public Headers handleGetRequest(HttpExchange exchange) throws IOException {
    String response = "Hello, " +  exchange.getRequestURI().toString().split("=")[1];

    exchange.sendResponseHeaders(200, response.getBytes().length);
    exchange.getResponseHeaders().set("Access-Control-Allow-Origin", "*");

    try (OutputStream stream = exchange.getResponseBody()) {
        stream.write(response.getBytes());
    }

    return _____________;
}
Enter a short text
___

Create a free account to access the full topic