Add syntax highlighting to README C code

make-http-max-header-size-gyp-configurable
Uli Köhler 12 years ago committed by Ben Noordhuis
parent f5c779bb85
commit c4079e7c38

@ -36,7 +36,7 @@ Usage
One `http_parser` object is used per TCP connection. Initialize the struct One `http_parser` object is used per TCP connection. Initialize the struct
using `http_parser_init()` and set the callbacks. That might look something using `http_parser_init()` and set the callbacks. That might look something
like this for a request parser: like this for a request parser:
```c
http_parser_settings settings; http_parser_settings settings;
settings.on_url = my_url_callback; settings.on_url = my_url_callback;
settings.on_header_field = my_header_field_callback; settings.on_header_field = my_header_field_callback;
@ -45,9 +45,11 @@ like this for a request parser:
http_parser *parser = malloc(sizeof(http_parser)); http_parser *parser = malloc(sizeof(http_parser));
http_parser_init(parser, HTTP_REQUEST); http_parser_init(parser, HTTP_REQUEST);
parser->data = my_socket; parser->data = my_socket;
```
When data is received on the socket execute the parser and check for errors. When data is received on the socket execute the parser and check for errors.
```c
size_t len = 80*1024, nparsed; size_t len = 80*1024, nparsed;
char buf[len]; char buf[len];
ssize_t recved; ssize_t recved;
@ -68,6 +70,7 @@ When data is received on the socket execute the parser and check for errors.
} else if (nparsed != recved) { } else if (nparsed != recved) {
/* Handle error. Usually just close the connection. */ /* Handle error. Usually just close the connection. */
} }
```
HTTP needs to know where the end of the stream is. For example, sometimes HTTP needs to know where the end of the stream is. For example, sometimes
servers send responses without Content-Length and expect the client to servers send responses without Content-Length and expect the client to

Loading…
Cancel
Save