KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
redirect.h File Reference

HTTP redirect following (sync + async). More...

#include <keel/allocator.h>
#include <keel/client.h>
#include <keel/client_pool.h>
#include <keel/error.h>
#include <keel/event_ctx.h>
#include <keel/url.h>
Include dependency graph for redirect.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  KlRedirectConfig
 

Macros

#define KL_REDIRECT_DEFAULT_MAX   10
 Default maximum redirects.
 

Typedefs

typedef struct KlRedirectClient KlRedirectClient
 
typedef void(* KlRedirectDoneFn) (KlRedirectClient *rc, void *user_data)
 Callback invoked when an async redirect-following request completes.
 

Functions

int kl_redirect_request (KlAllocator *alloc, const KlClientConfig *cfg, const KlRedirectConfig *redir, const char *method, const char *url, const KlClientHeader *headers, int num_headers, const char *body, size_t body_len, KlClientResponse *resp)
 Synchronous HTTP request with automatic redirect following.
 
int kl_redirect_request_pooled (KlClientPool *pool, KlAllocator *alloc, const KlClientConfig *cfg, const KlRedirectConfig *redir, const char *method, const char *url, const KlClientHeader *headers, int num_headers, const char *body, size_t body_len, KlClientResponse *resp)
 Synchronous pooled HTTP request with automatic redirect following.
 
KlRedirectClientkl_redirect_start (KlEventCtx *ev_ctx, KlAllocator *alloc, const KlClientConfig *cfg, const KlRedirectConfig *redir, const char *method, const char *url, const KlClientHeader *headers, int num_headers, const char *body, size_t body_len, KlRedirectDoneFn on_done, void *user_data)
 Start an asynchronous HTTP request with automatic redirect following.
 
KlRedirectClientkl_redirect_start_pooled (KlClientPool *pool, KlEventCtx *ev_ctx, KlAllocator *alloc, const KlClientConfig *cfg, const KlRedirectConfig *redir, const char *method, const char *url, const KlClientHeader *headers, int num_headers, const char *body, size_t body_len, KlRedirectDoneFn on_done, void *user_data)
 Start an asynchronous pooled HTTP request with redirect following.
 
const KlClientResponsekl_redirect_response (const KlRedirectClient *rc)
 Get the final response from a completed redirect client.
 
int kl_redirect_error (const KlRedirectClient *rc)
 Check if the redirect request completed with an error.
 
KlError kl_redirect_last_error (const KlRedirectClient *rc)
 Get the specific error code from a completed redirect request.
 
void kl_redirect_cancel (KlRedirectClient *rc)
 Cancel an in-flight redirect request.
 
void kl_redirect_free (KlRedirectClient *rc)
 Free all redirect client resources.
 

Detailed Description

HTTP redirect following (sync + async).

Orthogonal redirect module that wraps the existing client APIs with automatic 3xx redirect following. Does not modify client.h or client.c. Supports both unpooled and pooled variants.

Macro Definition Documentation

◆ KL_REDIRECT_DEFAULT_MAX

#define KL_REDIRECT_DEFAULT_MAX   10

Default maximum redirects.

Typedef Documentation

◆ KlRedirectClient

◆ KlRedirectDoneFn

typedef void(* KlRedirectDoneFn) (KlRedirectClient *rc, void *user_data)

Callback invoked when an async redirect-following request completes.

Function Documentation

◆ kl_redirect_request()

int kl_redirect_request ( KlAllocator alloc,
const KlClientConfig cfg,
const KlRedirectConfig redir,
const char *  method,
const char *  url,
const KlClientHeader headers,
int  num_headers,
const char *  body,
size_t  body_len,
KlClientResponse resp 
)

Synchronous HTTP request with automatic redirect following.

Follows 301/302/303/307/308 redirects up to max_redirects hops. Method transformation per RFC 7231/7538: 301/302/303 change POST/PUT/PATCH to GET (dropping body); 307/308 preserve method.

Returns
0 on success, -1 on error. Sets resp->error on failure.

◆ kl_redirect_request_pooled()

int kl_redirect_request_pooled ( KlClientPool pool,
KlAllocator alloc,
const KlClientConfig cfg,
const KlRedirectConfig redir,
const char *  method,
const char *  url,
const KlClientHeader headers,
int  num_headers,
const char *  body,
size_t  body_len,
KlClientResponse resp 
)

Synchronous pooled HTTP request with automatic redirect following.

◆ kl_redirect_start()

KlRedirectClient * kl_redirect_start ( KlEventCtx ev_ctx,
KlAllocator alloc,
const KlClientConfig cfg,
const KlRedirectConfig redir,
const char *  method,
const char *  url,
const KlClientHeader headers,
int  num_headers,
const char *  body,
size_t  body_len,
KlRedirectDoneFn  on_done,
void *  user_data 
)

Start an asynchronous HTTP request with automatic redirect following.

Returns
Client handle, or NULL on immediate failure.

◆ kl_redirect_start_pooled()

KlRedirectClient * kl_redirect_start_pooled ( KlClientPool pool,
KlEventCtx ev_ctx,
KlAllocator alloc,
const KlClientConfig cfg,
const KlRedirectConfig redir,
const char *  method,
const char *  url,
const KlClientHeader headers,
int  num_headers,
const char *  body,
size_t  body_len,
KlRedirectDoneFn  on_done,
void *  user_data 
)

Start an asynchronous pooled HTTP request with redirect following.

Returns
Client handle, or NULL on immediate failure.

◆ kl_redirect_response()

const KlClientResponse * kl_redirect_response ( const KlRedirectClient rc)

Get the final response from a completed redirect client.

Returns
Response pointer (valid until kl_redirect_free), or NULL if error.

◆ kl_redirect_error()

int kl_redirect_error ( const KlRedirectClient rc)

Check if the redirect request completed with an error.

Returns
0 on success, -1 on error.

◆ kl_redirect_last_error()

KlError kl_redirect_last_error ( const KlRedirectClient rc)

Get the specific error code from a completed redirect request.

◆ kl_redirect_cancel()

void kl_redirect_cancel ( KlRedirectClient rc)

Cancel an in-flight redirect request.

◆ kl_redirect_free()

void kl_redirect_free ( KlRedirectClient rc)

Free all redirect client resources.