Giter VIP home page Giter VIP logo

rest's People

Contributors

doichev-kostia avatar paskal avatar rupeshhacker avatar ssgreg avatar umputun avatar zonescape avatar

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

Watchers

 avatar  avatar  avatar  avatar  avatar

rest's Issues

custom directory-listing mode for FileServer

With #18 in place, one of the new options allows directory listing. Unfortunately, the one from stdlib is as ugly as hell and not customizable at all. It would be very nice to add the ability to make this list somewhat custom. Ideally, it should support some template with {{.Name}} {{.Size}} {{.DateTime}} and so on.

I don't see a direct way to achieve it and can think of a couple of hacks:

  1. Define a custom response writer to intercept and replace the standard list of files. Very unclear how to even detect the list output, how to eliminate dbl/read, and so on
  2. Implement our own http.File / http.Dir on top of stdlib. Also a lot of questions here and potential issues.
  3. something else?

Replace web cache

The goal is to remove the local lru cache implementation and replace it with go-pkgz/lcw package. LCW provides lru, ttl and redis caches. Recently added scache support should be fully compatible with rest's cache and migration supposed to be relatively painless

SendErrorJSON sets Content-Type: text/plain instead Content-Type: application/json; charset=utf-8

github.com/go-pkgz/rest v1.5.0

For some reason, SendErrorJSON writes the wrong Content-Type.

rest.SendErrorJSON(w, r, nil, http.StatusNotFound, nil, "nothing to show")

Response:

HTTP/1.1 404 Not Found
Date: Thu, 07 May 2020 08:21:12 GMT
Content-Length: 28
Content-Type: text/plain; charset=utf-8

{"error":"nothing to show"}


Response code: 404 (Not Found); Time: 22ms; Content length: 28 bytes

Looks like w.Header().Set("Content-Type", "application/json; charset=utf-8") should be called before w.WriteHeader(code).

SizeLimit middleware performance and memory issues

As reported here the performance of the size limiter not that good for huge requests. This is unlikely even noticeable for a typical request, but in the case of uploading file chunks it is problematic

The current method uses LimitReader to get the allowed part of the request and serves it from bytes buffer after the read. Actually, I'm not even sure why it's causing such a delay. I suspect some deficiency of the testing method, i.e. with size limiter in place the actual read of the data enforced, but maybe without it that read just skipped

Anyhow, for large limits the current approach may utilize a lot of memory, even if the performance problem is not real. Probably the better way to deal with this is to hijack the response writer and deal with the limit on the writer level

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.