Unit internetaccess

Description

You can use this unit to configure and create internet connections.

Currently it only supports HTTP/S connections, but this might change in future (e.g. to also support ftp)

Overview

Classes, Interfaces, Objects and Records

Name Description
Record TInternetConfig Internet configuration
Record TDecodedUrl A record storing a decoded url.
Record TMIMEMultipartSubData  
Record TMIMEMultipartData encodes the data corresponding to RFC 1341 (preliminary)
Class THTTPHeaderList  
Record TCookieManager  
Record TTransfer  
Class TTransferContentInflater  
Class TInternetAccess Abstract base class for connections
Class EInternetException  

Functions and Procedures

function decodeURL(const totalURL: string; normalize: boolean = true): TDecodedUrl;
function decodeURL(const protocol, host, url: string; normalize: boolean = true): TDecodedUrl;
function guessType(const data: string): TRetrieveType;
function httpRequest(url: string): string; overload;
function httpRequest(url: string; rawpostdata: string): string; overload;
function httpRequest(url: string; postdata: TStringList): string; overload;
function httpRequest(const method, url, rawdata: string): string; overload;
function defaultInternet: TInternetAccess;
procedure freeThreadVars;

Types

PInternetConfigTInternetConfig;
TDecodedUrlParts = set of (dupProtocol, dupUsername, dupPassword, dupHost, dupPort, dupPath, dupParams, dupLinkTarget);
TInternetAccessDataBlock = TPCharView;
PMIMEMultipartSubData = ˆTMIMEMultipartSubData;
THeaderKind = (...);
TCookieFlags = set of (cfHostOnly, cfSecure );
TInternetAccessReaction = (...);
THeaderEnumCallback = procedure (data: pointer; headerKindHint: THeaderKind; const name, value: string);
TProgressEvent = procedure (sender: TObject; progress,maxprogress: longint) of object;
TTransferClearEvent = procedure() of object;
TTransferBlockWriteEvent = TStreamLikeWriteNativeInt;
TTransferStartEvent = procedure (sender: TObject; const method: string; const url: TDecodedUrl; const data: TInternetAccessDataBlock) of object;
TTransferReactEvent = procedure (sender: TInternetAccess; var transfer: TTransfer; var reaction: TInternetAccessReaction) of object;
TTransferEndEvent = procedure (sender: TObject; var transfer: TTransfer) of object;
TTransferInflaterClass = class of TTransferContentInflater;
TUrlEncodingModel = (...);
TInternetAccessClass=class of TInternetAccess;
TRetrieveType = (...);

Constants

DecodedUrlPartsALL = [dupProtocol, dupUsername, dupPassword, dupHost, dupPort, dupPath, dupParams, dupLinkTarget];
ContentTypeUrlEncoded: string = 'application/x-www-form-urlencoded';
ContentTypeMultipart: string = 'multipart/form-data';
ContentTypeTextPlain: string = 'text/plain';

Variables

defaultInternetConfiguration: TInternetConfig;
defaultInternetAccessClass:TInternetAccessClass = nil;
defaultTransferInflater: TTransferInflaterClass;

Description

Functions and Procedures

function decodeURL(const totalURL: string; normalize: boolean = true): TDecodedUrl;

Splits a url into parts

