         }
         return nil
     }
-    
+
+    private enum ParseState {
+        case preamble, body
+    }
+
     ///
     /// Multipart form data parse function
     ///

            switch(state) {
            case .preamble where bodyLine.hasPrefix(boundaryData), .body where bodyLine.hasPrefix(boundaryData):
                // boundary found
                if partData.length > 0 {
                    if let parser = getParsingFunction(contentType: currentPart.type), let parsedBody = parser(partData) {
                        currentPart.body = parsedBody
                    } else {
                        currentPart.body = .raw(partData)
                    }
                    parts.append(currentPart)
                }
                currentPart = Part()
                partData = NSMutableData()
                if bodyLine.hasPrefix(endBoundaryData) {
                    // end boundary found, end of parsing
                    return .multipart(parts)
                }
                state = .body
            case .preamble:
                // discard preamble text
                break

            Log.error("Error converting strings to data for multipart parsing")
            return nil
        }

        var state = ParseState.preamble
        var parts: [Part] = []
        var currentPart = Part()
