File: strutil.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 (84 lines) | stat: -rw-r--r-- 2,653 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
#ifndef AWS_HTTP_STRUTIL_H
#define AWS_HTTP_STRUTIL_H

/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */
#include <aws/http/http.h>

AWS_EXTERN_C_BEGIN

/**
 * Return a cursor with all leading and trailing SPACE and TAB characters removed.
 * RFC7230 section 3.2.3 Whitespace
 * Examples:
 * " \t a \t  " -> "a"
 * "a \t a" -> "a \t a"
 */
AWS_HTTP_API
struct aws_byte_cursor aws_strutil_trim_http_whitespace(struct aws_byte_cursor cursor);

/**
 * Return whether this is a valid token, as defined by RFC7230 section 3.2.6:
 *  token          = 1*tchar
 *  tchar          = "!" / "#" / "$" / "%" / "&" / "'" / "*"
 *                 / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
 *                 / DIGIT / ALPHA
 */
AWS_HTTP_API
bool aws_strutil_is_http_token(struct aws_byte_cursor token);

/**
 * Same as aws_strutil_is_http_token(), but uppercase letters are forbidden.
 */
AWS_HTTP_API
bool aws_strutil_is_lowercase_http_token(struct aws_byte_cursor token);

/**
 * Return whether this ASCII/UTF-8 sequence is a valid HTTP header field-value.
 *
 * As defined in RFC7230 section 3.2 (except we are ALWAYS forbidding obs-fold):
 *
 * field-value    = *( field-content / obs-fold )
 * field-content  = field-vchar [ 1*( SP / HTAB ) field-vchar ]
 * field-vchar    = VCHAR / obs-text
 * VCHAR          = %x21-7E ; visible (printing) characters
 * obs-text       = %x80-FF
 *
 * Note that we ALWAYS forbid obs-fold. Section 3.2.4 explains how
 * obs-fold is deprecated "except within the message/http media type".
 */
AWS_HTTP_API
bool aws_strutil_is_http_field_value(struct aws_byte_cursor cursor);

/**
 * Return whether this ASCII/UTF-8 sequence is a valid HTTP response status reason-phrase.
 *
 * As defined in RFC7230 section 3.1.2:
 *
 * reason-phrase  = *( HTAB / SP / VCHAR / obs-text )
 * VCHAR          = %x21-7E ; visible (printing) characters
 * obs-text       = %x80-FF
 */
AWS_HTTP_API
bool aws_strutil_is_http_reason_phrase(struct aws_byte_cursor cursor);

/**
 * Return whether this ASCII/UTF-8 sequence is a valid HTTP request-target.
 *
 * TODO: Actually check the complete grammar as defined in RFC7230 5.3 and
 * RFC3986. Currently this just checks whether the sequence is blatantly illegal
 * (ex: contains CR or LF)
 */
AWS_HTTP_API
bool aws_strutil_is_http_request_target(struct aws_byte_cursor cursor);

/**
 * Return whether this ASCII/UTF-8 sequence start with ":" or not as the requirement for pseudo headers.
 */
AWS_HTTP_API
bool aws_strutil_is_http_pseudo_header_name(struct aws_byte_cursor cursor);

AWS_EXTERN_C_END
#endif /* AWS_HTTP_STRUTIL_H */