REBOL [ file: %rebhtty.r name: "RebHTTY" title: "RebHTTY" purpose: "HTTP console in REBOL like HTTY console in Ruby" date: 23/06/2011 version: 0.2.1 author: "RedChronicle" url: http://www.red-chronicle.com history: [ 0.2.1 23/06/2011 { Fix ISSUE#0003 Add inside-tag inner function (to replace body function and to add new function) Remove | in switch (thx guest2 RebelBB) Add title, debug functions } 0.2.0 22/06/2011 "Merge %htty.r and %rebhtty.r" 0.1.2 22/06/2011 "Add r | reuse functions" 0.1.1 21/06/2011 "Add headers | headers-response | body | body-response" 0.1.1 22/06/2011 "Add error management, proxy config in a config file" 0.1.0 20/06/2011 "Creation of the program" 0.1.0 20/06/2011 "Creation of the program" ] scripts: [%my-proxy-config.r] comments: { ISSUE#0001: Pb with display of console-header ( ** Script Error: Cannot use path on none! value ** Where: halt-view ** Near: system/script/header/version newline ISSUE#0002: do-rebol do not work ISSUE#0003: r | reuse do not work ** Script Error: Invalid argument: 2 ** Where: to-integer ** Near: to integer! :value ISSUE#0004: debug false ** Script Error: false word has no context ** Where: execute-action ** Near: false TO IMPLEMENT: # fol[low] : Change the address of the request to the value of the response's 'Location' header # fragment-c[lear] : Alias for fragment-u[nset] # fragment-s[et] FRAGMENT : Sets the fragment of the request's address # fragment-u[nset] : Removes the fragment from the request's address # history-verbose : Displays the details of previous request-response activity in this session # ho[st-set] HOST : Changes the host of the request's address # por[t-set] PORT : Changes the TCP port of the request's address # query-a[dd] NAME [VALUE [NAME [VALUE ...]]] : Adds query-string parameters to the request's address # ... } ] ;foreach script system/script/header/scripts [do script] rebhtty: context [ mode: 'console debug: false console-history: make block! [] http-port: make port! http://0.0.0.0/ open-http: func [url [url!]] [ emit join "Try to connect to " url http-port: make port! url open http-port if debug [write %http-port.txt http-port] emit join "Connected to " url ] close-http: does [ if http-port/host <> "0.0.0.0" [ emit join "Closing connection to " http-port/url close http-port emit "Connection closed." ] ] address: func [adr [string!]] [ if debug [emit rejoin ["[address] " adr]] if adr <> http-port/url [ close-http open-http to-url adr ] ] body: has [http-body [string!]] [ parse http-port/state/inbuffer [thru "
] return http-body ] headers: does [ http-port/locals/headers ] inside-tag: func [tag-name [string!] /local tag-content [string!] ts [string!] te [string!] res [logic!]] [ ts: join "<" tag-name te: rejoin ["" tag-name ">"] res: parse http-port/state/inbuffer [thru ts skip to #"<" copy tag-content to te] if not res [ ts: rejoin ["<" tag-name ">"] parse http-port/state/inbuffer [thru ts copy tag-content to te] ] return tag-content ] emit: func [msg] [ switch mode [ console [print msg] html [print reform [