Giter Club home page Giter Club logo

hummingbird's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hummingbird's Issues

HBParameters doesn't handle repeating query parameters.

Just came across some API calls here with repeating query parameters. Things like ...?category=cars&category=engines (a bit contrived but still possible). I looked in the code for HBParameters and it's coded like I would have done it in that it's baed on a dictionary. But with this new information it needs to be able to handle repeating keys with different values. So I'm thinking more like an array of tuples or some simple struct type.

How do I add async responses

Hi, I'm trying to use HummingBird in a project and I want to add a asynchronous response to a path. ie. To generate the HBResponse I need to execute something asynchronously first. But my problem is that

server.router.on(path, method: .GET) { request -> EVentLoopFuture<HBResponseGenerator> in
    let promise = eventLoop.makePromise(of: NetworkResponse.self)

    // Do some magic here....

    return promise.futureResult
}

returns a HBREsponseGenerator which has a synchronous function when I need to call something with a signature like func doAsyncThing(completion: (HBResponse) -> Void). I can't use await/aync because I'm working with iOS12 as a base so I'm trying to figure out how to run async code to generate a HBResponse.

Can you give me an example of how to do this

Catch anything as a path component

Seems like the wildcard support works quite different as I was expecting.

e.g.

router.get("*") { req in
    return req.uri.description
}

GET /foo => ok
GET /foo/bar => 404

or

router.get("*/*/*") { req in
    return req.uri.description
}

GET /foo/bar/baz => ok
GET /foo/bar => 404

This behavior is just fine, but is there a way to catch more path components using a dynamic approach? This could be useful for frontend frameworks, for dynamic routes & SEO support this is a must have feature.

In Vapor we have ** for this purpose. See this link.

Currently if I don't set parameters for a given route, the app Crashes with the following error:

Hummingbird/Extensions.swift:111: Fatal error: Cannot access HBRequest.parameters on a route not extracting parameters from the URI.
2023-03-17 14:38:23.077213+0100 Server[15185:10028744] Hummingbird/Extensions.swift:111: Fatal error: Cannot access HBRequest.parameters on a route not extracting parameters from the URI.

What if we change this behavior and always return the parameters as an array of strings, separated by a / character? This could also allow a catch all pattern somehow...

I'm just throwing in some ideas, but catching path components could be really useful.
If somethings similar already exists in the project, please let me know. Thank you.

Hummingbird dependency swift-service-lifecycle won't compile on iOS

Trying to add Hummingbird to a project but I'm getting errors compiling swift-service-lifecycle. It appears that classes in there use Task which is iOS13 and above, whilst Hummingbird's package indicates it's minimum version as iOS12 and regardless of the iOS version I set on the project, it won't compile.

Any idea how to fix this?

See comment below for more info from a package project I was trying to use. Have since also tried in a single screen iOS app and got the same compilation error.

0.16.2, compilation error - HBLogRequestsMiddleware 32: Argument HBURL does not conform to expected type 'Sendable'

Hi, I just updated to 0.16.2 and I'm getting a compilation error on lines 32 & 38 of HBLogRequestsMiddleware where it's attempting to log request.uri:

if self.includeHeaders {
    request.logger.log(
        level: self.logLevel,
        "\(request.headers)",
        metadata: ["hb_uri": .stringConvertible(request.uri), "hb_method": .string(request.method.rawValue)] <-- Error!
    )
} else {
    request.logger.log(
        level: self.logLevel,
        "",
        metadata: ["hb_uri": .stringConvertible(request.uri), "hb_method": .string(request.method.rawValue)] <-- Error!
    )
}

Not sure why this is coming up now as it hasn't changed for some time and neither has the code in .stringConvertable(...).

Plus (+) symbol in URL query strings.

Hi

Just been looking at the use of the "+" symbol to represent a space in URLs. There's a lot of long winded discussions on the topic around the inter webs but I got the impression that its value as a representative of a space in a URL's query arguments. So something like this:

https://127.0.0.1/8080/abc?a1=Hello+World

As opposed to percent encoding:

https://127.0.0.1/8080/abc?a1=Hello%20World

I'm playing around with this and either I've done something wrong or Hummingbird doesn't appear to handle '+' space characters. I'm looking at URL.swift's extension to HBParameters on line 155 where it says

return (key: key.string[...], value: value.percentDecode().map { $0[...] } ?? value.string[...])

I'm wondering if this should also handle the '+' symbol. like this:

return (key: key.string[...], value: value. replacingOccurrences(of:"+", with: "%20").percentDecode().map { $0[...] } ?? value.string[...])

Just a guess.

Failing to start on Mac due to in-use port fails to return

Not sure if I'm right about this. I have a Mac command line target that's starting a Hummingbird server.

What appears to be happening is that if the port I ask it to start on is already taken, Hummingbird fail and hangs at this point:

Screen Shot 2022-07-20 at 10 35 03 pm

This doesn't seem to occur when running the same startup code on an iOS simulator, just when running via a Mac command.

Any clues how I might resolve this?

Endpoint path incorrect for router group index routes

When using a router group in combination with index routes, the endpoint path for those requests incorrectly (IMO) has a trailing slash:

let group = router.group("/users")
group.get(use: list)

func list(request: HBRequest) {
  // here I'd expect request.endpointPath to be "/users", but it is "/users/"
}

This might be a regression from #164.

Handling incoming request with stream body

Hi, I've setup my server to look at the request.body as a ByteBuffer to get the contents of the incoming request. However I'm receiving an unexpected request from the app (not under my control) that is returning a stream instead of a byte buffer. I'm trying to figure out how to read this stream and have been digging through the Hummingbird code base to try and figure it out but not having much luck so far.

For byte buffers I've been doing

let buffer = request.body.buffer
let data = buffer.getData(at: 0, length: buffer.readableBytes)

But this crashes when the body is set to a stream.

Any ides how to read the data?

`HBRequest.endpointPath` not set while applying middleware

Within the context of middleware, the request's endpointPath property will always be nil. This is due to the endpointPath being set by the TrieRouter after all middleware was applied, as shown in the following call tree:

image

In this call tree "0" refers to the following line:

request.endpointPath = result.value.path

I also checked the built-in HBMetricsMiddleware and it resulted in the same lack of an endpointPath while it was being applied. For Distributed Tracing support however the endpoint path is more or less required since it should be used as the span name.

Feature: Associate a unique ID with each request

Vapor keeps a unique ID for each request which, although not publicly exposed yet, allows us to track logs related to a specific request. I think that this kind of information could also be useful for logs originating from a handled Hummingbird Request.

Related: vapor/vapor#2964

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.