Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging and debugging and make Kitura available for iOS #1522

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

DanielMandea
Copy link

@DanielMandea DanielMandea commented Sep 23, 2020

Description

Added support for accessing serverRequest under RouterRequest in order to improve logging capabilities and debugging. Also added Kitura Nio as the main underlying layer for networking.

Motivation and Context

Kitura Nio is mandatory while running on iOS
While improving logging as part of our internal RouterMiddleware that is specialised for logging we were forced at some point to do the following (request.serverRequest as? HTTPServerRequest)?.buffer?.rewind() which was impossible due to internal access for serverRequest

How Has This Been Tested?

The change consists in making a constant public instead of keeping it internal.

Checklist:

  • If applicable, I have updated the documentation accordingly.
  • If applicable, I have added tests to cover my changes.

@DanielMandea DanielMandea changed the title Improve logging and debugging Improve logging and debugging and make Kitura available for iOS Sep 23, 2020
Copy link

@futurejones futurejones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Substituting official packages https://github.com/IBM-Swift/Kitura-NIO.git with your own personal version https://github.com/DanielMandea/Kitura-NIO.git is not acceptable.
    If you want changes made to Kitura-NIO you need to submit a PR to the Kitura-NIO repo and have it approved there. https://github.com/Kitura/Kitura-NIO

  2. Removing https://github.com/IBM-Swift/Kitura-net.git and forcing everybody to use Kitura-NIO is not a good idea.
    If there is an issue caused by defaulting to Kitura-Net then maybe the default can be changed to Kitura-NIO but leaving the option to use Kitura-Net.

@mbarnach
Copy link
Member

I think you can have the logging behaviour with the ServerDelegate.

A pseudo-code like that could work:

class RequestLogger: ServerDelegate {
    let router: Router
    init(_ router: Router) {
        self.router = router
    }
    func handle(request: ServerRequest, response: ServerResponse) {
        Log.debug("[\(request.remoteAddress)] \(request.method) HTTP \(request.httpVersionMajor ?? 1).\(request.httpVersionMinor ?? 1) \(request.urlURL)")
        router.handle(request: request, response: response)
    }
}

And then wrap your router:

Kitura.addHTTPServer(onPort: 8080, with: RequestLogger(router))

This doesn't solve the NIO issue, but hopefully the log issue.

@CLAassistant
Copy link

CLAassistant commented Sep 27, 2020

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ DanielMandea
❌ danielmandeaibm
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants