address zig changes in awshttp. zig 15a030ef3 or newer needed
There are two recent changes in zig that effect awshttp. 1. cf65ab8 disallows unused variables. Fair enough and backward compatible. 2. https://github.com/ziglang/zig/issues/2115#issuecomment-827968279 This comment resulted in a backward incompatible change to use the underlying value from a C enum rather than its symbol. This reduces edge cases in the compiler. Ultimately we may want awshttp to define zig enums that mirror the C enums, but for now I've commented the definitions of the C enums used.
This commit is contained in:
parent
de41b456d3
commit
dcfefa4072
|
@ -45,7 +45,6 @@ pub const Aws = struct {
|
||||||
const meta_info = request.metaInfo();
|
const meta_info = request.metaInfo();
|
||||||
const service = meta_info.service;
|
const service = meta_info.service;
|
||||||
const action = meta_info.action;
|
const action = meta_info.action;
|
||||||
const R = Response(request);
|
|
||||||
|
|
||||||
log.debug("call: prefix {s}, sigv4 {s}, version {s}, action {s}", .{
|
log.debug("call: prefix {s}, sigv4 {s}, version {s}, action {s}", .{
|
||||||
service.endpoint_prefix,
|
service.endpoint_prefix,
|
||||||
|
|
|
@ -103,7 +103,7 @@ const EndPoint = struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn cInit(allocator: *std.mem.Allocator) void {
|
fn cInit(_: *std.mem.Allocator) void {
|
||||||
// TODO: what happens if we actually get an allocator?
|
// TODO: what happens if we actually get an allocator?
|
||||||
httplog.debug("auth init", .{});
|
httplog.debug("auth init", .{});
|
||||||
c_allocator = c.aws_default_allocator();
|
c_allocator = c.aws_default_allocator();
|
||||||
|
@ -121,7 +121,7 @@ fn cInit(allocator: *std.mem.Allocator) void {
|
||||||
// .level = .AWS_LL_INFO,
|
// .level = .AWS_LL_INFO,
|
||||||
// .level = .AWS_LL_DEBUG,
|
// .level = .AWS_LL_DEBUG,
|
||||||
// .level = .AWS_LL_TRACE,
|
// .level = .AWS_LL_TRACE,
|
||||||
.level = .AWS_LL_FATAL,
|
.level = 1, //.AWS_LL_FATAL, // https://github.com/awslabs/aws-c-common/blob/057746b2e094f4b7a31743d8ba5a9fd0155f69f3/include/aws/common/logging.h#L33
|
||||||
.file = c.get_std_err(),
|
.file = c.get_std_err(),
|
||||||
.filename = null,
|
.filename = null,
|
||||||
};
|
};
|
||||||
|
@ -143,7 +143,7 @@ fn cDeinit() void { // probably the wrong name
|
||||||
c.aws_tls_ctx_release(ctx);
|
c.aws_tls_ctx_release(ctx);
|
||||||
httplog.debug("tls_ctx deinit end", .{});
|
httplog.debug("tls_ctx deinit end", .{});
|
||||||
}
|
}
|
||||||
if (tls_ctx_options) |opts| {
|
if (tls_ctx_options != null) {
|
||||||
// See:
|
// See:
|
||||||
// https://github.com/awslabs/aws-c-io/blob/6c7bae503961545c5e99c6c836c4b37749cfc4ad/source/tls_channel_handler.c#L25
|
// https://github.com/awslabs/aws-c-io/blob/6c7bae503961545c5e99c6c836c4b37749cfc4ad/source/tls_channel_handler.c#L25
|
||||||
//
|
//
|
||||||
|
@ -311,10 +311,13 @@ pub const AwsHttp = struct {
|
||||||
// tls_connection_options = try self.setupTls(host);
|
// tls_connection_options = try self.setupTls(host);
|
||||||
if (tls_ctx_options == null) {
|
if (tls_ctx_options == null) {
|
||||||
httplog.debug("Setting up tls options", .{});
|
httplog.debug("Setting up tls options", .{});
|
||||||
|
// Language change - translate_c no longer translates c enums
|
||||||
|
// to zig enums as there were too many edge cases:
|
||||||
|
// https://github.com/ziglang/zig/issues/2115#issuecomment-827968279
|
||||||
var opts: c.aws_tls_ctx_options = .{
|
var opts: c.aws_tls_ctx_options = .{
|
||||||
.allocator = c_allocator,
|
.allocator = c_allocator,
|
||||||
.minimum_tls_version = @intToEnum(c.aws_tls_versions, c.AWS_IO_TLS_VER_SYS_DEFAULTS),
|
.minimum_tls_version = 128, // @intToEnum(c.aws_tls_versions, c.AWS_IO_TLS_VER_SYS_DEFAULTS), // https://github.com/awslabs/aws-c-io/blob/6c7bae503961545c5e99c6c836c4b37749cfc4ad/include/aws/io/tls_channel_handler.h#L21
|
||||||
.cipher_pref = @intToEnum(c.aws_tls_cipher_pref, c.AWS_IO_TLS_CIPHER_PREF_SYSTEM_DEFAULT),
|
.cipher_pref = 0, // @intToEnum(c.aws_tls_cipher_pref, c.AWS_IO_TLS_CIPHER_PREF_SYSTEM_DEFAULT), // https://github.com/awslabs/aws-c-io/blob/6c7bae503961545c5e99c6c836c4b37749cfc4ad/include/aws/io/tls_channel_handler.h#L25
|
||||||
.ca_file = c.aws_byte_buf_from_c_str(""),
|
.ca_file = c.aws_byte_buf_from_c_str(""),
|
||||||
.ca_path = c.aws_string_new_from_c_str(c_allocator, ""),
|
.ca_path = c.aws_string_new_from_c_str(c_allocator, ""),
|
||||||
.alpn_list = null,
|
.alpn_list = null,
|
||||||
|
@ -361,8 +364,8 @@ pub const AwsHttp = struct {
|
||||||
}
|
}
|
||||||
if (signing_options) |opts| try self.signRequest(http_request.?, opts);
|
if (signing_options) |opts| try self.signRequest(http_request.?, opts);
|
||||||
const socket_options = c.aws_socket_options{
|
const socket_options = c.aws_socket_options{
|
||||||
.type = @intToEnum(c.aws_socket_type, c.AWS_SOCKET_STREAM),
|
.type = 0, // @intToEnum(c.aws_socket_type, c.AWS_SOCKET_STREAM), // https://github.com/awslabs/aws-c-io/blob/6c7bae503961545c5e99c6c836c4b37749cfc4ad/include/aws/io/socket.h#L24
|
||||||
.domain = @intToEnum(c.aws_socket_domain, c.AWS_SOCKET_IPV4),
|
.domain = 0, // @intToEnum(c.aws_socket_domain, c.AWS_SOCKET_IPV4), // https://github.com/awslabs/aws-c-io/blob/6c7bae503961545c5e99c6c836c4b37749cfc4ad/include/aws/io/socket.h#L12
|
||||||
.connect_timeout_ms = 3000, // TODO: change hardcoded 3s value
|
.connect_timeout_ms = 3000, // TODO: change hardcoded 3s value
|
||||||
.keep_alive_timeout_sec = 0,
|
.keep_alive_timeout_sec = 0,
|
||||||
.keepalive = false,
|
.keepalive = false,
|
||||||
|
@ -472,13 +475,13 @@ pub const AwsHttp = struct {
|
||||||
|
|
||||||
// TODO: Re-encapsulate or delete this function. It is not currently
|
// TODO: Re-encapsulate or delete this function. It is not currently
|
||||||
// used and will not be touched by the compiler
|
// used and will not be touched by the compiler
|
||||||
fn setupTls(self: Self, host: []const u8) !*c.aws_tls_connection_options {
|
fn setupTls(_: Self, host: []const u8) !*c.aws_tls_connection_options {
|
||||||
if (tls_ctx_options == null) {
|
if (tls_ctx_options == null) {
|
||||||
httplog.debug("Setting up tls options", .{});
|
httplog.debug("Setting up tls options", .{});
|
||||||
var opts: c.aws_tls_ctx_options = .{
|
var opts: c.aws_tls_ctx_options = .{
|
||||||
.allocator = c_allocator,
|
.allocator = c_allocator,
|
||||||
.minimum_tls_version = @intToEnum(c.aws_tls_versions, c.AWS_IO_TLS_VER_SYS_DEFAULTS),
|
.minimum_tls_version = 128, // @intToEnum(c.aws_tls_versions, c.AWS_IO_TLS_VER_SYS_DEFAULTS), // https://github.com/awslabs/aws-c-io/blob/6c7bae503961545c5e99c6c836c4b37749cfc4ad/include/aws/io/tls_channel_handler.h#L21
|
||||||
.cipher_pref = @intToEnum(c.aws_tls_cipher_pref, c.AWS_IO_TLS_CIPHER_PREF_SYSTEM_DEFAULT),
|
.cipher_pref = 0, // @intToEnum(c.aws_tls_cipher_pref, c.AWS_IO_TLS_CIPHER_PREF_SYSTEM_DEFAULT), // https://github.com/awslabs/aws-c-io/blob/6c7bae503961545c5e99c6c836c4b37749cfc4ad/include/aws/io/tls_channel_handler.h#L25
|
||||||
.ca_file = c.aws_byte_buf_from_c_str(""),
|
.ca_file = c.aws_byte_buf_from_c_str(""),
|
||||||
.ca_path = c.aws_string_new_from_c_str(c_allocator, ""),
|
.ca_path = c.aws_string_new_from_c_str(c_allocator, ""),
|
||||||
.alpn_list = null,
|
.alpn_list = null,
|
||||||
|
@ -553,9 +556,9 @@ pub const AwsHttp = struct {
|
||||||
const signing_service = try std.fmt.allocPrintZ(self.allocator, "{s}", .{options.service});
|
const signing_service = try std.fmt.allocPrintZ(self.allocator, "{s}", .{options.service});
|
||||||
defer self.allocator.free(signing_service);
|
defer self.allocator.free(signing_service);
|
||||||
const temp_signing_config = c.bitfield_workaround_aws_signing_config_aws{
|
const temp_signing_config = c.bitfield_workaround_aws_signing_config_aws{
|
||||||
.algorithm = .AWS_SIGNING_ALGORITHM_V4,
|
.algorithm = 0, // .AWS_SIGNING_ALGORITHM_V4, // https://github.com/awslabs/aws-c-auth/blob/ace1311f8ef6ea890b26dd376031bed2721648eb/include/aws/auth/signing_config.h#L38
|
||||||
.config_type = .AWS_SIGNING_CONFIG_AWS,
|
.config_type = 1, // .AWS_SIGNING_CONFIG_AWS, // https://github.com/awslabs/aws-c-auth/blob/ace1311f8ef6ea890b26dd376031bed2721648eb/include/aws/auth/signing_config.h#L24
|
||||||
.signature_type = .AWS_ST_HTTP_REQUEST_HEADERS,
|
.signature_type = 0, // .AWS_ST_HTTP_REQUEST_HEADERS, // https://github.com/awslabs/aws-c-auth/blob/ace1311f8ef6ea890b26dd376031bed2721648eb/include/aws/auth/signing_config.h#L49
|
||||||
.region = c.aws_byte_cursor_from_c_str(@ptrCast([*c]const u8, signing_region)),
|
.region = c.aws_byte_cursor_from_c_str(@ptrCast([*c]const u8, signing_region)),
|
||||||
.service = c.aws_byte_cursor_from_c_str(@ptrCast([*c]const u8, signing_service)),
|
.service = c.aws_byte_cursor_from_c_str(@ptrCast([*c]const u8, signing_service)),
|
||||||
.should_sign_header = null,
|
.should_sign_header = null,
|
||||||
|
@ -566,7 +569,7 @@ pub const AwsHttp = struct {
|
||||||
.omit_session_token = 1,
|
.omit_session_token = 1,
|
||||||
},
|
},
|
||||||
.signed_body_value = c.aws_byte_cursor_from_c_str(""),
|
.signed_body_value = c.aws_byte_cursor_from_c_str(""),
|
||||||
.signed_body_header = .AWS_SBHT_X_AMZ_CONTENT_SHA256, //or AWS_SBHT_NONE
|
.signed_body_header = 1, // .AWS_SBHT_X_AMZ_CONTENT_SHA256, //or 0 = AWS_SBHT_NONE // https://github.com/awslabs/aws-c-auth/blob/ace1311f8ef6ea890b26dd376031bed2721648eb/include/aws/auth/signing_config.h#L131
|
||||||
.credentials = creds,
|
.credentials = creds,
|
||||||
.credentials_provider = self.credentialsProvider,
|
.credentials_provider = self.credentialsProvider,
|
||||||
.expiration_in_seconds = 0,
|
.expiration_in_seconds = 0,
|
||||||
|
@ -601,7 +604,7 @@ pub const AwsHttp = struct {
|
||||||
async_result.count += 1;
|
async_result.count += 1;
|
||||||
async_result.result.error_code = error_code;
|
async_result.result.error_code = error_code;
|
||||||
|
|
||||||
if (result) |res| {
|
if (result != null) {
|
||||||
if (c.aws_apply_signing_result_to_http_request(http_request, c_allocator, result) != c.AWS_OP_SUCCESS) {
|
if (c.aws_apply_signing_result_to_http_request(http_request, c_allocator, result) != c.AWS_OP_SUCCESS) {
|
||||||
httplog.alert("Could not apply signing request to http request: {s}", .{c.aws_error_debug_str(c.aws_last_error())});
|
httplog.alert("Could not apply signing request to http request: {s}", .{c.aws_error_debug_str(c.aws_last_error())});
|
||||||
}
|
}
|
||||||
|
@ -616,7 +619,7 @@ pub const AwsHttp = struct {
|
||||||
const accept_header = c.aws_http_header{
|
const accept_header = c.aws_http_header{
|
||||||
.name = c.aws_byte_cursor_from_c_str("Accept"),
|
.name = c.aws_byte_cursor_from_c_str("Accept"),
|
||||||
.value = c.aws_byte_cursor_from_c_str("application/json"),
|
.value = c.aws_byte_cursor_from_c_str("application/json"),
|
||||||
.compression = .AWS_HTTP_HEADER_COMPRESSION_USE_CACHE,
|
.compression = 0, // .AWS_HTTP_HEADER_COMPRESSION_USE_CACHE, // https://github.com/awslabs/aws-c-http/blob/ec42882310900f2b414b279fc24636ba4653f285/include/aws/http/request_response.h#L37
|
||||||
};
|
};
|
||||||
if (c.aws_http_message_add_header(request, accept_header) != c.AWS_OP_SUCCESS)
|
if (c.aws_http_message_add_header(request, accept_header) != c.AWS_OP_SUCCESS)
|
||||||
return AwsError.AddHeaderError;
|
return AwsError.AddHeaderError;
|
||||||
|
@ -624,7 +627,7 @@ pub const AwsHttp = struct {
|
||||||
const host_header = c.aws_http_header{
|
const host_header = c.aws_http_header{
|
||||||
.name = c.aws_byte_cursor_from_c_str("Host"),
|
.name = c.aws_byte_cursor_from_c_str("Host"),
|
||||||
.value = c.aws_byte_cursor_from_c_str(@ptrCast([*c]const u8, host)),
|
.value = c.aws_byte_cursor_from_c_str(@ptrCast([*c]const u8, host)),
|
||||||
.compression = .AWS_HTTP_HEADER_COMPRESSION_USE_CACHE,
|
.compression = 0, // .AWS_HTTP_HEADER_COMPRESSION_USE_CACHE,
|
||||||
};
|
};
|
||||||
if (c.aws_http_message_add_header(request, host_header) != c.AWS_OP_SUCCESS)
|
if (c.aws_http_message_add_header(request, host_header) != c.AWS_OP_SUCCESS)
|
||||||
return AwsError.AddHeaderError;
|
return AwsError.AddHeaderError;
|
||||||
|
@ -632,7 +635,7 @@ pub const AwsHttp = struct {
|
||||||
const user_agent_header = c.aws_http_header{
|
const user_agent_header = c.aws_http_header{
|
||||||
.name = c.aws_byte_cursor_from_c_str("User-Agent"),
|
.name = c.aws_byte_cursor_from_c_str("User-Agent"),
|
||||||
.value = c.aws_byte_cursor_from_c_str("zig-aws 1.0, Powered by the AWS Common Runtime."),
|
.value = c.aws_byte_cursor_from_c_str("zig-aws 1.0, Powered by the AWS Common Runtime."),
|
||||||
.compression = .AWS_HTTP_HEADER_COMPRESSION_USE_CACHE,
|
.compression = 0, // .AWS_HTTP_HEADER_COMPRESSION_USE_CACHE,
|
||||||
};
|
};
|
||||||
if (c.aws_http_message_add_header(request, user_agent_header) != c.AWS_OP_SUCCESS)
|
if (c.aws_http_message_add_header(request, user_agent_header) != c.AWS_OP_SUCCESS)
|
||||||
return AwsError.AddHeaderError;
|
return AwsError.AddHeaderError;
|
||||||
|
@ -654,7 +657,7 @@ pub const AwsHttp = struct {
|
||||||
const content_type_header = c.aws_http_header{
|
const content_type_header = c.aws_http_header{
|
||||||
.name = c.aws_byte_cursor_from_c_str("Content-Type"),
|
.name = c.aws_byte_cursor_from_c_str("Content-Type"),
|
||||||
.value = c.aws_byte_cursor_from_c_str("application/x-www-form-urlencoded"),
|
.value = c.aws_byte_cursor_from_c_str("application/x-www-form-urlencoded"),
|
||||||
.compression = .AWS_HTTP_HEADER_COMPRESSION_USE_CACHE,
|
.compression = 0, // .AWS_HTTP_HEADER_COMPRESSION_USE_CACHE,
|
||||||
};
|
};
|
||||||
if (c.aws_http_message_add_header(request, content_type_header) != c.AWS_OP_SUCCESS)
|
if (c.aws_http_message_add_header(request, content_type_header) != c.AWS_OP_SUCCESS)
|
||||||
return AwsError.AddHeaderError;
|
return AwsError.AddHeaderError;
|
||||||
|
@ -666,7 +669,7 @@ pub const AwsHttp = struct {
|
||||||
const content_length_header = c.aws_http_header{
|
const content_length_header = c.aws_http_header{
|
||||||
.name = c.aws_byte_cursor_from_c_str("Content-Length"),
|
.name = c.aws_byte_cursor_from_c_str("Content-Length"),
|
||||||
.value = c.aws_byte_cursor_from_c_str(@ptrCast([*c]const u8, len)),
|
.value = c.aws_byte_cursor_from_c_str(@ptrCast([*c]const u8, len)),
|
||||||
.compression = .AWS_HTTP_HEADER_COMPRESSION_USE_CACHE,
|
.compression = 0, // .AWS_HTTP_HEADER_COMPRESSION_USE_CACHE,
|
||||||
};
|
};
|
||||||
if (c.aws_http_message_add_header(request, content_length_header) != c.AWS_OP_SUCCESS)
|
if (c.aws_http_message_add_header(request, content_length_header) != c.AWS_OP_SUCCESS)
|
||||||
return AwsError.AddHeaderError;
|
return AwsError.AddHeaderError;
|
||||||
|
@ -685,12 +688,13 @@ pub const AwsHttp = struct {
|
||||||
httplog.debug("connection setup callback end", .{});
|
httplog.debug("connection setup callback end", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connectionShutdownCallback(connection: ?*c.aws_http_connection, error_code: c_int, user_data: ?*c_void) callconv(.C) void {
|
fn connectionShutdownCallback(connection: ?*c.aws_http_connection, error_code: c_int, _: ?*c_void) callconv(.C) void {
|
||||||
httplog.debug("connection shutdown callback start", .{});
|
// ^^ error_code ^^ user_data
|
||||||
|
httplog.debug("connection shutdown callback start ({*}). error_code: {d}", .{ connection, error_code });
|
||||||
httplog.debug("connection shutdown callback end", .{});
|
httplog.debug("connection shutdown callback end", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn incomingHeadersCallback(stream: ?*c.aws_http_stream, header_block: c.aws_http_header_block, headers: [*c]const c.aws_http_header, num_headers: usize, user_data: ?*c_void) callconv(.C) c_int {
|
fn incomingHeadersCallback(stream: ?*c.aws_http_stream, _: c.aws_http_header_block, headers: [*c]const c.aws_http_header, num_headers: usize, user_data: ?*c_void) callconv(.C) c_int {
|
||||||
var context = userDataTo(RequestContext, user_data);
|
var context = userDataTo(RequestContext, user_data);
|
||||||
|
|
||||||
if (context.response_code == null) {
|
if (context.response_code == null) {
|
||||||
|
@ -712,7 +716,7 @@ pub const AwsHttp = struct {
|
||||||
}
|
}
|
||||||
return c.AWS_OP_SUCCESS;
|
return c.AWS_OP_SUCCESS;
|
||||||
}
|
}
|
||||||
fn incomingBodyCallback(stream: ?*c.aws_http_stream, data: [*c]const c.aws_byte_cursor, user_data: ?*c_void) callconv(.C) c_int {
|
fn incomingBodyCallback(_: ?*c.aws_http_stream, data: [*c]const c.aws_byte_cursor, user_data: ?*c_void) callconv(.C) c_int {
|
||||||
var context = userDataTo(RequestContext, user_data);
|
var context = userDataTo(RequestContext, user_data);
|
||||||
|
|
||||||
httplog.debug("inbound body, len {d}", .{data.*.len});
|
httplog.debug("inbound body, len {d}", .{data.*.len});
|
||||||
|
@ -723,7 +727,8 @@ pub const AwsHttp = struct {
|
||||||
httplog.alert("could not append to body!", .{});
|
httplog.alert("could not append to body!", .{});
|
||||||
return c.AWS_OP_SUCCESS;
|
return c.AWS_OP_SUCCESS;
|
||||||
}
|
}
|
||||||
fn requestCompleteCallback(stream: ?*c.aws_http_stream, error_code: c_int, user_data: ?*c_void) callconv(.C) void {
|
fn requestCompleteCallback(stream: ?*c.aws_http_stream, _: c_int, user_data: ?*c_void) callconv(.C) void {
|
||||||
|
// ^^ error_code
|
||||||
var context = userDataTo(RequestContext, user_data);
|
var context = userDataTo(RequestContext, user_data);
|
||||||
context.request_complete.store(true, .SeqCst);
|
context.request_complete.store(true, .SeqCst);
|
||||||
c.aws_http_stream_release(stream);
|
c.aws_http_stream_release(stream);
|
||||||
|
@ -735,8 +740,9 @@ pub const AwsHttp = struct {
|
||||||
var callback_results = AsyncResult(AwsAsyncCallbackResult(c.aws_credentials)){ .result = &credential_result };
|
var callback_results = AsyncResult(AwsAsyncCallbackResult(c.aws_credentials)){ .result = &credential_result };
|
||||||
|
|
||||||
const callback = awsAsyncCallbackResult(c.aws_credentials, "got credentials", assignCredentialsOnCallback);
|
const callback = awsAsyncCallbackResult(c.aws_credentials, "got credentials", assignCredentialsOnCallback);
|
||||||
const get_async_result =
|
// const get_async_result =
|
||||||
c.aws_credentials_provider_get_credentials(self.credentialsProvider, callback, &callback_results);
|
_ = c.aws_credentials_provider_get_credentials(self.credentialsProvider, callback, &callback_results);
|
||||||
|
// TODO: do we care about the return value from get_creds?
|
||||||
|
|
||||||
waitOnCallback(c.aws_credentials, &callback_results);
|
waitOnCallback(c.aws_credentials, &callback_results);
|
||||||
if (credential_result.error_code != c.AWS_ERROR_SUCCESS) {
|
if (credential_result.error_code != c.AWS_ERROR_SUCCESS) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
fn defaultTransformer(field_name: []const u8, options: EncodingOptions) anyerror![]const u8 {
|
fn defaultTransformer(field_name: []const u8, _: EncodingOptions) anyerror![]const u8 {
|
||||||
return field_name;
|
return field_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user