Appearance
api.service.HttpParser 1.2.0
Commonly useful methods for parsing HTTP-related information are exposed by this service.
Methods
parseForwardedHeader()
This static method takes an incoming request's descriptor and delivers a list of peers according to some Forwarded
header included with it. An empty list is returned if there is no such header.
javascript
const peers = api.service.HttpParser.parseForwardedHeader( this.request );
In the resulting list, every peer is described by optional properties for
, by
, host
and proto
as given in the Forwarded
request header. The first item is assumed to describe the actually requesting client. All other items describe some involved reverse proxy or similar.
parseXForwardedHeaders()
This static method takes an incoming request's descriptor and delivers a list of peers according to X-Forwarded-For
header, X-Forwarded-Host
header or X-Forwarded-Proto
header optionally included with it. An empty list is returned if there is no X-Forwarded-For
header. Values of the other two headers are used to augment the information on first item of resulting list.
javascript
const peers = api.service.HttpParser.parseXForwardedHeaders( this.request );
In the resulting list, every peer is described by properties for
, host
and proto
based on inspected headers with host
and proto
properties may appear in first item of list, only, which is assumed to describe the actually requesting client while all other items describe some involved reverse proxy or similar.
getPeersList()
This static method is conveniently combining parseForwardedHeader() and parseXForwardedHeaders() for delivering result of either function given some provided request preferring the former's result over the latter one's.
javascript
const peers = api.service.HttpParser.getPeersList( this.request );
It simplifies access on actually requesting client like this:
javascript
const [client] = api.service.HttpParser.getPeersList( this.request );