Curl support RFC
Johannes Pfau
spam at example.com
Mon Mar 14 08:40:10 PDT 2011
Jonas Drewsen wrote:
>> Do you plan to add some kind of support for header parsing? I think
>> something like what the .net webclient uses
>> ( http://msdn.microsoft.com/en-us/library/system.net.webclient(v=VS.100).aspx )
>> would be great. Especially the HeaderCollection supporting headers as
>> strings and as data types (for both parsing and formatting), but
>> without a class hierarchy for the headers, using templates instead.
>
>It would be nice to be able to get/set headers by string and enums
>(http://msdn.microsoft.com/en-us/library/system.net.httprequestheader.aspx).
>But I cannot see that .net is using datatypes or templates for it.
>Could you give me a pointer please?
>
You're right I didn't look close enough at the .net documentation. I
thought HttpRequestHeader is a class. What I meant for D was something
like this:
struct ETagHeader
{
//Data members
bool Weak = false;
string Value;
//All header structs provide these
static string Key = "ETag";
static ETagHeader parse(string value)
{
//parser logic here
}
void format(T writer)
if (isOutputRange!(T, string))
{
if(etag.Weak)
writer.put("W/");
assert(etag.Value != "");
writer.put(quote(etag.Value));
}
}
Then we can offer methods like these:
setHeader(T)(T header)
if(isHeader(T))
{
headers[T.Key] = formatHeader(header);
}
T getHeader(T type)()
if(isHeader(T))
{
if(!T.Key in headers)
throw Exception();
return T.parse(headers[T.key]);
}
So user code wouldn't have to deal with header parsing / formatting:
auto etag = client.getHeader!ETagHeader();
assert(etag.Weak);
>> I've written D parsers/formatters for almost all headers in
>> rfc2616 (1 or 2 might be missing) and for a few additional commonly
>> used headers (Content-Disposition, cookie headers). The parsers are
>> written with ragel and are to be used with curl (continuations must
>> be removed and the parsers always take 1 line of input, just as you
>> get it from curl). Right now only the client side is implemented (no
>> parsers for headers which can only be sent from client-->server ).
>> However, I need to add some more documentation to the parsers, need
>> to do some refactoring and I've got absolutely no time for that in
>> the next 2 weeks ('abitur' final exams). But if you could wait 2
>> weeks or if you wanted to do the refactoring yourself, I would be
>> happy to contribute that code.
>
>That sounds very interesting. I would very much like to see the code
>and see if fits in.
Ok, here it is, but it seriously needs to be refactored and documented:
https://gist.github.com/869324
--
Johannes Pfau
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110314/322da2ac/attachment.pgp>
More information about the Digitalmars-d
mailing list