File file = new File(filename);
log.info("Now sending PUT with File in the body");
given().body(file).when().log().all().put(url).then().log().all();
log.info("Now sending PUT with ASCII characters in the body");
given().body("12345").when().log().all().put(url).then().log().all();
Thanks,
Todd.
--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Now back to your specific example RA chose text/plain because you're sending text (I assume?) using PUT. If you where to send the file as multipart data instead it would not use text/plain (but rather multipart/form-data with application/octet-stream as the "part" content-type unless specified explicitly).
The gist of the matter is that if you want to control it you should explicitly specify a content-type other Rest Assured (et al) will try to "guess".You can specify a default content-type for all requests by using a RequestSpecification and define the content-type there. Then you can either supply this spec to the DSL (given().spec(mySpec). ..) or attach it statically (RestAssured.requestSpecification = mySpec).
On Wed, Jan 4, 2017 at 11:50 PM, Johan Haleby <johan....@gmail.com> wrote:[...]Now back to your specific example RA chose text/plain because you're sending text (I assume?) using PUT. If you where to send the file as multipart data instead it would not use text/plain (but rather multipart/form-data with application/octet-stream as the "part" content-type unless specified explicitly).Nope. It seems that RA chooses text/plain regardless of what I'm sending. I didn't show it in the example, but the file is a JPG. I also tried it with a PDF, a PNG, and a couple other files. In all cases, the HTTP request gets sent out with a content type of text/plain.
The gist of the matter is that if you want to control it you should explicitly specify a content-type other Rest Assured (et al) will try to "guess".You can specify a default content-type for all requests by using a RequestSpecification and define the content-type there. Then you can either supply this spec to the DSL (given().spec(mySpec). ..) or attach it statically (RestAssured.requestSpecification = mySpec).OK, it sounds like that's the best approach. I was hoping there was something that would let me tell RA, "If I haven't explicitly told you a Content-Type to use, please use this one." In the same way you can tell EncoderConfig, "If I haven't explicitly told you an encoding to use, please use this one."
Thanks for the help,Todd.
On Thu, Jan 5, 2017 at 3:31 PM, Todd Bradley <to...@toddbradley.com> wrote:Nope. It seems that RA chooses text/plain regardless of what I'm sending. I didn't show it in the example, but the file is a JPG. I also tried it with a PDF, a PNG, and a couple other files. In all cases, the HTTP request gets sent out with a content type of text/plain.Interesting, I didn't know this. Would it make sense to try to recognize the file extension and determine try to determine the content-type based on it? For example if you supply a file that points to "/tmp/pic.jpg" the content-type would resolve to "image/jpeg"? This could be made configurable in the EncoderConfig (1), something like encoderConfig.contentTypeForFileExtension("jpg", "application/octet-stream"). If so would you mind creating an issue for it?
OK, it sounds like that's the best approach. I was hoping there was something that would let me tell RA, "If I haven't explicitly told you a Content-Type to use, please use this one." In the same way you can tell EncoderConfig, "If I haven't explicitly told you an encoding to use, please use this one."Yeah this would be useful. But let's say that we implement (1) as well then I suppose that (1) should have priority over this configuration?!
On Thu, Jan 5, 2017 at 8:01 AM, Johan Haleby <johan....@gmail.com> wrote:On Thu, Jan 5, 2017 at 3:31 PM, Todd Bradley <to...@toddbradley.com> wrote:Nope. It seems that RA chooses text/plain regardless of what I'm sending. I didn't show it in the example, but the file is a JPG. I also tried it with a PDF, a PNG, and a couple other files. In all cases, the HTTP request gets sent out with a content type of text/plain.Interesting, I didn't know this. Would it make sense to try to recognize the file extension and determine try to determine the content-type based on it? For example if you supply a file that points to "/tmp/pic.jpg" the content-type would resolve to "image/jpeg"? This could be made configurable in the EncoderConfig (1), something like encoderConfig.contentTypeForFileExtension("jpg", "application/octet-stream"). If so would you mind creating an issue for it?I've given this topic a lot of thought over the past couple weeks, because I've been testing an object storage system that can guess a Content-Type based on the contents of the object.I actually think that REST-assured shouldn't ever guess a Content-Type for the body of a PUT request, either by filename or content. I think that if the user doesn't specify one, RA should send out some default. But the default should always be the same, and ideally configurable.
OK, it sounds like that's the best approach. I was hoping there was something that would let me tell RA, "If I haven't explicitly told you a Content-Type to use, please use this one." In the same way you can tell EncoderConfig, "If I haven't explicitly told you an encoding to use, please use this one."Yeah this would be useful. But let's say that we implement (1) as well then I suppose that (1) should have priority over this configuration?!Well, I don't think that (1) is a great idea. If a tester wants his tests to work that way, changing Content-Type based on the filename, then he should build that into his own tests. That's my opinion, anyhow.
Cheers,Todd.
Well, I don't think that (1) is a great idea. If a tester wants his tests to work that way, changing Content-Type based on the filename, then he should build that into his own tests. That's my opinion, anyhow.Not implementing (1) would make it easier to understand and reason about as well which is nice.