swangkkb / rest-assured

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

Content-Type seems to work in console out, but it's not really working #362

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Global Params are:

RestAssured.defaultParser = Parser.XML;
RestAssured.urlEncodingEnabled = true;

Run a test like this one:

given().log().all().
    param("foo", "bar").
    contentType(ContentType.XML.withCharset("utf-8")).
when().
    get("/service");

OR:

given().log().all().
    param("foo", "bar").
    header("Content-Type", "text/xml; charset=utf-8").
when().
    get("/service");

What is the expected output? What do you see instead?

With .log().all() I see an output I expect, but it's not really there,
with sniffing on the original request (e.g WireShark) I see that there is no 
Content-Type...

What version of the product are you using? On what operating system?

rest-assured-2.3.4

Please provide any additional information below.

Other Headers are working.

Original issue reported on code.google.com by zingl.ma...@gmail.com on 15 Oct 2014 at 1:13

GoogleCodeExporter commented 9 years ago
This seems really bad.. Need to investigate it. Thanks for reporting.

Original comment by johan.ha...@gmail.com on 16 Oct 2014 at 1:14

GoogleCodeExporter commented 9 years ago
This only seem to happen on GET requests since they shouldn't have content. Why 
do you need a content-type for a GET request? Are you sure you're not mistaken 
it for a accept header? 
(http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1)

Original comment by johan.ha...@gmail.com on 16 Oct 2014 at 1:19

GoogleCodeExporter commented 9 years ago
You're right. I do a request to a Tomcat Servlet. And the Tomcat config has the 
flag useBodyEncodingForURI="true". So it works for requests from other tools if 
i set right encoding through headers.

I try to fix my problem with another flag: URIEncoding="UTF-8"
But I'm not sure if I'll get other problems, if legacy requests do GET requests 
with setting encoding through header other than UTF-8.

Thanks.

Original comment by zingl.ma...@gmail.com on 16 Oct 2014 at 3:23

GoogleCodeExporter commented 9 years ago
I've actually fixed it in master. I'll push a new snapshot soon.

Original comment by johan.ha...@gmail.com on 16 Oct 2014 at 4:42

GoogleCodeExporter commented 9 years ago
I've published a new snapshot now. Please try it out by depending on version 
2.3.5-SNAPSHOT after having added the following maven repository:

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

Original comment by johan.ha...@gmail.com on 16 Oct 2014 at 5:10

GoogleCodeExporter commented 9 years ago
Working. Perfect.

Thank you.

Original comment by zingl.ma...@gmail.com on 17 Oct 2014 at 9:56

GoogleCodeExporter commented 9 years ago
Great, thanks for reporting and for testing it.

Original comment by johan.ha...@gmail.com on 17 Oct 2014 at 10:03

GoogleCodeExporter commented 9 years ago
Issue 365 has been merged into this issue.

Original comment by johan.ha...@gmail.com on 24 Oct 2014 at 5:15

GoogleCodeExporter commented 9 years ago
I am facing same issue with version 2.4.0. Mine is not the maven project, so do 
i need to change to 2.3.5-SNAPSHOT version? If yes where can I download?

Thanks.

Original comment by jimipar...@gmail.com on 18 Nov 2014 at 4:26

GoogleCodeExporter commented 9 years ago
Could you give me an example of when it's not working? What's your code?

Original comment by johan.ha...@gmail.com on 18 Nov 2014 at 4:35

GoogleCodeExporter commented 9 years ago
My application sends response based on the request content type.
I am explicitly setting content typs as "application/json" in "get" request. In 
request log also i see its setting it, but its not passing any content type to 
server. So my application by default assume its as xml and sends back xml 
response, but i expect json response.

Below is my request.

String response =
            given().
                contentType("application/json").
                header("Content-Type", "application/json").
                log().all().
            expect().
                statusCode(200).
                log().all().
            when().
                get(url).body().asString();

Original comment by jimipar...@gmail.com on 18 Nov 2014 at 4:48

GoogleCodeExporter commented 9 years ago
Got it....

Its my mistake, I have version 2.3.4 not 2.4.0. I will try with 2.4.0 now.

Thanks.

Original comment by jimipar...@gmail.com on 18 Nov 2014 at 5:00

GoogleCodeExporter commented 9 years ago
Please tell us the result

Original comment by johan.ha...@gmail.com on 18 Nov 2014 at 5:16

GoogleCodeExporter commented 9 years ago
It worked with 2.4.0.

Thanks.

Original comment by jimipar...@gmail.com on 18 Nov 2014 at 6:07

GoogleCodeExporter commented 9 years ago
Good, thanks for sharing

Original comment by johan.ha...@gmail.com on 18 Nov 2014 at 6:15