Home

Traffic Server Software Developers Kit

URL Functions

The URL functions are listed below.

INKUrlClone

Copies a URL from a specified location in a source marshal buffer to a target marshal buffer.

Prototype

INKMLoc INKUrlClone (INKMBuffer dest_bufp, INKMBuffer src_bufp, INKMLoc src_url_loc)

Arguments

src_bufp and dest_bufp are the source and destination marshal buffers.

src_url_loc is the source URL location within the source marshal buffer.

Description

Copies the contents of the URL at location src_url_loc within the marshal buffer src_bufp to a location within the marshal buffer dest_bufp.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Release the returned handle with a call to INKHandleMLocRelease.

Returns

Returns the INKMLoc location of the copied URL.

INK_ERROR_PTR if an error occurs.

INKUrlCopy

Copies a URL from a specified location in a source marshal buffer to a specified location in a target marshal buffer.

Prototype

INKReturnCode INKUrlCopy (INKMBuffer dest_bufp, INKMLoc dest_url_loc, INKMBuffer src_bufp, INKMLoc src_url_loc)

Arguments

src_bufp and dest_bufp are the source and destination marshal buffers.

src_url_loc and dest_url_loc are the source and destination URL locations within the source and destination marshal buffers. The type INKMLoc is used for marshal buffer locations.

Description

Copies the contents of the URL at location src_url_loc within the marshal buffer src_bufp to the location dest_url_loc within the marshal buffer dest_bufp. INKUrlCopy works correctly even if src_bufp and dest_bufp point to different marshal buffers. It is important to create the destination URL (its marshal buffer and INKMLoc) before you copy into it.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKUrlCreate

Creates a new URL in a marshal buffer.

Prototype

INKMLoc INKUrlCreate (INKMBuffer bufp)

Description

Creates a new URL within the marshal buffer bufp. Release the resulting handle with a call to INKHandleMLocRelease and destroy the URL with a call to INKUrlDestroy. Note that if you destroy the URL, then you must also release the handle.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

A location handle for the URL within the marshal buffer.

INK_ERROR_PTR if an error occurs.

INKUrlDestroy

Destroys a specific URL within a marshal buffer.

Prototype

INKReturnCode INKUrlDestroy (INKMBuffer bufp, INKMLoc url_loc)

Description

Destroys the URL located at url_loc within the marshal buffer bufp.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

[Caution] Caution

Do not forget to release the handle url_loc with a call to INKHandleMLocRelease.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKUrlPrint

Formats a URL stored in a marshal buffer to an INKIOBuffer.

Prototype

INKReturnCode INKUrlPrint (INKMBuffer bufp, INKMLoc url_loc, INKIOBuffer iobufp)

Description

Formats a URL stored in an INKMBuffer to an INKIOBuffer.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKUrlFtpTypeGet

Gets the FTP type of a specific URL.

Prototype

int INKUrlFtpTypeGet (INKMBuffer bufp, INKMLoc url_loc)

Description

Retrieves the FTP type portion of the URL located at url_loc within the marshal buffer bufp.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

Returns 65 if the FTP type is ASCII.

Return 73 if the FTP type is binary.

INK_ERROR_PTR if an error occurs.

INKUrlFtpTypeSet

Sets the FTP type of a specific URL.

Prototype

INKReturnCode INKUrlFtpTypeSet (INKMBuffer bufp, INKMLoc url_loc, int type)

Description

Sets the FTP type portion of the URL located at url_loc within the marshal buffer bufp to the value type. Valid values for the type argument are: 0, 65('A'), 97('a'), 69('E'), 101('e'), 73 ('I'), and 105('i').

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKUrlHostGet

Gets the host portion of a specific URL.

Prototype

const char* INKUrlHostGet (INKMBuffer bufp, INKMLoc url_loc, int *length)

Description

Retrieves the host portion of the URL located at url_loc within the marshal buffer bufp. The length of the returned string is placed in the length argument.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

A pointer to the host portion of the specified URL. Release with a call to INKHandleStringRelease.

INK_ERROR_PTR if an error occurs.

[Note] Note

The returned string is not guaranteed to be null-terminated.

 

INKUrlHostSet

Sets the host portion of a URL to a specific value.

Prototype

INKReturnCode INKUrlHostSet (INKMBuffer bufp, INKMLoc url_loc, const char *value, int length)

Description

Sets the host portion of the URL located at url_loc within the marshal buffer bufp to the string value. If length is -1, then INKUrlHostSet assumes that value is null-terminated. Otherwise, the length of the string value is taken to be length. The string is copied to within bufp, so it is okay to modify or delete value after calling INKUrlHostSet.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKUrlHttpFragmentGet

Gets a specified HTTP fragment of a URL.

Prototype

const char* INKUrlHttpFragmentGet (INKMBuffer bufp, INKMLoc url_loc, int *length)

Description

Retrieves the HTTP fragment portion of the URL located at url_loc within the marshal buffer bufp. INKUrlHttpFragmentGet places the length of the returned string in the length argument.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

