r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3 Schemes] Implementors guide

Graham
5-Jan-2010
[60]
Kaj raised the point of how much memory r2 and r3 take compared with 
the clone ...
BrianH
5-Jan-2010
[61]
Yes, another point for the refactoring. The clone doesn't do as much 
though.
Graham
5-Jan-2010
[62x4]
read and write are very similar ... can we do this?

		read: func [
			port [port!]
			/write data
		] [
			either any-function? :port/awake [

    unless open? port [cause-error 'Access 'not-open port/spec/ref] 
				if port/state/state <> 'ready [http-error "Port not ready"] 
				port/state/awake: :port/awake 
				do-request port 
				port
			] [
				sync-op port either write [ data ] [[]]
			]
		] 
		write: func [
			port [port!] 
			value
		] [

   unless any [block? :value any-string? :value] [value: form :value] 

   unless block? value [value: reduce [[Content-Type: "application/x-www-form-urlencoded; 
   charset=utf-8"] value]] 
			read/write port data 
		]
should be

read/write port [parse-write-dialect port value]
well... can't use /write as the refinement .. but the idea ...
heh ..Gabriele must be top down programming .. .he writes the higher 
order code first and then the supporting definitions.
BrianH
5-Jan-2010
[66]
He programs in the RLP and then it topologically sorts the code.
Graham
5-Jan-2010
[67]
Dunno what that means .. but it's the same in the rlp
BrianH
5-Jan-2010
[68]
Ah, less topological sorting than I thought.
Graham
5-Jan-2010
[69x3]
Which is the latest ... prot-http.rlp or prot-http.r ?
later ..
ie. is prot-http.r generated from the rebol literate programming 
document?
BrianH
5-Jan-2010
[72x2]
prot-http.r is the latest. prot-http.rlp was just uploaded later.
The original prot-http.r was generated from .rlp, but has since been 
revised directly. Look at the revision history with LF and DIFF.
Graham
5-Jan-2010
[74x2]
ok,  I see this

        spec/headers: third make make object! [
in the rlp, and in the .r

	spec/headers: body-of make make object! [
so they are different.
BrianH
5-Jan-2010
[76]
body-of would work, third wouldn't.
Graham
5-Jan-2010
[77x2]
so the rlp is correct?  and the .r is not ?
reverse that ...
BrianH
5-Jan-2010
[79]
The .rlp version is more than 2 years old, the .r is more recent 
and works.
Graham
5-Jan-2010
[80]
oh ...ok.
BrianH
5-Jan-2010
[81]
works, sort-of, still needs work.
Graham
5-Jan-2010
[82]
spec/headers: body-of make make object! [
		Accept: "*/*" 
		Accept-Charset: "utf-8" 
		Host: either spec/port-id <> 80 [
			rejoin [form spec/host #":" spec/port-id]
		] [
			form spec/host
		] 
		User-Agent: "REBOL"
	] spec/headers 
what exactly is this code doing?
BrianH
5-Jan-2010
[83x2]
Makes a object containing the standard http headers derived from 
the template object, also defined in a literal spec.
Has an extra object of overhead.
Graham
5-Jan-2010
[85]
so spec/headers contains the standard template, and it adds these 
other members to this template?
BrianH
5-Jan-2010
[86x2]
Yeah, I think so. I shoud check for sure. This is why I am starting 
woth mezz-ports.r first.
Something looks reversed, like spec/headers is using the specific 
headers as a template rather than the reverse. Don't know why yet.
Graham
5-Jan-2010
[88x3]
So, it is modifying the original spec/headers by adding these new 
members to spec/headers ...  as a way of modifying the object in 
situ as it were
I wonder why he can't do this 

spec/headers: make spec/headers [
		Accept: "*/*" 
		Accept-Charset: "utf-8" 
		Host: either spec/port-id <> 80 [
			rejoin [form spec/host #":" spec/port-id]
		] [
			form spec/host
		] 
		User-Agent: "REBOL"
]
oh ... headers is a block and not an object!
BrianH
5-Jan-2010
[91]
I think that the Accept, Accept-Charset and User-Agent headers are 
the defaults, and spec/headers are the user-specifiable options.
Graham
5-Jan-2010
[92]
So he is using make object! to ensure that he has unique members 
in the created block!
BrianH
5-Jan-2010
[93]
Actually, an object is created. Then it is converted to a string 
later.
Graham
5-Jan-2010
[94]
Yeah .. seems a rather round about way of doing things.
BrianH
5-Jan-2010
[95x2]
There are a lot of interesting tricks you can do with objects that 
are much trickier with string-format headers. It's worth it.
We can look into reducing the overhead though.
Graham
5-Jan-2010
[97x6]
In make-http-request there is this

	result: rejoin [
		uppercase form method #" " 
		either file? target [next mold target] [target] 
		" HTTP/1.0" CRLF
	] 

since it is stated that http 1.1 is being supported, we should change 
this to 1.1
yeah ... some function that appends one block of set pairs to another 
without overwriting the original ...
make-http-request  says that content is [ any-string! none! ]
it then converts this to binary.

But if we want to send a binary file using PUT,  I think this must 
mean we need to convert that file to string first ... which seems 
wrong.
we should allow binary! as well ... and change the code to 

if content [
		if string? [ content: to binary! content ] 
		repend result ["Content-Length: " length? content CRLF]
	]
if content [
		if string? content [ content: to binary! content ] 
		repend result ["Content-Length: " length? content CRLF]
	]
Also, if there is no content, then the content-length header is not 
set ... 

Here's my suggested changes at the bottom 


http://rebol.wik.is/Rebol3/Schemes/Http/Prot-http.r/Make-http-request
BrianH
5-Jan-2010
[103x4]
1.1 didn't work since chunked encoding was broken, so they reverted 
to 1.0. Proper 1.1 support is on the list to fix.
However, chunked encoding needs to be fixed first, before 1.1 support 
can be reenabled.
The .rlp http client was also written before the Unicode changes 
were finished, so we need to review for those fixes too.
That would affect the string-vs-binary situation.
Graham
5-Jan-2010
[107]
I'm looking at the .r source ...
BrianH
5-Jan-2010
[108]
Which has only been patched a few times, not yet properly reworked.
Graham
5-Jan-2010
[109]
well, I think not setting the content-length header might be bug 
..