-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
109 additions
and
79 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// PCHTTPFilterPlugin.swift | ||
// Pjango-Dev | ||
// | ||
// Created by 郑宇琦 on 2017/6/26. | ||
// | ||
// | ||
|
||
import Foundation | ||
import PerfectHTTP | ||
|
||
open class PCHTTPFilterPlugin: PCPlugin, HTTPRequestFilter, HTTPResponseFilter { | ||
|
||
open var priority: HTTPFilterPriority { | ||
return .low | ||
} | ||
|
||
open func requestFilter(req: HTTPRequest, res: HTTPResponse) -> Bool { return true } | ||
|
||
open func responseFilterHeader(req: HTTPRequest, res: HTTPResponse) -> Bool { return true } | ||
|
||
open func responseFilterBody(req: HTTPRequest, res: HTTPResponse) -> Bool { return true } | ||
|
||
public func filter(request: HTTPRequest, response: HTTPResponse, callback: (HTTPRequestFilterResult) -> ()) { | ||
if requestFilter(req: request, res: response) { | ||
callback(.continue(request, response)) | ||
} else { | ||
callback(.halt(request, response)) | ||
} | ||
} | ||
|
||
public func filterHeaders(response: HTTPResponse, callback: (HTTPResponseFilterResult) -> ()) { | ||
if responseFilterHeader(req: response.request, res: response) { | ||
callback(.continue) | ||
} else { | ||
callback(.done) | ||
} | ||
} | ||
|
||
public func filterBody(response: HTTPResponse, callback: (HTTPResponseFilterResult) -> ()) { | ||
if responseFilterBody(req: response.request, res: response) { | ||
callback(.continue) | ||
} else { | ||
callback(.done) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// PCLogFilterPlugin.swift | ||
// Pjango-Project | ||
// | ||
// Created by 郑宇琦 on 2017/6/21. | ||
// | ||
// | ||
|
||
import Foundation | ||
import PerfectHTTP | ||
|
||
open class PCLogFilterPlugin: PCHTTPFilterPlugin { | ||
|
||
open override func requestFilter(req: HTTPRequest, res: HTTPResponse) -> Bool { | ||
let url = req.getFullUrl() | ||
let method = req.method | ||
let host = req.serverAddress.host | ||
let port = req.serverAddress.port | ||
_pjango_core_log.info("Req: [\(method)][\(host)][\(port)]: \(url)") | ||
return true | ||
} | ||
|
||
open override func responseFilterHeader(req: HTTPRequest, res: HTTPResponse) -> Bool { | ||
let code = res.status.code | ||
let url = req.getFullUrl() | ||
let method = req.method | ||
let host = req.serverAddress.host | ||
let port = req.serverAddress.port | ||
_pjango_core_log.info("Res: [\(code)][\(method)][\(host)][\(port)]: \(url)") | ||
return true | ||
} | ||
|
||
|
||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.