hummingbird-project / hummingbird Goto Github PK
View Code? Open in Web Editor NEWLightweight, flexible HTTP server framework written in Swift
License: Apache License 2.0
Lightweight, flexible HTTP server framework written in Swift
License: Apache License 2.0
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.
Think I'm still logging at too high a level
Currently arrays are formatted as follows
value[]=1&value[]=2
Add possibility of parsing arrays in form
value[0]=1&value[1]=2
/user:id and not /user/123
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
Means users don't need to worry about it.
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.
Hi,
The app I'm dealing with is trying to use HTTPS but it's not clear how to enable this in Hummingbird. Any pointers?
Currently there's no way to access the channel's ByteBufferAllocator
through the application instance.
It'd be really nice to have a property on HBAppication
, to return the shared allocator.
Thanks,
Tib.
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.
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(...)
.
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.
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:
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?
It would be useful to be able to print the entire request/response for debugging
Sometimes it includes a leading "/", sometimes it doesn't
Firefox complains when it is not set on a http connection
If request body is small the body is automatically created as a ByteBuffer and currently will crash in HBRequestBody.stream
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.
HBApplication.HTTPResponder
references HBApplication
which references HBApplication.HTTPResponder
via server channel handlers
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?
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:
In this call tree "0" refers to the following line:
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.
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
This would remove the sync point with the counter atomic.
Look into using https://github.com/swift-extras/swift-extras-uuid
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.