Giter VIP home page Giter VIP logo

aero'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  avatar  avatar  avatar  avatar  avatar  avatar

aero's Issues

static path match error

Hi, I'm wondering if the static path match (tree.go#L29-L37 and tree.go#L121-L128) is wrong?

Here is the code snippet:

package main

import "github.com/aerogo/aero"

func main() {
	app := aero.New()
	app.Get("/:a/b/c", func(c aero.Context) error {
		return c.String("param a")
	})
	app.Get("/a/b/c", func(c aero.Context) error {
		return c.String("const a")
	})
	app.Run()
}

And request result:

http :4000/a/b/c
HTTP/1.1 200 OK
Content-Length: 7
Content-Type: text/plain; charset=utf-8
Date: Fri, 14 Aug 2020 11:24:04 GMT

const a

gzip encoding forced even if request doesn't accept such encodings

It looks as though when gzip is enabled in the configuration options, gzip is enabled blindly for all responses without properly checking the Accept-Encoding http headers.

Since there are many applications and utilities which do not fully implement the most common compression algorithms, I strongly urge adding in a check that only compresses when the client can accept it. If other compression algorithms are used by this library, I would recommend checking those too. I do not use this library myself, so I do not have first hand experience with what aero supports.

For example, curl by default doesn't do compression, and will only decompress gzip content when the compressed flag is specified (at least on my system.)

$ curl -q -v localhost
* Rebuilt URL to: localhost:80/
*   Trying ::1...
* Connected to localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> Host: example.com
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Cache-Control: must-revalidate
< Content-Encoding: gzip
< Content-Length: 3885
< Content-Type: text/html; charset=utf-8
< Etag: 665b19f6de0a7de
< Referrer-Policy: no-referrer
< X-Content-Type-Options: nosniff
< X-Xss-Protection: 1; mode=block
< Date: Tue, 30 Jan 2018 13:27:01 GMT
< 
��      n����;ے�6��������HQ�Vw[R���Ɠ��I��N*�2�G"� @��ԲJ����_��+I]�v��}�NE������Hϟ�ۏ����OߢRUt1׿�b����E�y	�X��Q���(��l
                                    �E�����3�~�B-9%|>�@�
�F
  Wp��	lj.T�r��0u�mH�����$��t��"�TM���S��%��F���;�H���3
�[�Q�V�2��V���_J@�&
                   �x�/Q�E�g������.
�Y����
<8ZW
[...]

Using the --compressed curl flag:

[core] [~]# curl -v --compressed localhost
* Rebuilt URL to: localhost:80/
*   Trying ::1...
* Connected to localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> Host: example.com
> User-Agent: curl/7.47.0
> Accept: */*
> Accept-Encoding: deflate, gzip
> 
< HTTP/1.1 200 OK
< Cache-Control: must-revalidate
< Content-Encoding: gzip
< Content-Length: 3885
< Content-Type: text/html; charset=utf-8
< Etag: 665b19f6de0a7de
< Referrer-Policy: no-referrer
< X-Content-Type-Options: nosniff
< X-Xss-Protection: 1; mode=block
< Date: Tue, 30 Jan 2018 13:30:51 GMT
< 
<!DOCTYPE html><html lang='en'><head><title>
[...]

An example of gunzip'ing the output, when curl isn't told it should be requesting compression..

[core] [~]# curl -v localhost | gunzip       
* Rebuilt URL to: localhost:80/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying ::1...
* Connected to localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> Host: example.com
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Cache-Control: must-revalidate
< Content-Encoding: gzip
< Content-Length: 3885
< Content-Type: text/html; charset=utf-8
< Etag: 665b19f6de0a7de
< Referrer-Policy: no-referrer
< X-Content-Type-Options: nosniff
< X-Xss-Protection: 1; mode=block
< Date: Tue, 30 Jan 2018 13:31:57 GMT
< 
{ [3885 bytes data]
100  3885  100  3885    0     0  4857k      0 --:--:-- --:--:-- --:--:-- 3793k
* Connection #0 to host localhost left intact
<!DOCTYPE html><html lang='en'><head><title>
[...]

At this time, it's unlikely servers running aero will properly work with legacy/older/more basic clients.

HTTP methods supported?

Are only GET and POST methods supported by this framework?

I have used gorilla/mux for routing before and I end up with code like this:

r.HandleFunc("/api/accounts", AddAccount).Methods("POST")
r.HandleFunc("/api/accounts", GetAccounts).Methods("GET")
r.HandleFunc("/api/accounts/{key}", UpdateAccount).Methods("POST")
r.HandleFunc("/api/accounts/{key}", DeleteAccount).Methods("DELETE")

At least DELETE seems very useful in any REST like api.

Option for Host IP configuration

Aero provides an option to set Port but there is no configuration setting for Host IP. Please provide an option for setting Host IP.

Fallback router not work properly with router within params

Code:

package main

import "github.com/aerogo/aero"

func echo(ctx aero.Context) error { return ctx.String("echo") }
func echoWithParams(ctx aero.Context) error { return ctx.String(ctx.Get("str")) }
func notFound(ctx aero.Context) error { return ctx.Error(404) }

func main() {
    app := aero.New()
    app.Config.Ports = aero.PortConfiguration{
        HTTP: 9000,
        HTTPS: 9001,
    }
    app.Any("/echo", echo)
    app.Any("/echo/", echo)
    app.Any("/echo/:str", echoWithParams)
    app.Any("/echo/:str/", echoWithParams)
    app.Any("/*",notFound)
    app.Any("/*/",notFound)
    app.Run()
}

What I expect:

Any other path not configure will return Not Found

What actually happens:

  • GET /echo
curl -v localhost:9000/echo
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> GET /echo HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 03 Jun 2021 04:41:13 GMT
< Content-Length: 4
< Content-Type: text/plain; charset=utf-8
<
echo* Connection #0 to host localhost left intact
  • GET /e (also /ec /ech)
curl -v localhost:9000/e
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> GET /e HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Thu, 03 Jun 2021 04:40:39 GMT
< Content-Length: 0
<
* Connection #0 to host localhost left intact
  • GET /e/ (also /ec/ /ech/)
curl -v localhost:9000/e/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> GET /x HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Thu, 03 Jun 2021 04:45:39 GMT
< Content-Length: 9
< Content-Type: text/plain; charset=utf-8
<
Not Found* Connection #0 to host localhost left intact
  • GET /x (also others)
curl -v localhost:9000/x/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> GET /x HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Thu, 03 Jun 2021 04:45:39 GMT
< Content-Length: 9
< Content-Type: text/plain; charset=utf-8
<
Not Found* Connection #0 to host localhost left intact

I don't know if is configure not properly or bug

but when I remove the params router it works again

package main

import "github.com/aerogo/aero"

func echo(ctx aero.Context) error { return ctx.String("echo") }
- func echoWithParams(ctx aero.Context) error { return ctx.String(ctx.Get("str")) }
func notFound(ctx aero.Context) error { return ctx.Error(404) }

func main() {
    app := aero.New()
    app.Config.Ports = aero.PortConfiguration{
        HTTP: 9000,
        HTTPS: 9001,
    }
    app.Any("/echo", echo)
    app.Any("/echo/", echo)
-   app.Any("/echo/:str", echoWithParams)
-   app.Any("/echo/:str/", echoWithParams)
    app.Any("/*",notFound)
    app.Any("/*/",notFound)
    app.Run()
}

...and when get /e

curl -v localhost:9000/e
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> GET /e HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Thu, 03 Jun 2021 04:52:37 GMT
< Content-Length: 9
< Content-Type: text/plain; charset=utf-8
<
Not Found* Connection #0 to host localhost left intact

Static routes with trailing slash

Trailing slash stopped working for static routes.
The fix is super simple, just adding the trailing slash route in tree.go.
I haven't had the time to do it yet but this should hopefully be working again, soon.

http.Server.Serve: "protocol not available" (OpenBSD 6.5)

I have problem running the test on OpenBSD 6.5.

$ uname -a
OpenBSD nuc.lounge.se 6.5 GENERIC.MP#3 amd64
$ go version
go version go1.12.1 openbsd/amd64

This is probably related to something in OpenBSD. I have a very similar issue with another web framework. Could ephemeral port ranges have something to do with it?

$ doas ./aerotest                                                                                                        
Server running on: http://localhost:4000
--------------------------------------------------------------------------------
panic: set tcp 127.0.0.1:4000->127.0.0.1:38930: protocol not available

goroutine 21 [running]:
github.com/aerogo/aero.(*Application).serveHTTP(0xc000102000, 0xc0000a0d88)
	/home/peter/go/pkg/mod/github.com/aerogo/[email protected]/Application.go:418 +0x29f
created by github.com/aerogo/aero.(*Application).ListenAndServe
	/home/peter/go/pkg/mod/github.com/aerogo/[email protected]/Application.go:197 +0xe3

But maybe you have seen something similar on another platform?

I tried a simple example using http on the same machine and that works fine.

package main

import (
	"fmt"
	"log"
	"net/http"
)

type helloHandler struct{}

func (h helloHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "hello, you've hit %s\n", r.URL.Path)
}

