Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Fixes #21
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Borchert committed Sep 29, 2020
1 parent 3ae4214 commit 4dc75c3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
6 changes: 4 additions & 2 deletions Sources/Squid/Core/Request/HttpRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ extension HttpRequest {

// 2) Modify request to carry all required data
do {
let secure = request.usesSecureProtocol ?? service.usesSecureProtocol
httpRequest = try httpRequest
.with(scheme: request.usesSecureProtocol ? "https" : "http")
.with(scheme: secure ? "https" : "http")
.with(method: request.method)
.with(route: request.routes)
.with(query: request.query)
Expand Down Expand Up @@ -144,8 +145,9 @@ extension HttpRequest {

// 2) Modify request to carry all required data
do {
let secure = request.usesSecureProtocol ?? service.usesSecureProtocol
httpRequest = try httpRequest
.with(scheme: request.usesSecureProtocol ? "wss" : "ws")
.with(scheme: secure ? "wss" : "ws")
.with(method: .get)
.with(route: request.routes)
.with(query: request.query)
Expand Down
9 changes: 5 additions & 4 deletions Sources/Squid/Request/NetworkRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public protocol NetworkRequest {

// MARK: Protocol
/// Whether the request makes use of the secure counterpart of the protocol (e.g. "https" for
/// HTTP requests, "wss" for WebSockets).
var usesSecureProtocol: Bool { get }
/// HTTP requests, "wss" for WebSockets). If this option is set, it overrides the option set on
/// the service it is scheduled against.
var usesSecureProtocol: Bool? { get }

// MARK: URL Manipulation
/// The routing paths of the request.
Expand All @@ -40,8 +41,8 @@ extension NetworkRequest {

/// By default, this is set to `true`. Think twice before setting this to `false` and allowing
/// insecure network requests.
public var usesSecureProtocol: Bool {
return true
public var usesSecureProtocol: Bool? {
return nil
}

/// By default, no routing paths are used.
Expand Down
9 changes: 9 additions & 0 deletions Sources/Squid/Service/HttpService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public protocol HttpService {
/// contain the scheme (e.g. "https://") as it might get overwritten unexpectedly by a request.
var apiUrl: UrlConvertible { get }

/// Whether requests scheduled against this service use secure protocols (e.g. "https" for HTTP
/// requests, "wss" for WebSockets).
var usesSecureProtocol: Bool { get }

/// A header that ought to be used by all requests issued against the API represented by this
/// HTTP service. Most commonly, this header contains fields such as the API key or some form
/// of Authorization. Request headers always overwrite header fields set by the HTTP service
Expand Down Expand Up @@ -62,6 +66,11 @@ public protocol HttpService {

extension HttpService {

/// By default, requests are secured.
public var usesSecureProtocol: Bool {
return true
}

/// By default, the HTTP service does not set any headers.
public var header: HttpHeader {
return [:]
Expand Down
4 changes: 3 additions & 1 deletion Squid.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1130;
LastUpgradeCheck = 1130;
LastUpgradeCheck = 1200;
ORGANIZATIONNAME = "Oliver Borchert";
TargetAttributes = {
C911D3C123E7C2560065CD7D = {
Expand Down Expand Up @@ -708,6 +708,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -771,6 +772,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down
2 changes: 1 addition & 1 deletion Squid.xcodeproj/xcshareddata/xcschemes/Squid.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down

0 comments on commit 4dc75c3

Please sign in to comment.