sahaya / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

Binary body() content method ignores given contentType specification #167

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
The code below...

byte[] bytes = "<tag attr='value'>/".getBytes( "UTF-8" );
given().contentType("application/xml").body(bytes).when().post("http://localhost
:9999/test");

produces this HTTP request.  Note there is no Content-Type header even though 
it was specified.

POST /test HTTP/1.1
Accept: */*
Content-Length: 19
Host: localhost:9999
Connection: Keep-Alive
Accept-Encoding: gzip,deflate

<tag attr='value'>

What is the expected output? What do you see instead?
POST /test HTTP/1.1
Accept: */*
Content-Length: 19
Content-Type: application/xml
Host: localhost:9999
Connection: Keep-Alive
Accept-Encoding: gzip,deflate

<tag attr='value'>

What version of the product are you using? On what operating system?
Restlet: 1.6.1
MaxOS: 10.7.3

Please provide any additional information below.
The code below produces the expected HTTP request...

given().header(new 
Header("Content-Type","application/xml")).body(bytes).when().post("http://localh
ost:9999/test");

Note also that I basically need to do this because there isn't currently a way 
to specify a custom ObjectMapper but that is addressed in other existing 
issues. 

Original issue reported on code.google.com by kmin...@gmail.com on 23 Apr 2012 at 6:09

GoogleCodeExporter commented 9 years ago
Hi, 

This was indeed a quite serious bug! I've fixed it in trunk now and you can see 
if it works for you if you depend on 1.6.2-SNAPSHOT after having added the 
snapshot repo:

<repositories>
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots />
        </repository>
</repositories>

Also bare in mind that if you want to make sure that your request body is 
indeed going to use UTF-8 you need to supply the charset to the content-type 
header OR configure it as the default request content charset using the 
detailed configuration in REST Assured (search for it on the usage page).

Original comment by johan.ha...@gmail.com on 26 Apr 2012 at 7:54

GoogleCodeExporter commented 9 years ago
Hi,
Thank you very much for the quick turn around!  I've verified that 
1.6.2-SNAPSHOT does resolve the issue.  For future readers the charset point is 
an important one.  To that end, I've verified that this mechanism can be used 
to control that...  

given().contentType("text/plain; charset=UTF-8").body( "TEST".getBytes( "UTF-8" 
) ).when().post( "http://localhost:8888/test" );

This produces the expected HTTP request...

POST /test HTTP/1.1
Accept: */*
Content-Length: 4
Content-Type: text/plain; charset=UTF-8
Host: localhost:8888
Connection: Keep-Alive
Accept-Encoding: gzip,deflate

TEST

Original comment by kmin...@gmail.com on 26 Apr 2012 at 2:51