Objectively
Ultra-lightweight object oriented framework for GNU C.
Loading...
Searching...
No Matches
URLRequest Struct Reference

#include <URLRequest.h>

Overview

A protocol-agnostic abstraction for requesting resources via URLs.

Definition at line 58 of file URLRequest.h.

Inheritance diagram for URLRequest:
Object

Properties

DatahttpBody
 The HTTP request body, sent as POST or PUT data.
 
DictionaryhttpHeaders
 The HTTP request headers.
 
HTTPMethod httpMethod
 The HTTP request method.
 
Object object
 The superclass.
 
URLurl
 The URL.
 
- Properties inherited from Object
Classclazz
 Every instance of Object begins with a pointer to its Class.
 
unsigned int magic
 A header to allow introspection of Object types.
 

Methods

Class_URLRequest (void)
 The URLRequest archetype.
 
URLRequestinitWithURL (URLRequest *self, URL *url)
 Initializes this URLRequest with the specified URL.
 
void setValueForHTTPHeaderField (URLREquest *self, const char *value, const char *field)
 
void setValueForHTTPHeaderField (URLRequest *self, const char *value, const char *field)
 Sets a value for the specified HTTP header.
 
- Methods inherited from Object
Class_Object (void)
 The Object archetype.
 
Objectcopy (const Object *self)
 Creates a shallow copy of this Object.
 
void dealloc (Object *self)
 Frees all resources held by this Object.
 
Stringdescription (const Object *self)
 
int hash (const Object *self)
 
Objectinit (Object *self)
 Initializes this Object.
 
bool isEqual (const Object *self, const Object *other)
 Tests equality of the other Object.
 
bool isKindOfClass (const Object *self, const Class *clazz)
 Tests for Class hierarchy membership.
 

Protected Attributes

URLRequestInterface * interface
 The interface.
 
- Protected Attributes inherited from Object
ObjectInterface * interface
 The interface.
 

Property Details

◆ httpBody

Data* URLRequest::httpBody

The HTTP request body, sent as POST or PUT data.

Definition at line 74 of file URLRequest.h.

◆ httpHeaders

Dictionary* URLRequest::httpHeaders

The HTTP request headers.

Definition at line 79 of file URLRequest.h.

◆ httpMethod

HTTPMethod URLRequest::httpMethod

The HTTP request method.

Definition at line 84 of file URLRequest.h.

◆ interface

URLRequestInterface* URLRequest::interface
protected

The interface.

Definition at line 69 of file URLRequest.h.

◆ object

Object URLRequest::object

The superclass.

Definition at line 63 of file URLRequest.h.

◆ url

URL* URLRequest::url

The URL.

Definition at line 89 of file URLRequest.h.

Method Details

◆ _URLRequest()

Class * _URLRequest ( void  )

The URLRequest archetype.

Returns
The URLRequest Class.

Definition at line 204 of file URLRequest.c.

204 {
205 static Class *clazz;
206 static Once once;
207
208 do_once(&once, {
209 clazz = _initialize(&(const ClassDef) {
210 .name = "URLRequest",
211 .superclass = _Object(),
212 .instanceSize = sizeof(URLRequest),
213 .interfaceOffset = offsetof(URLRequest, interface),
214 .interfaceSize = sizeof(URLRequestInterface),
216 });
217 });
218
219 return clazz;
220}
static void initialize(Class *clazz)
Definition Array.c:710
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition Class.c:86
long Once
The Once type.
Definition Once.h:37
#define do_once(once, block)
Executes the given block at most one time.
Definition Once.h:43
ClassDefs are passed to _initialize via an archetype to initialize a Class.
Definition Class.h:41
The runtime representation of a Class.
Definition Class.h:95
Class * clazz
Every instance of Object begins with a pointer to its Class.
Definition Object.h:55
Class * _Object(void)
The Object archetype.
Definition Object.c:136
A protocol-agnostic abstraction for requesting resources via URLs.
Definition URLRequest.h:58
URLRequestInterface * interface
The interface.
Definition URLRequest.h:69

◆ initWithURL()

URLRequest * initWithURL ( URLRequest self,
URL url 
)

Initializes this URLRequest with the specified URL.

Parameters
selfThe URLRequest.
urlThe URL.
Returns
The initialized URLRequest, or NULL on error.

Definition at line 150 of file URLRequest.c.

150 {
151
152 assert(url);
153
154 self = (URLRequest *) super(Object, self, init);
155 if (self) {
156 self->url = retain(url);
157 assert(self->url);
158
159 self->httpMethod = HTTP_GET;
160 }
161
162 return self;
163}
ident retain(ident obj)
Atomically increment the given Object's reference count.
Definition Class.c:210
#define super(type, obj, method,...)
@ HTTP_GET
Definition URLRequest.h:46
Object is the root Class of The Objectively Class hierarchy.
Definition Object.h:46
Object * init(Object *self)
Initializes this Object.
Definition Object.c:83
HTTPMethod httpMethod
The HTTP request method.
Definition URLRequest.h:84
URL * url
The URL.
Definition URLRequest.h:89

◆ setValueForHTTPHeaderField() [1/2]

void setValueForHTTPHeaderField ( URLREquest *  self,
const char *  value,
const char *  field 
)

◆ setValueForHTTPHeaderField() [2/2]

void setValueForHTTPHeaderField ( URLRequest self,
const char *  value,
const char *  field 
)

Sets a value for the specified HTTP header.

Parameters
selfThe URLRequest.
valueThe HTTP header value.
fieldThe HTTP header field.

Definition at line 169 of file URLRequest.c.

169 {
170
171 if (self->httpHeaders == NULL) {
172 self->httpHeaders = (Dictionary *) $(alloc(Dictionary), init);
173 }
174
175 String *object = str(value);
176 String *key = str(field);
177
178 $((Dictionary *) self->httpHeaders, setObjectForKey, object, key);
179
180 release(object);
181 release(key);
182}
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Definition Class.c:195
#define alloc(type)
Allocate and initialize and instance of type.
Definition Class.h:176
static void setObjectForKey(Dictionary *self, const ident obj, const ident key)
Definition Dictionary.c:634
String * str(const char *fmt,...)
Definition String.c:1084
Key-value stores.
Definition Dictionary.h:60
UTF-8 strings.
Definition String.h:69
Dictionary * httpHeaders
The HTTP request headers.
Definition URLRequest.h:79

The documentation for this struct was generated from the following files: