Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <zephyr/kernel.h>
#include <zephyr/net/net_ip.h>
#include <zephyr/net/http_parser.h>
#include <zephyr/net/http/parser.h>

#ifdef __cplusplus
extern "C" {
Expand Down
70 changes: 70 additions & 0 deletions include/zephyr/net/http/method.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/** @file
* @brief HTTP request methods
*/

/*
* Copyright (c) 2022 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_NET_HTTP_METHOD_H_
#define ZEPHYR_INCLUDE_NET_HTTP_METHOD_H_

/**
* @brief HTTP request methods
* @defgroup http_methods HTTP request methods
* @ingroup networking
* @{
*/

#ifdef __cplusplus
extern "C" {
#endif

/** @brief HTTP Request Methods */
enum http_method {
HTTP_DELETE = 0, /**< DELETE */
HTTP_GET = 1, /**< GET */
HTTP_HEAD = 2, /**< HEAD */
HTTP_POST = 3, /**< POST */
HTTP_PUT = 4, /**< PUT */
HTTP_CONNECT = 5, /**< CONNECT */
HTTP_OPTIONS = 6, /**< OPTIONS */
HTTP_TRACE = 7, /**< TRACE */
HTTP_COPY = 8, /**< COPY */
HTTP_LOCK = 9, /**< LOCK */
HTTP_MKCOL = 10, /**< MKCOL */
HTTP_MOVE = 11, /**< MOVE */
HTTP_PROPFIND = 12, /**< PROPFIND */
HTTP_PROPPATCH = 13, /**< PROPPATCH */
HTTP_SEARCH = 14, /**< SEARCH */
HTTP_UNLOCK = 15, /**< UNLOCK */
HTTP_BIND = 16, /**< BIND */
HTTP_REBIND = 17, /**< REBIND */
HTTP_UNBIND = 18, /**< UNBIND */
HTTP_ACL = 19, /**< ACL */
HTTP_REPORT = 20, /**< REPORT */
HTTP_MKACTIVITY = 21, /**< MKACTIVITY */
HTTP_CHECKOUT = 22, /**< CHECKOUT */
HTTP_MERGE = 23, /**< MERGE */
HTTP_MSEARCH = 24, /**< MSEARCH */
HTTP_NOTIFY = 25, /**< NOTIFY */
HTTP_SUBSCRIBE = 26, /**< SUBSCRIBE */
HTTP_UNSUBSCRIBE = 27, /**< UNSUBSCRIBE */
HTTP_PATCH = 28, /**< PATCH */
HTTP_PURGE = 29, /**< PURGE */
HTTP_MKCALENDAR = 30, /**< MKCALENDAR */
HTTP_LINK = 31, /**< LINK */
HTTP_UNLINK = 32, /**< UNLINK */
};

#ifdef __cplusplus
}
#endif

/**
* @}
*/

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ typedef unsigned __int64 uint64_t;
#include <zephyr/types.h>
#include <stddef.h>
#endif
#include <zephyr/net/http_parser_state.h>
#include <zephyr/net/http_parser_url.h>
#include <zephyr/net/http/method.h>
#include <zephyr/net/http/parser_state.h>
#include <zephyr/net/http/parser_url.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -89,42 +90,6 @@ typedef int (*http_data_cb)(struct http_parser *, const char *at,
size_t length);
typedef int (*http_cb)(struct http_parser *);

enum http_method {
HTTP_DELETE = 0,
HTTP_GET = 1,
HTTP_HEAD = 2,
HTTP_POST = 3,
HTTP_PUT = 4,
HTTP_CONNECT = 5,
HTTP_OPTIONS = 6,
HTTP_TRACE = 7,
HTTP_COPY = 8,
HTTP_LOCK = 9,
HTTP_MKCOL = 10,
HTTP_MOVE = 11,
HTTP_PROPFIND = 12,
HTTP_PROPPATCH = 13,
HTTP_SEARCH = 14,
HTTP_UNLOCK = 15,
HTTP_BIND = 16,
HTTP_REBIND = 17,
HTTP_UNBIND = 18,
HTTP_ACL = 19,
HTTP_REPORT = 20,
HTTP_MKACTIVITY = 21,
HTTP_CHECKOUT = 22,
HTTP_MERGE = 23,
HTTP_MSEARCH = 24,
HTTP_NOTIFY = 25,
HTTP_SUBSCRIBE = 26,
HTTP_UNSUBSCRIBE = 27,
HTTP_PATCH = 28,
HTTP_PURGE = 29,
HTTP_MKCALENDAR = 30,
HTTP_LINK = 31,
HTTP_UNLINK = 32
};

enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };

/* Flag values for http_parser.flags field */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <sys/types.h>
#include <zephyr/types.h>
#include <stddef.h>
#include <zephyr/net/http_parser_state.h>
#include <zephyr/net/http/parser_state.h>

#ifdef __cplusplus
extern "C" {
Expand Down
108 changes: 108 additions & 0 deletions include/zephyr/net/http/status.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/** @file
* @brief HTTP response status codes
*/

/*
* Copyright (c) 2022 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_NET_HTTP_STATUS_H_
#define ZEPHYR_INCLUDE_NET_HTTP_STATUS_H_

/**
* @brief HTTP response status codes
* @defgroup http_status_codes HTTP response status codes
* @ingroup networking
* @{
*/

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief HTTP response status codes
*
* @note HTTP response status codes are subject to IANA approval.
*
* @see <a href="https://www.iana.org/assignments/http-status-codes">Hypertext Transfer Protocol (HTTP) Status Code Registry</a>
* @see <a href="https://www.ietf.org/rfc/rfc9110.txt">RFC9110</a>
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status">HTTP response status codes</a>
*/
enum http_status {
HTTP_100_CONTINUE = 100, /**< Continue */
HTTP_101_SWITCHING_PROTOCOLS = 101, /**< Switching Protocols */
HTTP_102_PROCESSING = 102, /**< Processing */
HTTP_103_EARLY_HINTS = 103, /**< Early Hints */
HTTP_200_OK = 200, /**< OK */
HTTP_201_CREATED = 201, /**< Created */
HTTP_202_ACCEPTED = 202, /**< Accepted */
HTTP_203_NON_AUTHORITATIVE_INFORMATION = 203, /**< Non-Authoritative Information */
HTTP_204_NO_CONTENT = 204, /**< No Content */
HTTP_205_RESET_CONTENT = 205, /**< Reset Content */
HTTP_206_PARTIAL_CONTENT = 206, /**< Partial Content */
HTTP_207_MULTI_STATUS = 207, /**< Multi-Status */
HTTP_208_ALREADY_REPORTED = 208, /**< Already Reported */
HTTP_226_IM_USED = 226, /**< IM Used */
HTTP_300_MULTIPLE_CHOICES = 300, /**< Multiple Choices */
HTTP_301_MOVED_PERMANENTLY = 301, /**< Moved Permanently */
HTTP_302_FOUND = 302, /**< Found */
HTTP_303_SEE_OTHER = 303, /**< See Other */
HTTP_304_NOT_MODIFIED = 304, /**< Not Modified */
HTTP_305_USE_PROXY = 305, /**< Use Proxy */
HTTP_306_UNUSED = 306, /**< unused */
HTTP_307_TEMPORARY_REDIRECT = 307, /**< Temporary Redirect */
HTTP_308_PERMANENT_REDIRECT = 308, /**< Permanent Redirect */
HTTP_400_BAD_REQUEST = 400, /**< Bad Request */
HTTP_401_UNAUTHORIZED = 401, /**< Unauthorized */
HTTP_402_PAYMENT_REQUIRED = 402, /**< Payment Required */
HTTP_403_FORBIDDEN = 403, /**< Forbidden */
HTTP_404_NOT_FOUND = 404, /**< Not Found */
HTTP_405_METHOD_NOT_ALLOWED = 405, /**< Method Not Allowed */
HTTP_406_NOT_ACCEPTABLE = 406, /**< Not Acceptable */
HTTP_407_PROXY_AUTHENTICATION_REQUIRED = 407, /**< Proxy Authentication Required */
HTTP_408_REQUEST_TIMEOUT = 408, /**< Request Timeout */
HTTP_409_CONFLICT = 409, /**< Conflict */
HTTP_410_GONE = 410, /**< Gone */
HTTP_411_LENGTH_REQUIRED = 411, /**< Length Required */
HTTP_412_PRECONDITION_FAILED = 412, /**< Precondition Failed */
HTTP_413_PAYLOAD_TOO_LARGE = 413, /**< Payload Too Large */
HTTP_414_URI_TOO_LONG = 414, /**< URI Too Long */
HTTP_415_UNSUPPORTED_MEDIA_TYPE = 415, /**< Unsupported Media Type */
HTTP_416_RANGE_NOT_SATISFIABLE = 416, /**< Range Not Satisfiable */
HTTP_417_EXPECTATION_FAILED = 417, /**< Expectation Failed */
HTTP_418_IM_A_TEAPOT = 418, /**< I'm a teapot */
HTTP_421_MISDIRECTED_REQUEST = 421, /**< Misdirected Request */
HTTP_422_UNPROCESSABLE_ENTITY = 422, /**< Unprocessable Entity */
HTTP_423_LOCKED = 423, /**< Locked */
HTTP_424_FAILED_DEPENDENCY = 424, /**< Failed Dependency */
HTTP_425_TOO_EARLY = 425, /**< Too Early */
HTTP_426_UPGRADE_REQUIRED = 426, /**< Upgrade Required */
HTTP_428_PRECONDITION_REQUIRED = 428, /**< Precondition Required */
HTTP_429_TOO_MANY_REQUESTS = 429, /**< Too Many Requests */
HTTP_431_REQUEST_HEADER_FIELDS_TOO_LARGE = 431, /**< Request Header Fields Too Large */
HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS = 451, /**< Unavailable For Legal Reasons */
HTTP_500_INTERNAL_SERVER_ERROR = 500, /**< Internal Server Error */
HTTP_501_NOT_IMPLEMENTED = 501, /**< Not Implemented */
HTTP_502_BAD_GATEWAY = 502, /**< Bad Gateway */
HTTP_503_SERVICE_UNAVAILABLE = 503, /**< Service Unavailable */
HTTP_504_GATEWAY_TIMEOUT = 504, /**< Gateway Timeout */
HTTP_505_HTTP_VERSION_NOT_SUPPORTED = 505, /**< HTTP Version Not Supported */
HTTP_506_VARIANT_ALSO_NEGOTIATES = 506, /**< Variant Also Negotiates */
HTTP_507_INSUFFICIENT_STORAGE = 507, /**< Insufficient Storage */
HTTP_508_LOOP_DETECTED = 508, /**< Loop Detected */
HTTP_510_NOT_EXTENDED = 510, /**< Not Extended */
HTTP_511_NETWORK_AUTHENTICATION_REQUIRED = 511, /**< Network Authentication Required */
};

#ifdef __cplusplus
}
#endif

/**
* @}
*/

#endif
4 changes: 2 additions & 2 deletions include/zephyr/net/websocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <zephyr/kernel.h>

#include <zephyr/net/net_ip.h>
#include <zephyr/net/http_parser.h>
#include <zephyr/net/http_client.h>
#include <zephyr/net/http/parser.h>
#include <zephyr/net/http/client.h>

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion samples/net/cloud/tagoio_http_post/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LOG_MODULE_REGISTER(tagoio_http_post, CONFIG_TAGOIO_HTTP_POST_LOG_LEVEL);

#include <zephyr/kernel.h>
#include <zephyr/net/socket.h>
#include <zephyr/net/http_client.h>
#include <zephyr/net/http/client.h>
#include <zephyr/random/rand32.h>
#include <stdio.h>

Expand Down
2 changes: 1 addition & 1 deletion samples/net/cloud/tagoio_http_post/src/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LOG_MODULE_DECLARE(tagoio_http_post, CONFIG_TAGOIO_HTTP_POST_LOG_LEVEL);
#include <zephyr/net/socketutils.h>
#include <zephyr/net/dns_resolve.h>
#include <zephyr/net/tls_credentials.h>
#include <zephyr/net/http_client.h>
#include <zephyr/net/http/client.h>

#include "sockets.h"

