Objectively
Object oriented framework for 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

Data * httpBody
 The HTTP request body, sent as POST or PUT data.
 
Dictionary * httpHeaders
 The HTTP request headers.
 
HTTPMethod httpMethod
 The HTTP request method.
 
Object object
 The superclass.
 
URL * url
 The URL.
 
- Properties inherited from Object
Class * clazz
 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.
 
URLRequest * initWithURL (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.
 
Object * copy (const Object *self)
 Creates a shallow copy of this Object.
 
void dealloc (Object *self)
 Frees all resources held by this Object.
 
String * description (const Object *self)
 
int hash (const Object *self)
 
Object * init (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 [0]
 The interface type.
 
- Protected Attributes inherited from Object
ObjectInterface * interface [0]
 The interface type.
 

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[0]
protected

The interface type.

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 .interfaceSize = sizeof(URLRequestInterface),
214 .initialize = initialize,
215 });
216 });
217
218 return clazz;
219}
static void initialize(Class *clazz)
Definition Array.c:710
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition Class.c:151
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:90
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

◆ 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:372
#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:356
#define alloc(type)
Allocate and initialize and instance of type.
Definition Class.h:226
static void setObjectForKey(Dictionary *self, const ident obj, const ident key)
Definition Dictionary.c:634
String * str(const char *fmt,...)
Definition String.c:1078
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: