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

Can't execute DELETE without body. #745

Closed
pepyakin opened this Issue Apr 21, 2014 · 7 comments

Comments

4 participants
@pepyakin

pepyakin commented Apr 21, 2014

I'm trying to create Request just as:

Request.Builder builder = new Request.Builder().url("URL");
builder.method("DELETE", null);

(because there are no .delete() method)

When I'm trying to execute such request it crashes, with error message:
java.lang.IllegalStateException: Cannot stream a request body without chunked encoding or a known content length!

As I get it, it happens because DELETE can "has request body" (hasRequestBody returns true for DELETE) and when we are trying to create request body it blows up, because neither contentLength info provided nor Transfer-Encoding is set to chunked because no body provided.

So, there is workaround: just add Content-Length: 0 header.

Looks like it is somekind related to #605.

@swankjesse swankjesse added the bug label Apr 21, 2014

@swankjesse swankjesse added this to the 2.0 milestone Apr 21, 2014

@swankjesse

This comment has been minimized.

Show comment
Hide comment
@swankjesse

swankjesse Apr 21, 2014

Member

Yup. DELETE is a mess because the spec doesn't say whether a body is required or not. Will fix.

Member

swankjesse commented Apr 21, 2014

Yup. DELETE is a mess because the spec doesn't say whether a body is required or not. Will fix.

@swankjesse

This comment has been minimized.

Show comment
Hide comment
@swankjesse

swankjesse Apr 23, 2014

Member

Does this work?

  Request.Body.create(MediaType.parse("text/plain"), "");

Or does the inclusion of an unwanted content-type harm things?

Member

swankjesse commented Apr 23, 2014

Does this work?

  Request.Body.create(MediaType.parse("text/plain"), "");

Or does the inclusion of an unwanted content-type harm things?

@pepyakin

This comment has been minimized.

Show comment
Hide comment
@pepyakin

pepyakin Apr 23, 2014

I will try it and write back.

But if you will ask, what I like more: Content-Length: 0 or Content-Type: text/plain (Also, It seems to me that adding empty body implicitly adds Content-Length: 0), of course I choose first option.

pepyakin commented Apr 23, 2014

I will try it and write back.

But if you will ask, what I like more: Content-Length: 0 or Content-Type: text/plain (Also, It seems to me that adding empty body implicitly adds Content-Length: 0), of course I choose first option.

@cowtowncoder

This comment has been minimized.

Show comment
Hide comment
@cowtowncoder

cowtowncoder Apr 26, 2014

I am pretty sure DELETE typically does not take a body, although one could send it. At least I have never sent anything in body with other client libs.

cowtowncoder commented Apr 26, 2014

I am pretty sure DELETE typically does not take a body, although one could send it. At least I have never sent anything in body with other client libs.

@adriancole

This comment has been minimized.

Show comment
Hide comment
@adriancole

adriancole Apr 26, 2014

Collaborator

I can recall a few times where a foresaken api required delete with body
and made it impossible to use urlconnection. I agree delete with body is
misguided, but I also think users shouldn't have to do terrible reflective
hacks if they are put in such a spot.

2p

Collaborator

adriancole commented Apr 26, 2014

I can recall a few times where a foresaken api required delete with body
and made it impossible to use urlconnection. I agree delete with body is
misguided, but I also think users shouldn't have to do terrible reflective
hacks if they are put in such a spot.

2p

@cowtowncoder

This comment has been minimized.

Show comment
Hide comment
@cowtowncoder

cowtowncoder Apr 26, 2014

@adriancole I absolutely agree and did not mean to say it should be hard to add a body. I meant the that it should also be easy to leave out body; and have .delete() method for constructing "typical" DELETE requests. Ant then adding body is easy via existing methods.

cowtowncoder commented Apr 26, 2014

@adriancole I absolutely agree and did not mean to say it should be hard to add a body. I meant the that it should also be easy to leave out body; and have .delete() method for constructing "typical" DELETE requests. Ant then adding body is easy via existing methods.

@adriancole

This comment has been minimized.

Show comment
Hide comment
@adriancole

adriancole Apr 26, 2014

Collaborator

+1

Collaborator

adriancole commented Apr 26, 2014

+1

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