Expand Down
2 changes: 1 addition & 1 deletion samples/net/sockets/http_client/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LOG_MODULE_REGISTER(net_http_client_sample, LOG_LEVEL_DBG);
#include <zephyr/net/net_ip.h>
#include <zephyr/net/socket.h>
#include <zephyr/net/tls_credentials.h>
#include <zephyr/net/http_client.h>
#include <zephyr/net/http/client.h>

#include "ca_certificate.h"

Expand Down
53 changes: 53 additions & 0 deletions scripts/net/enumerate_http_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3
# Copyright(c) 2022 Meta
# SPDX-License-Identifier: Apache-2.0

"""Format HTTP Status codes for use in a C header

This script extracts HTTP status codes from mozilla.org
and formats them to fit inside of a C enum along with
comments.

The output may appear somewhat redundant but it strives
to
a) be human readable
b) eliminate the need to look up status manually,
c) be machine parseable for table generation

The output is sorted for convenience.

Usage:
./scripts/net/enumerate_http_status.py
HTTP_100_CONTINUE = 100, /**< Continue */
...
HTTP_418_IM_A_TEAPOT = 418, /**< I'm a teapot */
...
HTTP_511_NETWORK_AUTHENTICATION_REQUIRED = 511, /**< Network Authentication Required */
"""

from lxml import html
import requests
import re

page = requests.get('https://developer.mozilla.org/en-US/docs/Web/HTTP/Status')
tree = html.fromstring(page.content)

codes = tree.xpath('//code/text()')

codes2 = {}
for c in codes:
if re.match('[0-9][0-9][0-9] [a-zA-Z].*', c):
key = int(c[0:3])
val = c[4:]
codes2[key] = val

keys = sorted(codes2.keys())
for key in keys:
val = codes2[key]
enum_head = 'HTTP'
enum_body = f'{key}'
enum_tail = val.upper().replace(' ', '_').replace("'", '').replace('-', '_')
enum_label = '_'.join([enum_head, enum_body, enum_tail])
comment = f'/**< {val} */'

print(f'{enum_label} = {key}, {comment}')
2 changes: 1 addition & 1 deletion subsys/mgmt/hawkbit/hawkbit.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(hawkbit, CONFIG_HAWKBIT_LOG_LEVEL);
#include <zephyr/net/net_mgmt.h>
#include <zephyr/sys/reboot.h>
#include <zephyr/drivers/flash.h>
#include <zephyr/net/http_client.h>
#include <zephyr/net/http/client.h>
#include <zephyr/net/dns_resolve.h>
#include <zephyr/logging/log_ctrl.h>
#include <zephyr/storage/flash_map.h>
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/http/http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ LOG_MODULE_REGISTER(net_http, CONFIG_NET_HTTP_LOG_LEVEL);

#include <zephyr/net/net_ip.h>
#include <zephyr/net/socket.h>
#include <zephyr/net/http_client.h>
#include <zephyr/net/http/client.h>

#include "net_private.h"

Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/http/http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <zephyr/net/http_parser.h>
#include <zephyr/net/http/parser.h>
#include <zephyr/sys/__assert.h>
#include <stddef.h>
#include <ctype.h>
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/http/http_parser_url.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <zephyr/net/http_parser_url.h>
#include <zephyr/net/http/parser_url.h>
#include <zephyr/toolchain.h>

#ifndef BIT_AT
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/lwm2m/lwm2m_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <string.h>

#include <zephyr/init.h>
#include <zephyr/net/http_parser_url.h>
#include <zephyr/net/http/parser_url.h>
#include <zephyr/net/lwm2m.h>
#include <zephyr/net/net_ip.h>
#include <zephyr/net/socket.h>
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/lwm2m/lwm2m_message_handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <string.h>

#include <zephyr/init.h>
#include <zephyr/net/http_parser_url.h>
#include <zephyr/net/http/parser_url.h>
#include <zephyr/net/lwm2m.h>
#include <zephyr/net/net_ip.h>
#include <zephyr/net/socket.h>
Expand Down
Loading