Changeset 10 in code for trunk/morty.go


Ignore:
Timestamp:
Oct 25, 2016, 2:55:06 PM (9 years ago)
Author:
asciimoo
Message:

[enh] disallow crawling bots

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/morty.go

    r9 r10  
    124124
    125125func (p *Proxy) RequestHandler(ctx *fasthttp.RequestCtx) {
     126
     127        if appRequestHandler(ctx) {
     128                return
     129        }
     130
    126131        requestHash := popRequestParam(ctx, []byte("mortyhash"))
    127132
     
    224229                ctx.Write(responseBody)
    225230        }
     231}
     232
     233func appRequestHandler(ctx *fasthttp.RequestCtx) bool {
     234        if bytes.Equal(ctx.Path(), []byte("/robots.txt")) {
     235                ctx.SetContentType("text/plain")
     236                ctx.Write([]byte("User-Agent: *\nDisallow: /\n"))
     237                return true
     238        }
     239        return false
    226240}
    227241
Note: See TracChangeset for help on using the changeset viewer.