@@ -648,74 +648,6 @@ public final class RegistryClient: Cancellable {
648
648
}
649
649
}
650
650
651
- public func getPublishRequirements(
652
- registryURL: URL ,
653
- timeout: DispatchTimeInterval ? = . none,
654
- observabilityScope: ObservabilityScope ,
655
- callbackQueue: DispatchQueue ,
656
- completion: @escaping ( Result < PublishRequirements , Error > ) -> Void
657
- ) {
658
- let completion = self . makeAsync ( completion, on: callbackQueue)
659
-
660
- guard var components = URLComponents ( url: registryURL, resolvingAgainstBaseURL: true ) else {
661
- return completion ( . failure( RegistryError . invalidURL ( registryURL) ) )
662
- }
663
- components. appendPathComponents ( " publish-requirements " )
664
- guard let url = components. url else {
665
- return completion ( . failure( RegistryError . invalidURL ( registryURL) ) )
666
- }
667
-
668
- let request = LegacyHTTPClient . Request (
669
- method: . get,
670
- url: url,
671
- headers: [
672
- " Accept " : self . acceptHeader ( mediaType: . json) ,
673
- ] ,
674
- options: self . defaultRequestOptions ( timeout: timeout, callbackQueue: callbackQueue)
675
- )
676
-
677
- self . httpClient. execute ( request, observabilityScope: observabilityScope, progress: nil ) { result in
678
- completion (
679
- result. tryMap { response in
680
- switch response. statusCode {
681
- case 200 :
682
- let publishRequirements = try response. parseJSON (
683
- Serialization . PublishRequirements. self,
684
- decoder: self . jsonDecoder
685
- )
686
-
687
- return PublishRequirements (
688
- metadata: . init(
689
- location: publishRequirements. metadata. location. map {
690
- switch $0 {
691
- case . archive:
692
- return . archive
693
- case . request:
694
- return . request
695
- }
696
- }
697
- ) ,
698
- signing: . init(
699
- required: publishRequirements. signing. required,
700
- acceptedSignatureFormats: publishRequirements. signing. acceptedSignatureFormats. map {
701
- switch $0 {
702
- case . CMS_1_0_0:
703
- return . CMS_1_0_0
704
- }
705
- } ,
706
- trustedRootCertificates: publishRequirements. signing. trustedRootCertificates
707
- )
708
- )
709
- default :
710
- throw self . unexpectedStatusError ( response, expectedStatus: [ 200 ] )
711
- }
712
- } . mapError {
713
- RegistryError . failedRetrievingRegistryPublishRequirements ( $0)
714
- }
715
- )
716
- }
717
- }
718
-
719
651
public func publish(
720
652
registryURL: URL ,
721
653
packageIdentity: PackageIdentity ,
@@ -759,43 +691,46 @@ public final class RegistryClient: Cancellable {
759
691
}
760
692
761
693
// TODO: add generic support for upload requests in Basics
762
- var body = Data ( )
763
694
let boundary = UUID ( ) . uuidString
695
+ var parts = [ String] ( )
764
696
765
697
// archive field
766
- body. append ( contentsOf: """
767
- -- \( boundary)
698
+ parts. append ( """
768
699
Content-Disposition: form-data; name= \" source-archive \" \r
769
700
Content-Type: application/zip \r
770
701
Content-Transfer-Encoding: base64 \r
771
702
Content-Length: \( packageArchiveContent. count) \r
772
703
\r
773
- \( packageArchiveContent. base64EncodedString ( ) )
774
- """ . utf8 )
704
+ \( packageArchiveContent. base64EncodedString ( ) ) \r
705
+ """ )
775
706
776
707
if let metadataContent = metadataContent {
777
- // spacer
778
- body. append ( contentsOf: " \r \n " . utf8)
779
- // metadata fiels
780
- body. append ( contentsOf: """
781
- -- \( boundary) \r
708
+ parts. append ( """
782
709
Content-Disposition: form-data; name= \" metadata \" \r
783
710
Content-Type: application/json \r
784
711
Content-Transfer-Encoding: quoted-printable \r
785
712
Content-Length: \( metadataContent. count) \r
786
713
\r
787
- \( metadataContent)
788
- """ . utf8 )
714
+ \( metadataContent) \r
715
+ """ )
789
716
}
790
717
718
+ let bodyString = """
719
+ -- \( boundary) \r
720
+ \( parts. joined ( separator: " \n -- \( boundary) \r \n " ) )
721
+ -- \( boundary) -- \r \n
722
+ """
723
+
791
724
let request = LegacyHTTPClient . Request (
792
725
method: . put,
793
726
url: url,
794
727
headers: [
728
+ " Content-Type " : " multipart/form-data;boundary= \" \( boundary) \" " ,
795
729
" Accept " : self . acceptHeader ( mediaType: . json) ,
730
+ " Expect " : " 100-continue " ,
796
731
" Prefer " : " respond-async " ,
797
732
] ,
798
- body: body ,
733
+ body: Data ( bodyString . utf8 ) ,
799
734
options: self . defaultRequestOptions ( timeout: timeout, callbackQueue: callbackQueue)
800
735
)
801
736
@@ -1017,33 +952,12 @@ extension RegistryClient {
1017
952
}
1018
953
}
1019
954
1020
- extension RegistryClient {
1021
- public enum SignatureFormat {
1022
- case CMS_1_0_0
1023
- }
1024
- }
1025
-
1026
- extension RegistryClient {
1027
- public struct PublishRequirements {
1028
- public let metadata : Metadata
1029
- public let signing : Signing
1030
-
1031
- public struct Metadata {
1032
- public let location : [ MetadataLocation ]
1033
- }
1034
-
1035
- public enum MetadataLocation {
1036
- case request
1037
- case archive
1038
- }
1039
-
1040
- public struct Signing {
1041
- public let required : Bool
1042
- public let acceptedSignatureFormats : [ SignatureFormat ]
1043
- public let trustedRootCertificates : [ String ]
1044
- }
1045
- }
1046
- }
955
+ /*
956
+ extension RegistryClient {
957
+ public enum SignatureFormat {
958
+ case CMS_1_0_0
959
+ }
960
+ }*/
1047
961
1048
962
extension RegistryClient {
1049
963
public enum PublishResult : Equatable {
0 commit comments