File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -39,4 +39,10 @@ public final class Serializer {
39
39
part. headers [ " Content-Disposition " ] = contentDisposition
40
40
try multipart. serialize ( part)
41
41
}
42
+
43
+ /// Generates a Content-Type header value from a boundary
44
+ public static func generateContentType( boundary: BytesConvertible ) throws -> Bytes {
45
+ let b = try boundary. makeBytes ( )
46
+ return " multipart/form-data; boundary= " . bytes + b
47
+ }
42
48
}
Original file line number Diff line number Diff line change 1
1
import Core
2
2
import HTTP
3
+ import Foundation
3
4
4
5
/**
5
6
Parses preamble, Parts, and epilogue from a Multipart
@@ -72,6 +73,15 @@ public final class Parser {
72
73
buffer = [ ]
73
74
}
74
75
76
+ /// Extracts the boundary from a multipart Content-Type header
77
+ public static func extractBoundary( contentType: BytesConvertible ) throws -> Bytes {
78
+ let boundaryPieces = try contentType. makeBytes ( ) . string. components ( separatedBy: " boundary= " )
79
+ guard boundaryPieces. count == 2 else {
80
+ throw Error . invalidBoundary
81
+ }
82
+ return boundaryPieces [ 1 ] . bytes
83
+ }
84
+
75
85
/// Create a new multipart parser from a
76
86
/// Content-Type header value.
77
87
public convenience init ( contentType: BytesConvertible ) throws {
@@ -227,15 +237,6 @@ public final class Parser {
227
237
}
228
238
}
229
239
230
- /// Extracts the boundary from a multipart Content-Type header
231
- public static func extractBoundary( contentType: BytesConvertible ) throws -> Bytes {
232
- let boundaryPieces = try contentType. makeBytes ( ) . string. components ( separatedBy: " boundary= " )
233
- guard boundaryPieces. count == 2 else {
234
- throw Error . invalidBoundary
235
- }
236
- return boundaryPieces [ 1 ] . bytes
237
- }
238
-
239
240
// Private flag for tracking whether `finish()`
240
241
// has been called.
241
242
private var hasFinished = false
You can’t perform that action at this time.
0 commit comments