Parameters
normalize
performs some normalizations (e.g. foo//bar -> foo/bar)
function decodeURL(const protocol, host, url: string; normalize: boolean = true): TDecodedUrl;
 
function guessType(const data: string): TRetrieveType;

Guesses the type of a given string

E.g. for 'http://' it returns rtRemoteURL, for '/tmp' rtFile and for '<abc/>' rtXML.
Internally used by simpleinternet.retrieve to determine how to actually retrieve the data.

function httpRequest(url: string): string; overload;

Make a HTTP GET request to a certain url.

function httpRequest(url: string; rawpostdata: string): string; overload;

Make a HTTP POST request to a certain url, sending the data in rawpostdata unmodified to the server.

function httpRequest(url: string; postdata: TStringList): string; overload;

Make a HTTP POST request to a certain url, sending the data in postdata to the server, after url encoding all name=value pairs of it.

function httpRequest(const method, url, rawdata: string): string; overload;

Make a HTTP request to a certain url, sending the data in rawdata unmodified to the server.

function defaultInternet: TInternetAccess;

This provides a thread-safe default internet

procedure freeThreadVars;

If you use the procedural interface from different threads, you have to call freeThreadVars before the thread terminates to prevent memory leaks

Types

PInternetConfigTInternetConfig;
 
TDecodedUrlParts = set of (dupProtocol, dupUsername, dupPassword, dupHost, dupPort, dupPath, dupParams, dupLinkTarget);
 
TInternetAccessDataBlock = TPCharView;
 
PMIMEMultipartSubData = ˆTMIMEMultipartSubData;
 
THeaderKind = (...);
 
Values
  • iahUnknown
  • iahContentType
  • iahContentDisposition
  • iahAccept
  • iahReferer
  • iahLocation
  • iahSetCookie
  • iahCookie
  • iahUserAgent
TCookieFlags = set of (cfHostOnly, cfSecure );
 
TInternetAccessReaction = (...);
 
Values
  • iarAccept
  • iarFollowRedirectGET
  • iarFollowRedirectKeepMethod
  • iarRetry
  • iarReject
THeaderEnumCallback = procedure (data: pointer; headerKindHint: THeaderKind; const name, value: string);
 
TProgressEvent = procedure (sender: TObject; progress,maxprogress: longint) of object;

Event to monitor the progress of a download (measured in bytes)

TTransferClearEvent = procedure() of object;

Event to intercept transfers end/start

TTransferBlockWriteEvent = TStreamLikeWriteNativeInt;
 
TTransferStartEvent = procedure (sender: TObject; const method: string; const url: TDecodedUrl; const data: TInternetAccessDataBlock) of object;
 
TTransferReactEvent = procedure (sender: TInternetAccess; var transfer: TTransfer; var reaction: TInternetAccessReaction) of object;
 
TTransferEndEvent = procedure (sender: TObject; var transfer: TTransfer) of object;
 
TTransferInflaterClass = class of TTransferContentInflater;
 
TUrlEncodingModel = (...);

URL Encoding encodes every special character #$AB by %AB. This model describes which characters are special:

Values
  • ueHTMLForm: Encode for application/x-www-form-urlencoded as defined in HTML 5 standard
  • ueHTMLMultipartFieldName: Encode for multipart/form-data field names as defined in HTML 5 standard
  • ueURLPath: Encode for the path part of an URL
  • ueURLQuery: Encode for the query part of an URL
  • ueXPathURI: Encode for the XPath/XQuery function fn:encode-for-uri as defined in the XPath standard
  • ueXPathHTML4: Encode for the XPath/XQuery function fn:escape-html-uri as defined in the XPath standard (they quote the the HTML4 standard)
  • ueXPathFromIRI: Encode for the XPath/XQuery function fn:iri-to-uri as defined in the XPath standard
TInternetAccessClass=class of TInternetAccess;
 
TRetrieveType = (...);
 
Values
  • rtEmpty
  • rtRemoteURL
  • rtFile
  • rtXML
  • rtJSON

Constants

DecodedUrlPartsALL = [dupProtocol, dupUsername, dupPassword, dupHost, dupPort, dupPath, dupParams, dupLinkTarget];
 
ContentTypeUrlEncoded: string = 'application/x-www-form-urlencoded';
 
ContentTypeMultipart: string = 'multipart/form-data';
 
ContentTypeTextPlain: string = 'text/plain';
 

Variables

defaultInternetConfiguration: TInternetConfig;

default configuration, used by all internet access classes

defaultInternetAccessClass:TInternetAccessClass = nil;

default internet access. This controls which internet library the program will use.

defaultTransferInflater: TTransferInflaterClass;
 

Generated by PasDoc 0.16.0.