Skip to content

Commit

Permalink
Create Data using String.utf8 instead of NSString.data(using:)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pushkar N Kulkarni committed Feb 5, 2019
1 parent fe5db77 commit a3d35df
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions Sources/KituraNet/ClientRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ public class ClientRequest {
///
/// - Parameter from: The String to be added
public func write(from string: String) {
if let data = string.data(using: .utf8) {
write(from: data)
}
write(from: Data(string.utf8))
}

/// Add the bytes in a Data struct to the body of the request to be sent
Expand Down Expand Up @@ -480,11 +478,9 @@ public class ClientRequest {
}
}

private func createHTTPBasicAuthHeader(username: String, password: String) -> String? {
private func createHTTPBasicAuthHeader(username: String, password: String) -> String {
let authHeader = "\(username):\(password)"
guard let data = authHeader.data(using: String.Encoding.utf8) else {
return nil
}
let data = Data(authHeader.utf8)
return "Basic \(data.base64EncodedString())"
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/KituraNet/FastCGI/FastCGIServerRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class FastCGIServerRequest: ServerRequest {
/// The URL from the request in UTF-8 form
/// This contains just the path and query parameters starting with '/'
/// Use 'urlURL' for the full URL
public var url: Data { return requestUri?.data(using: .utf8) ?? Data() }
public var url: Data { return Data(urlURL.absoluteString.utf8) }

/// The URL from the request as URLComponents
/// URLComponents has a memory leak on linux as of swift 3.0.1. Use 'urlURL' instead
Expand Down
2 changes: 1 addition & 1 deletion Sources/KituraNet/HTTP/HTTPServerRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class HTTPServerRequest: ServerRequest {
/// Use 'urlURL' for the full URL
public var url: Data {
//The url needs to retain the percent encodings. URL.path doesn't, so we do this.
return _urlString.data(using: .utf8) ?? Data()
return Data(_urlString.utf8)
}

@available(*, deprecated, message: "URLComponents has a memory leak on linux as of swift 3.0.1. use 'urlURL' instead")
Expand Down

0 comments on commit a3d35df

Please sign in to comment.