A pointer to the HTTP fragment portion of the specified URL. Release with a call to INKHandleStringRelease.

INK_ERROR_PTR if an error occurs.

[Note] Note

The returned string is not guaranteed to be null-terminated.

 

INKUrlHttpFragmentSet

Sets a specified HTTP fragment within a URL.

Prototype

INKReturnCode INKUrlHttpFragmentSet (INKMBuffer bufp, INKMLoc url_loc, const char *value, int length)

Description

Sets the HTTP fragment portion of the URL located at url_loc within the marshal buffer bufp to the string value. If length is -1, then INKUrlHttpFragmentSet assumes that value is null-terminated. Otherwise, the length of the string value is taken to be length. The string is copied to within bufp, so it is okay to modify or delete value after calling INKUrlHttpFragmentSet.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKUrlHttpParamsGet

Gets the HTTP params portion of a specified URL.

Prototype

const char* INKUrlHttpParamsGet (INKMBuffer bufp, INKMLoc url_loc, int *length)

Description

Retrieves the HTTP params portion of the URL located at url_loc within the marshal buffer bufp. INKUrlHttpParamsGet places the length of the returned string in the length argument.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

A pointer to the HTTP params portion of the specified URL. Release with a call to INKHandleStringRelease.

INK_ERROR_PTR if an error occurs.

[Note] Note

The returned string is not guaranteed to be null-terminated.

 

INKUrlHttpParamsSet

Sets the HTTP params portion of a specified URL.

Prototype

INKReturnCode INKUrlHttpParamsSet (INKMBuffer bufp, INKMLoc url_loc, const char *value, int length)

Description

Sets the HTTP params portion of the URL located at url_loc within the marshal buffer bufp to the string value. If length is -1, then INKUrlHttpParamsSet assumes that value is null-terminated. Otherwise, the length of the string value is taken to be length. INKUrlHttpParamsSet copies the string to within bufp, so it is okay to modify or delete value after calling INKUrlHttpParamsSet.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKUrlHttpQueryGet

Gets the HTTP query portion of a specified URL.

Prototype

const char* INKUrlHttpQueryGet (INKMBuffer bufp, INKMLoc url_loc, int *length)

Description

Retrieves the HTTP query portion of the URL located at url_loc within the marshal buffer bufp. INKUrlHttpQueryGet places the length of the returned string in the length argument.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

A pointer to the HTTP query portion of the specified URL. Release with a call to INKHandleStringRelease.

INK_ERROR_PTR if an error occurs.

[Note] Note

The returned string is not guaranteed to be null-terminated.

 

INKUrlHttpQuerySet

Sets the HTTP query portion of a specified URL.

Prototype

INKReturnCode INKUrlHttpQuerySet (INKMBuffer bufp, INKMLoc url_loc, const char *value, int length)

Description

Sets the HTTP query portion of the URL located at url_loc within the marshal buffer bufp to the string value. If length is -1, then INKUrlHttpQuerySet assumes that value is null-terminated. Otherwise, the length of the string value is taken to be length. INKUrlHttpQuerySet copies the string to within bufp, so it's okay to modify or delete value after calling INKUrlHttpQuerySet.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKUrlLengthGet

Calculates the length of a URL's string representation.

Prototype

int INKUrlLengthGet (INKMBuffer bufp, INKMLoc url_loc)

Description

Calculates the length of URL located at url_loc within the marshal buffer bufp if it was returned as a string. This length is the same as the length returned by INKUrlStringGet.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

Returns the calculated length.

INK_ERROR if an error occurs.

INKUrlParse

Parses the specified URL.

Prototype

int INKUrlParse (INKMBuffer bufp, INKMLoc url_loc, const char **start, const char *end)

Description

Parses a URL. The start pointer is both an input and an output parameter, and marks the start of the URL to be parsed. After a successful parse, the start pointer equals the end pointer. The end pointer must be one byte after the last character you want to parse.The URL parsing routine assumes that everything between start and end is part of the URL. It is up to higher-level parsing routines, such as INKHttpHdrParseReq, to determine the actual end of the URL.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

Returns INK_PARSE_DONE if successful.

Returns INK_PARSE_ERROR if an error occurs.

INKUrlPasswordGet

Gets the password portion of a specified URL.

Prototype

const char* INKUrlPasswordGet (INKMBuffer bufp, INKMLoc url_loc, int *length)

Description

Retrieves the password portion of the URL located at url_loc within the marshal buffer bufp. INKUrlPasswordGet places the length of the returned string in the length argument.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

A pointer to the password portion of the specified URL. Release with a call to INKHandleStringRelease.

INK_ERROR_PTR if an error occurs.

[Note] Note

The returned string is not guaranteed to be null-terminated.

 

INKUrlPasswordSet

Sets the password portion of a specified URL.

Prototype

INKReturnCode INKUrlPasswordSet (INKMBuffer bufp, INKMLoc url_loc, const char *value, int length)

