digitalmars.D.learn - std.net.curl - how to set custom Content-Type?
- Dmitry Olshansky (14/14) Sep 17 2012 Recently was playing around with std.net.curl high-level API.
- Johannes Pfau (6/25) Sep 17 2012 addRequestHeader is quite dumb. It simply appends the header to a list.
- Jonathan M Davis (6/9) Sep 17 2012 So, you're suggesting to send 2 content headers? That can't be good. It ...
- Johannes Pfau (6/18) Sep 18 2012 No I'm not suggesting it, but that is what's being done if you call
- Dmitry Olshansky (6/24) Sep 18 2012 Yeah, that's the case. Thanks Johannes, I'll use your workaround for now...
Recently was playing around with std.net.curl high-level API. One thing that is a blocker for me is (quoting the docs): property void postData(const(char)[] data); Specifying data to post when not using the onSend callback. ... Content-Type will default to text/plain. Data is not converted or encoded by this method. Yeah, there are only 2 occurrences of Content-Type throughout the docs the second "defaults" to Content-Type application/octet-stream. Say I want to send text/xml. Adding Content-Type as header via addRequestHeader doesn't seem to change a thing (probably because it already has the default one). -- Dmitry Olshansky
Sep 17 2012
Am Mon, 17 Sep 2012 22:33:28 +0400 schrieb Dmitry Olshansky <dmitry.olsh gmail.com>:Recently was playing around with std.net.curl high-level API. One thing that is a blocker for me is (quoting the docs): property void postData(const(char)[] data); Specifying data to post when not using the onSend callback. ... Content-Type will default to text/plain. Data is not converted or encoded by this method. Yeah, there are only 2 occurrences of Content-Type throughout the docs the second "defaults" to Content-Type application/octet-stream. Say I want to send text/xml. Adding Content-Type as header via addRequestHeader doesn't seem to change a thing (probably because it already has the default one).addRequestHeader is quite dumb. It simply appends the header to a list. So by just calling it again you would actually send 2 Content-Type headers. Here's a short workaround: http://dpaste.dzfl.pl/4704965b
Sep 17 2012
On Monday, September 17, 2012 20:59:05 Johannes Pfau wrote:addRequestHeader is quite dumb. It simply appends the header to a list. So by just calling it again you would actually send 2 Content-Type headers.So, you're suggesting to send 2 content headers? That can't be good. It might work, but I'm pretty darn sure that it's against the HTTP spec to do so. You're only supposed to have duplicate headers when they're values are a list, and they can be concatenated into a single header. - Jonathan M Davis
Sep 17 2012
Am Mon, 17 Sep 2012 22:35:39 +0200 schrieb "Jonathan M Davis" <jmdavisProg gmx.com>:On Monday, September 17, 2012 20:59:05 Johannes Pfau wrote:No I'm not suggesting it, but that is what's being done if you call addRequestHeader twice. Dmitry said addRequestHeader didn't work for him and I wanted to explain that calling addRequestHeader again does not overwrite the first value.addRequestHeader is quite dumb. It simply appends the header to a list. So by just calling it again you would actually send 2 Content-Type headers.So, you're suggesting to send 2 content headers? That can't be good. It might work, but I'm pretty darn sure that it's against the HTTP spec to do so. You're only supposed to have duplicate headers when they're values are a list, and they can be concatenated into a single header. - Jonathan M Davis
Sep 18 2012
On 18-Sep-12 11:41, Johannes Pfau wrote:Am Mon, 17 Sep 2012 22:35:39 +0200 schrieb "Jonathan M Davis" <jmdavisProg gmx.com>:Yeah, that's the case. Thanks Johannes, I'll use your workaround for now. Still I believe it worths an enhancement request. Setting content type is a basic task. -- Dmitry OlshanskyOn Monday, September 17, 2012 20:59:05 Johannes Pfau wrote:No I'm not suggesting it, but that is what's being done if you call addRequestHeader twice. Dmitry said addRequestHeader didn't work for him and I wanted to explain that calling addRequestHeader again does not overwrite the first value.addRequestHeader is quite dumb. It simply appends the header to a list. So by just calling it again you would actually send 2 Content-Type headers.So, you're suggesting to send 2 content headers? That can't be good. It might work, but I'm pretty darn sure that it's against the HTTP spec to do so. You're only supposed to have duplicate headers when they're values are a list, and they can be concatenated into a single header. - Jonathan M Davis
Sep 18 2012