Changeset 8bd866f for lib/http_client.h


Ignore:
Timestamp:
2012-11-10T22:25:58Z (8 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
ddc2de5
Parents:
9e8c945
Message:

Reworked http_client a little bit to support streaming besides just buffering
a complete response before giving it back to the caller.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/http_client.h

    r9e8c945 r8bd866f  
    2626/* http_client allows you to talk (asynchronously, again) to HTTP servers.
    2727   In the "background" it will send the whole query and wait for a complete
    28    response to come back. Right now it's only used by the MSN Passport
    29    authentication code, but it might be useful for other things too (for
    30    example the AIM usericon patch uses this so icons can be stored on
    31    webservers instead of the local filesystem).
     28   response to come back. Initially written for MS Passport authentication,
     29   but used for many other things now like OAuth and Twitter.
    3230   
    33    Didn't test this too much, but it seems to work well. Just don't look
    34    at the code that handles HTTP 30x redirects. ;-) The function is
    35    probably not very useful for downloading lots of data since it keeps
    36    everything in a memory buffer until the download is completed (and
    37    can't pass any data or whatever before then). It's very useful for
    38    doing quick requests without blocking the whole program, though. */
     31   It's very useful for doing quick requests without blocking the whole
     32   program. Unfortunately it doesn't support fancy stuff like HTTP keep-
     33   alives. */
    3934
    4035#include <glib.h>
     
    4237
    4338struct http_request;
     39
     40typedef enum http_client_flags
     41{
     42        HTTPC_STREAMING = 1,
     43} http_client_flags_t;
    4444
    4545/* Your callback function should look like this: */
     
    5353        char *request;          /* The request to send to the server. */
    5454        int request_length;     /* Its size. */
    55         int status_code;        /* The numeric HTTP status code. (Or -1
     55        short status_code;      /* The numeric HTTP status code. (Or -1
    5656                                   if something really went wrong) */
    5757        char *status_string;    /* The error text. */
     
    5959        char *reply_body;
    6060        int body_size;          /* The number of bytes in reply_body. */
    61         /* int finished;           Set to non-0 if the request was completed
    62                                    successfully. */
    63         int redir_ttl;          /* You can set it to 0 if you don't want
     61        short redir_ttl;        /* You can set it to 0 if you don't want
    6462                                   http_client to follow them. */
     63       
     64        http_client_flags_t flags;
    6565       
    6666        http_input_function func;
     
    6868       
    6969        /* Please don't touch the things down here, you shouldn't need them. */
    70        
    7170        void *ssl;
    7271        int fd;
     
    7574        int bytes_written;
    7675        int bytes_read;
     76       
     77        /* Used in streaming mode. Caller should read from reply_body. */
     78        char *sbuf;
     79        size_t sblen;
    7780};
    7881
     
    8386struct http_request *http_dorequest( char *host, int port, int ssl, char *request, http_input_function func, gpointer data );
    8487struct http_request *http_dorequest_url( char *url_string, http_input_function func, gpointer data );
     88
     89/* For streaming connections only; flushes len bytes at the start of the buffer. */
     90void http_flush_bytes( struct http_request *req, size_t len );
Note: See TracChangeset for help on using the changeset viewer.