ptpb / pb

pb is a formerly-lightweight pastebin and url shortener
Other
549 stars 53 forks source link

When serving JSON responses, replace "Not Found." #134

Closed HalosGhost closed 8 years ago

HalosGhost commented 8 years ago

Right now, even when the client has been set to accept JSON (and therefore expects valid JSON), a GET or DELETE on a paste that does not exist returns the string Not Found. While this correctly conveys the error, it is invalid JSON. I would propose the following response to keep in-line with the other responses:

{"status": "nonexistant"}
buhman commented 8 years ago
14:41:46 +buhman halosghost: that would only work if you expect the paste content to also be encapsulated in json
14:41:49 +buhman is that what you want?
14:42:18 +halosghost no
14:42:23 +buhman then not a bug
14:43:01 +buhman if you want to interpret the response, use the http status code
buhman commented 8 years ago

You're right; DELETE and PUT should definitely always serve complex_response() and not lazy plaintext.

buhman commented 8 years ago

Fixed in ae5d8ef.

HalosGhost commented 8 years ago

@buhman, something is still a bit weird here:

$ curl -H 'Accept: application/json' https://ptpb.pw/l
[["rbcon", "irb"], ["glsl"], ["mql", "mq4", "mq5", "mql4", "mql5"], ["apacheconf", "aconf", "apache"], ["rd"], ["cython", "pyx", "pyrex"], ["delphi", "pas", "pascal", "objectpascal"], ["cpp", "c++"], ["sql"], ["ragel"], ["lcry", "literate-cryptol", "lcryptol"], ["inform6", "i6"], ["monkey"], ["control", "debcontrol"], ["sqlite3"], ["dart"], ["nesc"], ["croc"], ["erb"], ["lhs", "literate-haskell", "lhaskell"], ["django", "jinja"], ["ini", "cfg", "dosini"], ["sourceslist", "sources.list", "debsources"], ["treetop"], ["clojure", "clj"], ["octave"], ["chapel", "chpl"], ["python", "py", "sage"], ["css+smarty"], ["logos"], ["properties", "jproperties"], ["http"], ["robotframework"], ["docker", "dockerfile"], ["dylan-lid", "lid"], ["lua"], ["html+smarty"], ["squidconf", "squid.conf", "squid"], ["dg"], ["cobol"], ["cpp-objdump", "c++-objdumb", "cxx-objdump"], ["clojurescript", "cljs"], ["nimrod", "nim"], ["html"], ["json"], ["html+genshi", "html+kid"], ["make", "makefile", "mf", "bsdmake"], ["basemake"], ["io"], ["nixos", "nix"], ["smalltalk", "squeak", "st"], ["pov"], ["xml+cheetah", "xml+spitfire"], ["registry"], ["html+twig"], ["logtalk"], ["ragel-objc"], ["ioke", "ik"], ["gnuplot"], ["systemverilog", "sv"], ["maql"], ["console"], ["asy", "asymptote"], ["css+myghty"], ["abap"], ["nit"], ["aspx-cs"], ["rql"], ["erl"], ["haxeml", "hxml"], ["html+mako"], ["perl6", "pl6"], ["applescript"], ["xml+velocity"], ["idris", "idr"], ["cfc"], ["i6t"], ["pan"], ["erlang"], ["xtend"], ["scala"], ["iex"], ["clay"], ["moocode", "moo"], ["smarty"], ["css+genshitext", "css+genshi"], ["ceylon"], ["cobolfree"], ["antlr-perl"], ["pawn"], ["vctreestatus"], ["fortran"], ["lidr", "literate-idris", "lidris"], ["ooc"], ["css+django", "css+jinja"], ["gooddata-cl"], ["xquery", "xqy", "xq", "xql", "xqm"], ["css+lasso"], ["xml+evoque"], ["mozpercentpreproc"], ["cfs"], ["aspectj"], ["factor"], ["antlr-python"], ["js+erb", "javascript+erb", "js+ruby", "javascript+ruby"], ["sass"], ["rust"], ["cbmbas"], ["rebol"], ["agda"], ["objective-j", "objectivej", "obj-j", "objj"], ["js+php", "javascript+php"], ["xml+erb", "xml+ruby"], ["d-objdump"], ["ssp"], ["sml"], ["js+django", "javascript+django", "js+jinja", "javascript+jinja"], ["yaml+jinja", "salt", "sls"], ["bat", "batch", "dosbatch", "winbatch"], ["todotxt"], ["cuda", "cu"], ["haml"], ["eiffel"], ["js+lasso", "javascript+lasso"], ["jsonld", "json-ld"], ["newspeak"], ["html+cheetah", "html+spitfire", "htmlcheetah"], ["groovy"], ["objdump-nasm"], ["bash", "sh", "ksh", "shell"], ["irc"], ["moon", "moonscript"], ["smali"], ["cryptol", "cry"], ["tads3"], ["perl", "pl"], ["prolog"], ["fsharp"], ["awk", "gawk", "mawk", "nawk"], ["cucumber", "gherkin"], ["koka"], ["spec"], ["tex", "latex"], ["antlr-java"], ["html+velocity"], ["hybris", "hy"], ["ecl"], ["scheme", "scm"], ["objective-c++", "objectivec++", "obj-c++", "objc++"], ["lagda", "literate-agda"], ["nginx"], ["stan"], ["go"], ["genshi", "kid", "xml+genshi", "xml+kid"], ["postgresql", "postgres"], ["dylan"], ["java"], ["javascript+mozpreproc"], ["mscgen", "msc"], ["text"], ["racket", "rkt"], ["raw"], ["pytb"], ["mask"], ["genshitext"], ["blitzbasic", "b3d", "bplus"], ["redcode"], ["foxpro", "vfp", "clipper", "xbase"], ["gas", "asm"], ["vala", "vapi"], ["jlcon"], ["zephir"], ["alloy"], ["c-objdump"], ["ada", "ada95", "ada2005"], ["elixir", "ex", "exs"], ["ragel-java"], ["qml"], ["rconsole", "rout"], ["evoque"], ["psql", "postgresql-console", "postgres-console"], ["boo"], ["brainfuck", "bf"], ["jsp"], ["antlr-as", "antlr-actionscript"], ["csharp", "c#"], ["pike"], ["newlisp"], ["js", "javascript"], ["diff", "udiff"], ["slim"], ["lighty", "lighttpd"], ["nemerle"], ["fancy", "fy"], ["cheetah", "spitfire"], ["bbcode"], ["gosu"], ["mupad"], ["blitzmax", "bmax"], ["live-script", "livescript"], ["befunge"], ["shell-session"], ["urbiscript"], ["xml+smarty"], ["matlabsession"], ["puppet"], ["splus", "s", "r"], ["hylang"], ["mason"], ["pig"], ["ragel-em"], ["haskell", "hs"], ["ragel-c"], ["js+cheetah", "javascript+cheetah", "js+spitfire", "javascript+spitfire"], ["css+erb", "css+ruby"], ["css+php"], ["ragel-d"], ["vgl"], ["cfengine3", "cf3"], ["lean"], ["c"], ["vhdl"], ["ebnf"], ["aspx-vb"], ["inform7", "i7"], ["matlab"], ["html+evoque"], ["twig"], ["xml+django", "xml+jinja"], ["ca65"], ["js+myghty", "javascript+myghty"], ["minid"], ["powershell", "posh", "ps1", "psm1"], ["mysql"], ["verilog", "v"], ["velocity"], ["dylan-console", "dylan-repl"], ["js+genshitext", "js+genshi", "javascript+genshitext", "javascript+genshi"], ["at", "ambienttalk", "ambienttalk/2"], ["rsl"], ["ragel-cpp"], ["bro"], ["dpatch"], ["xml+php"], ["mozhashpreproc"], ["rst", "rest", "restructuredtext"], ["d"], ["cirru"], ["pycon"], ["isabelle"], ["jade"], ["fan"], ["handlebars"], ["postscript", "postscr"], ["tcl"], ["xul+mozpreproc"], ["gst"], ["julia", "jl"], ["pypylog", "pypy"], ["xslt"], ["hx", "haxe", "hxsl"], ["golo"], ["cmake"], ["swig"], ["kal"], ["kconfig", "menuconfig", "linux-config", "kernel-config"], ["as", "actionscript"], ["protobuf", "proto"], ["css+mozpreproc"], ["snobol"], ["bugs", "winbugs", "openbugs"], ["felix", "flx"], ["cfm"], ["html+lasso"], ["nsis", "nsi", "nsh"], ["groff", "nroff", "man"], ["pot", "po"], ["idl"], ["ragel-ruby", "ragel-rb"], ["mathematica", "mma", "nb"], ["mako"], ["tcsh", "csh"], ["html+handlebars"], ["antlr-ruby", "antlr-rb"], ["vim"], ["scss"], ["ocaml"], ["nasm"], ["php", "php3", "php4", "php5"], ["modula2", "m2"], ["resource", "resourcebundle"], ["jags"], ["numpy"], ["openedge", "abl", "progress"], ["gap"], ["sp"], ["cypher"], ["autoit"], ["antlr"], ["swift"], ["js+smarty", "javascript+smarty"], ["sparql"], ["yaml"], ["kotlin"], ["myghty"], ["html+php"], ["xml"], ["xml+lasso"], ["xml+mako"], ["common-lisp", "cl", "lisp", "elisp", "emacs", "emacs-lisp"], ["css"], ["dtd"], ["ec"], ["qbasic", "basic"], ["objdump"], ["trac-wiki", "moin"], ["as3", "actionscript3"], ["html+myghty"], ["modelica"], ["css+mako"], ["limbo"], ["js+mako", "javascript+mako"], ["antlr-cpp"], ["liquid"], ["py3tb"], ["llvm"], ["red", "red/system"], ["python3", "py3"], ["jasmin", "jasminxt"], ["antlr-csharp", "antlr-c#"], ["objective-c", "objectivec", "obj-c", "objc"], ["antlr-objc"], ["rhtml", "html+erb", "html+ruby"], ["plpgsql"], ["ahk", "autohotkey"], ["chai", "chaiscript"], ["apl"], ["tea"], ["opa"], ["rb", "ruby", "duby"], ["ts"], ["coq"], ["mxml"], ["coffee-script", "coffeescript", "coffee"], ["vb.net", "vbnet"], ["xml+myghty"], ["igor", "igorpro"], ["html+django", "html+jinja", "htmldjango"], ["lasso", "lassoscript"], ["scaml"], ["lsl"], ["duel", "jbst", "jsonml+bst"], ["rexx", "arexx"], ["scilab"]]
$ curl -H 'Accept: application/json' https://ptpb.pw/ls
- paraiso-light
- manni
- monokai
- igor
- emacs
- bw
- fruity
- murphy
- autumn
- vs
- vim
- tango
- native
- perldoc
- default
- pastie
- borland
- xcode
- trac
- rrt
- colorful
- friendly
- paraiso-dark

In theory, both of these should be using complex_response(). Is there a reason that /ls isn't obeying the Accept header?