mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Custom Methods
Currently, mIRC has a hard set list of request methods the user can pick from: HEAD, GET, POST, PUT, PATCH, and DELETE.

This has two issues:
1. The OPTIONS and TRACE methods are missing
2. It does not allow for custom/non-standardized methods to be used. The spec allows servers/hosts to use custom methods so long as they follow the format requirements. For example, a host I deal with has a REVERT method that mIRC's $urlget() can't make use of



Splitting and Processing of Status Line
The .reply property returns the full head of the response. Typical behavior with client libraries is to pull out the HTTP version, status code and status text from that reply line to make client-side processing easier; I suggest something of the following:
Code
;; HTTP/1.1 200 OK
echo -ag Reply: $urlget(id).Reply

;; HTTP/1.1 200 OK
echo -ag ReplyLine: $urlget(id).ReplyLine

;; HTTP/1.1
echo -ag VersionText: $urlget(id).VersionText

;; 1.1
echo -ag Version: $urlget(id).Version

;; 200
echo -ag StatusCode: $urlget(id).StatusCode

;; OK
echo -ag StatusText: $urlget(id).StatusText



Retrieving Header Information
I'm not sure what library you are using to perform the requests, but extracting header info can be tedious (and a tad slow) in mSL due to things like the line-length-limit and folded/multiline headers

I propose $urlget have native functionality to retrieve individual headers:

Code
;; Returns all headers (excluding the status line)
$urlget(id).Headers

;; Stores all headers (excluding the status line) in the specified bvar
;; if the bvar exists, its contents are overwrote
$urlget(id, &bvar).Headers

;; Returns the number of individual headers received
$urlget(id, 0).headers

;; Returns the Nth header received
$urlget(id, N).headers

;; Stores the Nth header received in a bvar
;; if the bvar exists its contents are overwrote
$urlget(id, N, &bvar).headers

;; Returns the number of 'name' headers received
$urlget(id, name, 0).headers

;; Returns the Nth 'name' header received
$urlget(id, name, N).headers

;; Stores the Nth 'name' header received in a bvar
;; If the bvar exists, its contents are overwrote
$urlget(id, Some-Header, 1, &bvar).headers

Last edited by FroggieDaFrog; 22/10/20 02:45 AM.

I am SReject
My Stuff
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Examples

Assume the following response is received:
Code
HTTP/1.1 200 OK
Server: site.com
Access-Control-Allow-Origin: *
Content-Encoding: gzip
Content-Type: text/plain; charset=utf-8
Content-Length: 0
Connection: keep-alive
Set-Cookie: sessid=123; Domain=site.com; Path=/; Secure; HttpOnly 
Set-Cookie: uid=abc; Domain=site.com; Path=/; secure; HttpOnly; Max-Age=2592000




Get status line:
Code
Call:
  echo -a $urlget(id).ReplyLine

Result:
  HTTP/1.1 200 OK


Get version text:
Code
Call:
  echo -a $urlget(id).VersionText

Result:
  HTTP/1.1


Get numerical version :
Code
Call:
  echo -a $urlget(id).Version

Result:
  1.1


Get status code:
Code
Call:
  echo -a $urlget(id).StatusCode

Result:
  200


Get status text:
Code
Call:
  echo -a $urlget(id).StatusText

Result:
  OK


Get All Headers
Code
Call:
  echo -a $urlget(id).Headers

Result (line breaks processed for readability):
  Server: site.com
  Access-Control-Allow-Origin: *
  Content-Encoding: gzip
  Content-Type: text/plain; charset=utf-8
  Content-Length: 0
  Connection: keep-alive
  Set-Cookie: sessid=123; Domain=site.com; Path=/; Secure; HttpOnly 
  Set-Cookie: uid=abc; Domain=site.com; Path=/; secure; HttpOnly; Max-Age=2592000


Store all headers in a bvar:
Code
Call:
  echo -ag $urlget(id, &bvar).Headers

Result (number of bytes wrote to the bvar):
  305


Gets the total number of headers received
Code
Call:
  echo -ag $urlget(id, 0).Headers

Result:
  8


Gets the 1st and 3rd header received:
Code
Call:
  echo -ag $urlget(id, 1).Headers
  echo -ag $urlget(id, 3).Headers

Result:
  Server: site.com
  Content-Encoding: gzip


Stores the 5th header in a bvar:
Code
Call:
  echo -ag $urlget(id, 5, &bvar).Headers

Result (number of bytes wrote to the bvar):
  17


Gets the Number of 'Set-Cookie' headers:
Code
Call:
  echo -ag $urlget(id, set-cookie, 0).Headers

Result:
  2


Gets the 1st Set-Cookie header
Code
Call:
  echo -ag $urlget(id, set-cookie, 1).Headers

Result:
  Set-Cookie: sessid=123; Domain=site.com; Path=/; Secure; HttpOnly


Stores the 2nd Set-Cookie header in a bvar
Code
Call:
  echo -ag $urlget(id, set-cookie, 2, &bvar).Headers

Result (number of bytes wrote to the bvar):
  79


Last edited by FroggieDaFrog; 22/10/20 09:52 PM.

I am SReject
My Stuff

Link Copied to Clipboard