Tor  0.4.7.0-alpha-dev
Macros | Functions
proto_http.c File Reference

Parse a subset of the HTTP protocol. More...

#include "core/or/or.h"
#include "lib/buf/buffers.h"
#include "core/proto/proto_http.h"

Go to the source code of this file.

Macros

#define PROTO_HTTP_PRIVATE
 
#define CONTENT_LENGTH   "\r\nContent-Length: "
 

Functions

int peek_buf_has_http_command (const buf_t *buf)
 
int fetch_from_buf_http (buf_t *buf, char **headers_out, size_t max_headerlen, char **body_out, size_t *body_used, size_t max_bodylen, int force_complete)
 
STATIC int buf_http_find_content_length (const char *headers, size_t headerlen, size_t *result_out)
 

Detailed Description

Parse a subset of the HTTP protocol.

Definition in file proto_http.c.

Function Documentation

◆ buf_http_find_content_length()

STATIC int buf_http_find_content_length ( const char *  headers,
size_t  headerlen,
size_t *  result_out 
)

Scan the HTTP headers in the headerlen-byte memory range at headers, looking for a "Content-Length" header. Try to set *result_out to the numeric value of that header if possible. Return -1 if the header was malformed, 0 if it was missing, and 1 if it was present and well-formed.

Definition at line 139 of file proto_http.c.

◆ fetch_from_buf_http()

int fetch_from_buf_http ( buf_t *  buf,
char **  headers_out,
size_t  max_headerlen,
char **  body_out,
size_t *  body_used,
size_t  max_bodylen,
int  force_complete 
)

There is a (possibly incomplete) http statement on buf, of the form "\%s\\r\\n\\r\\n\%s", headers, body. (body may contain NULs.) If a) the headers include a Content-Length field and all bytes in the body are present, or b) there's no Content-Length field and all headers are present, then:

  • strdup headers into *headers_out, and NUL-terminate it.
  • memdup body into *body_out, and NUL-terminate it.
  • Then remove them from buf, and return 1.
  • If headers or body is NULL, discard that part of the buf.
  • If a headers or body doesn't fit in the arg, return -1. (We ensure that the headers or body don't exceed max len, even if we're planning to discard them.)
  • If force_complete is true, then succeed even if not all of the content has arrived.

Else, change nothing and return 0.

Definition at line 50 of file proto_http.c.

Referenced by connection_fetch_from_buf_http(), and connection_read_https_proxy_response().

◆ peek_buf_has_http_command()

int peek_buf_has_http_command ( const buf_t *  buf)

Return true if cmd looks like a HTTP (proxy) request.

Definition at line 19 of file proto_http.c.