File: h1_decoder.h

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (90 lines) | stat: -rw-r--r-- 3,430 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef AWS_HTTP_H1_DECODER_H
#define AWS_HTTP_H1_DECODER_H

/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/http/private/http_impl.h>
#include <aws/http/private/request_response_impl.h>

struct aws_h1_decoded_header {
    /* Name of the header. If the type is `AWS_HTTP_HEADER_NAME_UNKNOWN` then `name_data` must be parsed manually. */
    enum aws_http_header_name name;

    /* Raw buffer storing the header's name. */
    struct aws_byte_cursor name_data;

    /* Raw buffer storing the header's value. */
    struct aws_byte_cursor value_data;

    /* Raw buffer storing the entire header. */
    struct aws_byte_cursor data;
};

struct aws_h1_decoder_vtable {
    /**
     * Called from `aws_h*_decode` when an http header has been received.
     * All pointers are strictly *read only*; any data that needs to persist must be copied out into user-owned memory.
     */
    int (*on_header)(const struct aws_h1_decoded_header *header, void *user_data);

    /**
     * Called from `aws_h1_decode` when a portion of the http body has been received.
     * `finished` is true if this is the last section of the http body, and false if more body data is yet to be
     * received. All pointers are strictly *read only*; any data that needs to persist must be copied out into
     * user-owned memory.
     */
    int (*on_body)(const struct aws_byte_cursor *data, bool finished, void *user_data);

    /* Only needed for requests, can be NULL for responses. */
    int (*on_request)(
        enum aws_http_method method_enum,
        const struct aws_byte_cursor *method_str,
        const struct aws_byte_cursor *uri,
        void *user_data);

    /* Only needed for responses, can be NULL for requests. */
    int (*on_response)(int status_code, void *user_data);

    int (*on_done)(void *user_data);
};

/**
 * Structure used to initialize an `aws_h1_decoder`.
 */
struct aws_h1_decoder_params {
    struct aws_allocator *alloc;
    size_t scratch_space_initial_size;
    /* Set false if decoding responses */
    bool is_decoding_requests;
    void *user_data;
    struct aws_h1_decoder_vtable vtable;
};

struct aws_h1_decoder;

AWS_EXTERN_C_BEGIN

AWS_HTTP_API struct aws_h1_decoder *aws_h1_decoder_new(struct aws_h1_decoder_params *params);
AWS_HTTP_API void aws_h1_decoder_destroy(struct aws_h1_decoder *decoder);
AWS_HTTP_API int aws_h1_decode(struct aws_h1_decoder *decoder, struct aws_byte_cursor *data);

AWS_HTTP_API void aws_h1_decoder_set_logging_id(struct aws_h1_decoder *decoder, const void *id);
AWS_HTTP_API void aws_h1_decoder_set_body_headers_ignored(struct aws_h1_decoder *decoder, bool body_headers_ignored);

/* RFC-7230 section 4.2 Message Format */
#define AWS_HTTP_TRANSFER_ENCODING_CHUNKED (1 << 0)
#define AWS_HTTP_TRANSFER_ENCODING_GZIP (1 << 1)
#define AWS_HTTP_TRANSFER_ENCODING_DEFLATE (1 << 2)
#define AWS_HTTP_TRANSFER_ENCODING_DEPRECATED_COMPRESS (1 << 3)
AWS_HTTP_API int aws_h1_decoder_get_encoding_flags(const struct aws_h1_decoder *decoder);

AWS_HTTP_API uint64_t aws_h1_decoder_get_content_length(const struct aws_h1_decoder *decoder);
AWS_HTTP_API bool aws_h1_decoder_get_body_headers_ignored(const struct aws_h1_decoder *decoder);
AWS_HTTP_API enum aws_http_header_block aws_h1_decoder_get_header_block(const struct aws_h1_decoder *decoder);

AWS_EXTERN_C_END

#endif /* AWS_HTTP_H1_DECODER_H */