| ... | ... | @@ -524,11 +524,110 @@ pub const Request = struct { |
| 524 | 524 | req.* = undefined; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | pub const Reader = std.io.Reader(*Request, ReadError, read); |
| 528 | |
| 529 | pub fn reader(req: *Request) Reader { |
| 530 | return .{ .context = req }; |
| 531 | } |
| 532 | |
| 527 | 533 | pub fn readAll(req: *Request, buffer: []u8) !usize { |
| 528 | 534 | return readAtLeast(req, buffer, buffer.len); |
| 529 | 535 | } |
| 530 | 536 | |
| 531 | | pub fn read(req: *Request, buffer: []u8) !usize { |
| 537 | pub const ReadError = net.Stream.ReadError || error{ |
| 538 | // From HTTP protocol |
| 539 | HttpHeadersInvalid, |
| 540 | HttpHeadersExceededSizeLimit, |
| 541 | HttpRedirectMissingLocation, |
| 542 | HttpTransferEncodingUnsupported, |
| 543 | HttpContentLengthUnknown, |
| 544 | TooManyHttpRedirects, |
| 545 | ShortHttpStatusLine, |
| 546 | BadHttpVersion, |
| 547 | HttpHeaderContinuationsUnsupported, |
| 548 | UnsupportedUrlScheme, |
| 549 | UriMissingHost, |
| 550 | UnknownHostName, |
| 551 | |
| 552 | // Network problems |
| 553 | NetworkUnreachable, |
| 554 | HostLacksNetworkAddresses, |
| 555 | TemporaryNameServerFailure, |
| 556 | NameServerFailure, |
| 557 | ProtocolFamilyNotAvailable, |
| 558 | ProtocolNotSupported, |
| 559 | |
| 560 | // System resource problems |
| 561 | ProcessFdQuotaExceeded, |
| 562 | SystemFdQuotaExceeded, |
| 563 | OutOfMemory, |
| 564 | |
| 565 | // TLS problems |
| 566 | InsufficientEntropy, |
| 567 | TlsConnectionTruncated, |
| 568 | TlsRecordOverflow, |
| 569 | TlsDecodeError, |
| 570 | TlsAlert, |
| 571 | TlsBadRecordMac, |
| 572 | TlsBadLength, |
| 573 | TlsIllegalParameter, |
| 574 | TlsUnexpectedMessage, |
| 575 | TlsDecryptFailure, |
| 576 | CertificateFieldHasInvalidLength, |
| 577 | CertificateHostMismatch, |
| 578 | CertificatePublicKeyInvalid, |
| 579 | CertificateExpired, |
| 580 | CertificateFieldHasWrongDataType, |
| 581 | CertificateIssuerMismatch, |
| 582 | CertificateNotYetValid, |
| 583 | CertificateSignatureAlgorithmMismatch, |
| 584 | CertificateSignatureAlgorithmUnsupported, |
| 585 | CertificateSignatureInvalid, |
| 586 | CertificateSignatureInvalidLength, |
| 587 | CertificateSignatureNamedCurveUnsupported, |
| 588 | CertificateSignatureUnsupportedBitCount, |
| 589 | TlsCertificateNotVerified, |
| 590 | TlsBadSignatureScheme, |
| 591 | TlsBadRsaSignatureBitCount, |
| 592 | TlsDecryptError, |
| 593 | UnsupportedCertificateVersion, |
| 594 | CertificateTimeInvalid, |
| 595 | CertificateHasUnrecognizedObjectId, |
| 596 | CertificateHasInvalidBitString, |
| 597 | |
| 598 | // TODO: convert to higher level errors |
| 599 | InvalidFormat, |
| 600 | InvalidPort, |
| 601 | UnexpectedCharacter, |
| 602 | Overflow, |
| 603 | InvalidCharacter, |
| 604 | AddressFamilyNotSupported, |
| 605 | AddressInUse, |
| 606 | AddressNotAvailable, |
| 607 | ConnectionPending, |
| 608 | ConnectionRefused, |
| 609 | FileNotFound, |
| 610 | PermissionDenied, |
| 611 | ServiceUnavailable, |
| 612 | SocketTypeNotSupported, |
| 613 | FileTooBig, |
| 614 | LockViolation, |
| 615 | NoSpaceLeft, |
| 616 | NotOpenForWriting, |
| 617 | InvalidEncoding, |
| 618 | IdentityElement, |
| 619 | NonCanonical, |
| 620 | SignatureVerificationFailed, |
| 621 | MessageTooLong, |
| 622 | NegativeIntoUnsigned, |
| 623 | TargetTooSmall, |
| 624 | BufferTooSmall, |
| 625 | InvalidSignature, |
| 626 | NotSquare, |
| 627 | DiskQuota, |
| 628 | }; |
| 629 | |
| 630 | pub fn read(req: *Request, buffer: []u8) ReadError!usize { |
| 532 | 631 | return readAtLeast(req, buffer, 1); |
| 533 | 632 | } |
| 534 | 633 | |
| ... | ... | @@ -709,11 +808,15 @@ pub const Request = struct { |
| 709 | 808 | } |
| 710 | 809 | }; |
| 711 | 810 | |
| 712 | | pub fn deinit(client: *Client, gpa: Allocator) void { |
| 713 | | client.ca_bundle.deinit(gpa); |
| 811 | pub fn deinit(client: *Client) void { |
| 812 | client.ca_bundle.deinit(client.allocator); |
| 714 | 813 | client.* = undefined; |
| 715 | 814 | } |
| 716 | 815 | |
| 816 | pub fn rescanRootCertificates(client: *Client) !void { |
| 817 | return client.ca_bundle.rescan(client.allocator); |
| 818 | } |
| 819 | |
| 717 | 820 | pub fn connect(client: *Client, host: []const u8, port: u16, protocol: Connection.Protocol) !Connection { |
| 718 | 821 | var conn: Connection = .{ |
| 719 | 822 | .stream = try net.tcpConnectToHost(client.allocator, host, port), |