View previous topic :: View next topic |
Author |
Message |
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Tue May 17, 2005 10:50 am Post subject: HttpHeaders? |
|
|
I'm trying this:
Code: |
Buffer buf = new Buffer( cast(void[]) response.data );
HttpHeaders headers = new HttpHeaders;
headers.parse(buf);
foreach (HeaderElement elm; headers)
writefln("?s: ?s", elm.name.value, elm.value);
|
response is a std.stream.MemoryStream and has this:
Code: |
HTTP/1.0 200 OK
Date: Tue, 17 May 2005 16:42:30 GMT
Server: worklist
Content-type: text/xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<bye />
|
But nothing is being printed. Why? |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Tue May 17, 2005 11:39 am Post subject: |
|
|
Take another look at these two Buffer ctors:
Code: | /***********************************************************************
Prime buffer with an application-supplied array. There is
no readable data present, and writing begins at position 0.
***********************************************************************/
this (void[] data)
{
this (data, 0);
}
/***********************************************************************
Prime buffer with an application-supplied array, and
indicate how much readable data is already there. A
write operation will begin writing immediately after
the existing content.
***********************************************************************/
this (void[] data, uint readable)
{
setContent (data, readable);
}
|
I imagine you want to use the second variation
[p.s. your cast(void[]) should be implied by the compiler] |
|
Back to top |
|
|
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Tue May 17, 2005 12:16 pm Post subject: |
|
|
Thank you! I hadn't seen that ctor.
Now, two questions: a) per design, the colon is included as part of the header name (ie, "Date:"). Why is that? b) HttpHeaders doesn't let me get the response (ie, "HTTP/1.0 200 OK"). One of the reasons I'm using Mango is to have that parsed. I'm creating a new ResponseLine for that, but I'd like to know if it's going to be possible in a future release of Mango. |
|
Back to top |
|
|
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Tue May 17, 2005 12:26 pm Post subject: |
|
|
Carlos wrote: | I'm creating a new ResponseLine |
I wanted to create a new ResponseLine, should I say. When I do "new ResponseLine()", the linker complains later:
Code: | d:\carlos\dev\dm\bin\..\..\dmd\lib\phobos.lib(winsock) Offset 087B7H Record Type 0091
Error 1: Previous Definition Different : _WSADESCRIPTION_LEN
d:\carlos\dev\dm\bin\..\..\dmd\lib\phobos.lib(winsock) Offset 087CFH Record Type 0091
Error 1: Previous Definition Different : _WSASYS_STATUS_LEN
d:\carlos\dev\dm\bin\..\..\dmd\lib\phobos.lib(winsock) Offset 08813H Record Type 0091
Error 1: Previous Definition Different : _IOCPARM_MASK
d:\carlos\dev\dm\bin\..\..\dmd\lib\phobos.lib(winsock) Offset 08820H Record Type 0091
Error 1: Previous Definition Different : _IOC_IN
d:\carlos\dev\dm\bin\..\..\dmd\lib\phobos.lib(winsock) Offset 0882EH Record Type 0091
Error 1: Previous Definition Different : _FIONBIO |
(DMD 0.123) |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Tue May 17, 2005 12:59 pm Post subject: |
|
|
Carlos wrote: | Thank you! I hadn't seen that ctor.
Now, two questions: a) per design, the colon is included as part of the header name (ie, "Date:"). Why is that? b) HttpHeaders doesn't let me get the response (ie, "HTTP/1.0 200 OK"). One of the reasons I'm using Mango is to have that parsed. I'm creating a new ResponseLine for that, but I'd like to know if it's going to be possible in a future release of Mango. |
a) optimization; plus it nicely distinguishes between "Accept:" and "Accept-Charset:" etc
b) "HTTP/1.0 200 OK" is not a header, so it's not likely to be made available as one in the future. I could certainly make ResponseLine public, if that were to be useful.
The Linker error is bizarre. I wonder if it's because ResponseLine is declared private, and therefore you shouldn't be able to access it in the first place? Did DMD recently break the 'private' attribute? |
|
Back to top |
|
|
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Tue May 17, 2005 1:20 pm Post subject: |
|
|
I hadn't even noticed ResponseLine was private. Maybe it is causing the problem. I don't know. |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Tue May 17, 2005 1:53 pm Post subject: |
|
|
Carlos wrote: | I hadn't even noticed ResponseLine was private. Maybe it is causing the problem. I don't know. |
In the meantime you might try something like this:
Code: | import mango.utils.Text;
import mango.format.Int;
int index = Text.indexOf (response, ' ');
char[] protocol = response[0..index];
int status = Int.parse (response[index..length]);
index = Text.indexOf (response, ' ', index+1);
int eol = Text.indexOf (response, '\n', index);
char[] reason = response[index..eol];
|
|
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Tue May 17, 2005 2:38 pm Post subject: |
|
|
Carlos wrote: | Carlos wrote: | I'm creating a new ResponseLine |
I wanted to create a new ResponseLine, should I say. When I do "new ResponseLine()", the linker complains later:
Code: | d:\carlos\dev\dm\bin\..\..\dmd\lib\phobos.lib(winsock) Offset 087B7H Record Type 0091
Error 1: Previous Definition Different : _WSADESCRIPTION_LEN
d:\carlos\dev\dm\bin\..\..\dmd\lib\phobos.lib(winsock) Offset 087CFH Record Type 0091
Error 1: Previous Definition Different : _WSASYS_STATUS_LEN
d:\carlos\dev\dm\bin\..\..\dmd\lib\phobos.lib(winsock) Offset 08813H Record Type 0091
Error 1: Previous Definition Different : _IOCPARM_MASK
d:\carlos\dev\dm\bin\..\..\dmd\lib\phobos.lib(winsock) Offset 08820H Record Type 0091
Error 1: Previous Definition Different : _IOC_IN
d:\carlos\dev\dm\bin\..\..\dmd\lib\phobos.lib(winsock) Offset 0882EH Record Type 0091
Error 1: Previous Definition Different : _FIONBIO |
(DMD 0.123) |
This is likely due to both mango.io.Socket and Phobos.std.socket being linked (the items noted are all 'const int', so it's a bit odd that the Linker has something to say about 'em). |
|
Back to top |
|
|
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Wed May 18, 2005 7:51 am Post subject: |
|
|
kris wrote: |
In the meantime you might try something like this:
Code: | import mango.utils.Text;
import mango.format.Int;
int index = Text.indexOf (response, ' ');
char[] protocol = response[0..index];
int status = Int.parse (response[index..length]);
index = Text.indexOf (response, ' ', index+1);
int eol = Text.indexOf (response, '\n', index);
char[] reason = response[index..eol];
|
|
Thanks. I already parsed it myself before, I just wanted to have it done. Lazyness, you know... |
|
Back to top |
|
|
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Wed May 18, 2005 7:52 am Post subject: |
|
|
kris wrote: | This is likely due to both mango.io.Socket and Phobos.std.socket being linked (the items noted are all 'const int', so it's a bit odd that the Linker has something to say about 'em). |
Could that be a reason good enough for you to start using std.socket instead of mango.io.Socket? |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Wed May 18, 2005 9:47 am Post subject: |
|
|
Carlos wrote: | kris wrote: | This is likely due to both mango.io.Socket and Phobos.std.socket being linked (the items noted are all 'const int', so it's a bit odd that the Linker has something to say about 'em). |
Could that be a reason good enough for you to start using std.socket instead of mango.io.Socket? |
I wish; it would alleviate some work for me. Things have not changed in this regard since this post: http://www.dsource.org/forums/viewtopic.php?t=158 |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Wed May 18, 2005 9:52 am Post subject: |
|
|
Carlos wrote: | kris wrote: |
In the meantime you might try something like this:
Code: | import mango.utils.Text;
import mango.format.Int;
int index = Text.indexOf (response, ' ');
char[] protocol = response[0..index];
int status = Int.parse (response[index..length]);
index = Text.indexOf (response, ' ', index+1);
int eol = Text.indexOf (response, '\n', index);
char[] reason = response[index..eol];
|
|
Thanks. I already parsed it myself before, I just wanted to have it done. Lazyness, you know... |
What was the story with ResponseLine being private? Can you access it regardless? |
|
Back to top |
|
|
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Wed May 18, 2005 10:08 am Post subject: |
|
|
kris wrote: | What was the story with ResponseLine being private? Can you access it regardless? |
Yes.
Mmm... I think I know the reason: I think access modifiers don't work for classes and such. I think there's a bug report or two for that. |
|
Back to top |
|
|
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Wed May 18, 2005 10:12 am Post subject: |
|
|
I see. I'm following this there. |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Wed May 18, 2005 10:17 am Post subject: |
|
|
Carlos wrote: | kris wrote: | What was the story with ResponseLine being private? Can you access it regardless? |
Yes.
Mmm... I think I know the reason: I think access modifiers don't work for classes and such. I think there's a bug report or two for that. |
You mean, I didn't make the ctor private? Doh! |
|
Back to top |
|
|
|