Description

Sets the password portion of the URL located at url_loc within the marshal buffer bufp to the string value. If length is -1, then INKUrlPasswordSet assumes that value is null-terminated. Otherwise, the length of the string value is taken to be length. INKUrlPasswordSet copies the string to within bufp, so it is okay to modify or delete value after calling INKUrlPasswordSet.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKUrlPathGet

Gets the path portion of a specified URL.

Prototype

const char* INKUrlPathGet (INKMBuffer bufp, INKMLoc url_loc, int *length)

Description

Retrieves the path portion of the URL located at url_loc within the marshal buffer bufp. INKUrlPathGet places the length of the returned string in the length argument.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

A pointer to the path portion of the specified URL. Release with a call to INKHandleStringRelease.

INK_ERROR_PTR if an error occurs.

[Note] Note

The returned string is not guaranteed to be null-terminated. If the URL contains a query portion, then it is not included in the response (see INKUrlHttpQueryGet).

 

INKUrlPathSet

Sets the path portion of a specified URL.

Prototype

INKReturnCode INKUrlPathSet (INKMBuffer bufp, INKMLoc url_loc, const char *value, int length)

Description

Sets the path portion of the URL located at url_loc within the marshal buffer bufp to the string value. If length is -1, then INKUrlPathSet assumes that value is null-terminated. Otherwise, the length of the string value is taken to be length. INKUrlPathSet copies the string to within bufp, so it is okay to modify or delete value after calling INKUrlPathSet.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKUrlPortGet

Gets the port number portion of a specified URL.

Prototype

int INKUrlPortGet (INKMBuffer bufp, INKMLoc url_loc)

Description

Retrieves the port number portion of the URL located at url_loc within the marshal buffer bufp.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

The port number portion of the specified URL.

INK_ERROR if an error occurs.

INKUrlPortSet

Sets the port number portion of a URL to a specified value.

Prototype

INKReturnCode INKUrlPortSet (INKMBuffer bufp, INKMLoc url_loc, int port)

Description

Sets the port number portion of the URL located at url_loc within the marshal buffer bufp to the value port.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKUrlSchemeGet

Gets the scheme portion of a specified URL.

Prototype

const char* INKUrlSchemeGet (INKMBuffer bufp, INKMLoc url_loc, int *length)

Description

Retrieves the scheme portion of the URL located at url_loc within the marshal buffer bufp. INKUrlSchemeGet places the length of the returned string in the length argument.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

A pointer to the scheme portion of the specified URL. Release with a call to INKHandleStringRelease.

INK_ERROR_PTR if an error occurs.

[Note] Note

The returned string is not guaranteed to be null-terminated.

 

INKUrlSchemeSet

Sets the scheme portion of a specified URL.

Prototype

INKReturnCode INKUrlSchemeSet (INKMBuffer bufp, INKMLoc url_loc, const char *value, int length)

Description

Sets the scheme portion of the URL located at url_loc within the marshal buffer bufp to the string value. If length is -1, then INKUrlSchemeSet assumes that value is null-terminated. Otherwise, the length of the string value is taken to be length. INKUrlSchemeSet copies the string to within bufp, so it's okay to modify or delete value after calling INKUrlSchemeSet.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKUrlStringGet

Constructs a string representation of the URL located at url_loc within the marshal buffer bufp.

Prototype

char* INKUrlStringGet (INKMBuffer bufp, INKMLoc url_loc, int *length)

Description

Constructs a string representation of the URL located at url_loc within the marshal buffer bufp. INKUrlStringGet stores the length of the allocated string in the parameter length (this is the same length that INKUrlLengthGet returns). The returned string is allocated by a call to INKmalloc; it should be freed by a call to INKfree. If length is NULL, then no attempt is made to dereference it.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

A null-terminated string.

INK_ERROR_PTR if there is an error.

INKUrlUserGet

Gets the user portion of a specified URL.

Prototype

const char* INKUrlUserGet (INKMBuffer bufp, INKMLoc url_loc, int *length)

Description

Retrieves the user portion of the URL located at url_loc within the marshal buffer bufp. INKUrlUserGet places the length of the returned string in the length argument.

If in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

A pointer to the user portion of the specified URL. Release with a call to INKHandleStringRelease.

INK_ERROR_PTR if an error occurs.

[Note] Note

The returned string is not guaranteed to be null-terminated.

 

INKUrlUserSet

Sets the user portion of a specified URL.

Prototype

INKReturnCode INKUrlUserSet (INKMBuffer bufp, INKMLoc url_loc, const char *value, int length)

Description

Sets the user portion of the URL located at url_loc within the marshal buffer bufp to the string value. If length is -1, then INKUrlUserSet assumes that value is null-terminated. Otherwise, the length of the string value is taken to be length. INKUrlUserSet copies the string to within bufp, so it is okay to modify or delete value after calling INKUrlUserSet.

If it is in a transaction header, then call after READ_REQUEST_HDR_HOOK.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.