Skip to content

Producing incorrect Location header #1327

Description

@mkarg

According to HTTP RFC an endpoint shall return the location of the created resource.

Looking at the following code, a reader would expect to get Location: http://host/foo/<id> from the POST method...

@POST @Path("foo")
public Response foo() {
    return Response.created(URI.create("id")).build();
}

...so a generic client can simply GET the received URL (which is the idea of the location header):

@GET @Path("foo/{id}")
public String foo(String id) {
    return "Content of " + id;
}

Unfortunately, what the POST actually produces according to our Javadocs (and according a quick test using Jersey) is: http://host/<id>. Apparently, this URI is wrong and is not GETable (it leads to 404).

I would say, we did a design mistake in our recent specifications and JavaDocs: The base uri never contains @Path. For backwards compatibility we cannot fix this. But to make things work correctly, we could add additional methods which work as intuitively expected. For example, we could say that besides the base uri there also is a "full base uri", which is the base uri plus the resource class's and resource method's @Path. So in the end, it could be as simple as: return Response.created("{id}").build(id) (as the new methode created() prefixes the path found in @Path).

WDYT?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions