Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on 1:sockread:mR_*:
- ;check for errors, if so, echo out then stop processing
- if ($sockerr) { echo -s Sockread error from: $sockname | return }
- ;if the sockmark isn't set lets get it to "GetHeader" which
- ;tells the script to, well, get the header
- if (!$sock($sockname).mark) { sockmark $sockname GetHeader }
- ;setup so we can loop back
- :loop
- ;read all data in the receive buffer into &tmp
- sockread $sock($sockname).rq &tmp
- ;if no data was read, stop processing
- if (!$sockbr) { return }
- ;if the header is "GetHeader" lets do some processing
- if ($sock($sockname).mark == GetHeader) {
- ;set %n to the data saved from socket, plus the data we just read
- var %n = $($+(%,$sockname),2) $+ $bvar(&tmp,1-).text
- ;if Get *crlfcrlf* is wildcard matched in %n, the header has been read:
- if (GET * $+ $str($crlf,2) $+ * iswm %n) {
- ;set %head to the entire header
- var %head = $regsubex(%n,/(\r\n\r\n.*)/s,$Null)
- ;change the sockets mark to GotHeader so we stop looking for the head
- sockmark $sockname GotHeader
- ;HEY, I GOT THAT DOUBLE CRLFCRLF I WAS LOOKING FOR, lets do some stuff
- echo -s %head
- }
- ;if Get *crlfcrlf* isn't matched in %n, lets save it, to look at on the next read
- else { set $+(%,$sockname) %n }
- }
- ;loop back so we can try to read more data
- goto loop
- }
Advertisement
Add Comment
Please, Sign In to add comment