func main() {
	err := http.ListenAndServe(":9999", helloHandler{})
	log.Fatal(err)
}

Any idea what this could be related to?

Proposal: Alternative handler signature

I'd like to know what people's thoughts are on changing the aero.Handle signature from returning a string to returning an error object.

Since most people are calling ctx.HTML before returning the http body we can adjust ctx.HTML to return an error object alongside the other content types and people would have no troubles adopting the new signature. A search and replace would do the job.

The advantage is that the error return type feels more like idiomatic Go code whereas the string type forces us to do things like return "" on not-in-memory responses like ctx.File or ctx.EventStream. return nil feels a little cleaner.

Thoughts?

Unable to see the official docs

I wanted to see the docs on the go packages website, it has more info, but I found this

Screenshot from 2022-08-03 16-15-46
aparrently is due to something about lack of license.
Screenshot from 2022-08-03 16-17-06

Aero for Crystal Language

Crystal Language http://crystal-lang.org/ is faster, better and simpler than Go. The only missing thing is parallelism which the core team is working on. I would request you to take a look and If possible develop Aero in Crystal Language.

OnError hook is not working.

I am returning an error from my route handler like this

return errors.New("Request interrupted by the client")

and I have registered a callback like this

app.OnError(func(ctx aero.Context, err error) {
		fmt.Printf("An Error occured.")
	         ctx.String(err.Error())
	})

but If I visit the route, The connection is closed without sending error message and no error message is printed in the console. It seems OnError callback is not working. Am I missing something?

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.