| 1 | #ifndef AWS_HTTP_STRUTIL_H |
| 2 | #define AWS_HTTP_STRUTIL_H |
| 3 | |
| 4 | /** |
| 5 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 6 | * SPDX-License-Identifier: Apache-2.0. |
| 7 | */ |
| 8 | #include <aws/http/http.h> |
| 9 | |
| 10 | AWS_EXTERN_C_BEGIN |
| 11 | |
| 12 | /** |
| 13 | * Return a cursor with all leading and trailing SPACE and TAB characters removed. |
| 14 | * RFC7230 section 3.2.3 Whitespace |
| 15 | * Examples: |
| 16 | * " \t a \t " -> "a" |
| 17 | * "a \t a" -> "a \t a" |
| 18 | */ |
| 19 | AWS_HTTP_API |
| 20 | struct aws_byte_cursor aws_strutil_trim_http_whitespace(struct aws_byte_cursor cursor); |
| 21 | |
| 22 | /** |
| 23 | * Return whether this is a valid token, as defined by RFC7230 section 3.2.6: |
| 24 | * token = 1*tchar |
| 25 | * tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" |
| 26 | * / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" |
| 27 | * / DIGIT / ALPHA |
| 28 | */ |
| 29 | AWS_HTTP_API |
| 30 | bool aws_strutil_is_http_token(struct aws_byte_cursor token); |
| 31 | |
| 32 | /** |
| 33 | * Same as aws_strutil_is_http_token(), but uppercase letters are forbidden. |
| 34 | */ |
| 35 | AWS_HTTP_API |
| 36 | bool aws_strutil_is_lowercase_http_token(struct aws_byte_cursor token); |
| 37 | |
| 38 | /** |
| 39 | * Return whether this ASCII/UTF-8 sequence is a valid HTTP header field-value. |
| 40 | * |
| 41 | * As defined in RFC7230 section 3.2 (except we are ALWAYS forbidding obs-fold): |
| 42 | * |
| 43 | * field-value = *( field-content / obs-fold ) |
| 44 | * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] |
| 45 | * field-vchar = VCHAR / obs-text |
| 46 | * VCHAR = %x21-7E ; visible (printing) characters |
| 47 | * obs-text = %x80-FF |
| 48 | * |
| 49 | * Note that we ALWAYS forbid obs-fold. Section 3.2.4 explains how |
| 50 | * obs-fold is deprecated "except within the message/http media type". |
| 51 | */ |
| 52 | AWS_HTTP_API |
| 53 | bool aws_strutil_is_http_field_value(struct aws_byte_cursor cursor); |
| 54 | |
| 55 | /** |
| 56 | * Return whether this ASCII/UTF-8 sequence is a valid HTTP response status reason-phrase. |
| 57 | * |
| 58 | * As defined in RFC7230 section 3.1.2: |
| 59 | * |
| 60 | * reason-phrase = *( HTAB / SP / VCHAR / obs-text ) |
| 61 | * VCHAR = %x21-7E ; visible (printing) characters |
| 62 | * obs-text = %x80-FF |
| 63 | */ |
| 64 | AWS_HTTP_API |
| 65 | bool aws_strutil_is_http_reason_phrase(struct aws_byte_cursor cursor); |
| 66 | |
| 67 | /** |
| 68 | * Return whether this ASCII/UTF-8 sequence is a valid HTTP request-target. |
| 69 | * |
| 70 | * TODO: Actually check the complete grammar as defined in RFC7230 5.3 and |
| 71 | * RFC3986. Currently this just checks whether the sequence is blatantly illegal |
| 72 | * (ex: contains CR or LF) |
| 73 | */ |
| 74 | AWS_HTTP_API |
| 75 | bool aws_strutil_is_http_request_target(struct aws_byte_cursor cursor); |
| 76 | |
| 77 | /** |
| 78 | * Return whether this ASCII/UTF-8 sequence start with ":" or not as the requirement for pseudo headers. |
| 79 | */ |
| 80 | AWS_HTTP_API |
| 81 | bool aws_strutil_is_http_pseudo_header_name(struct aws_byte_cursor cursor); |
| 82 | |
| 83 | AWS_EXTERN_C_END |
| 84 | #endif /* AWS_HTTP_STRUTIL_H */ |