78 lines
1.8 KiB
Go
78 lines
1.8 KiB
Go
/*
|
|
Copyright © 2019 Darko Luketic <info@icod.de>
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
package server
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"net/http"
|
|
"os/exec"
|
|
)
|
|
|
|
type Handler struct {
|
|
binary string
|
|
}
|
|
|
|
func NewHandler(binary string) *Handler {
|
|
h := new(Handler)
|
|
h.binary = binary
|
|
return h
|
|
}
|
|
|
|
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
b, e := h.FetchDom(fmt.Sprintf("https://%s%s", r.Host, r.RequestURI))
|
|
if e != nil {
|
|
fmt.Fprintln(w, e.Error())
|
|
return
|
|
}
|
|
w.Write(b.Bytes())
|
|
}
|
|
|
|
func (h *Handler) FetchDom(url string) (*bytes.Buffer, error) {
|
|
params := []string{
|
|
"--disable-client-side-phishing-detection",
|
|
"--disable-cloud-import",
|
|
"--disable-default-apps",
|
|
"--disable-dinosaur-easter-egg",
|
|
"--disable-new-tab-first-run",
|
|
"--disable-offer-upload-credit-cards",
|
|
"--disable-signin-promo",
|
|
"--disable-sync",
|
|
"--disable-translate",
|
|
"--hide-scrollbars",
|
|
"--incognito",
|
|
"--mute-audio",
|
|
"--no-default-browser-check",
|
|
"--no-first-run",
|
|
"--noerrdialogs",
|
|
"--password-store=basic",
|
|
"--window-size=1280,1696",
|
|
"--headless",
|
|
"--disable-gpu",
|
|
"--disable-software-rasterizer",
|
|
"--no-sandbox",
|
|
"--dump-dom",
|
|
url,
|
|
}
|
|
cmd := exec.Command(h.binary, params...)
|
|
buf := bytes.NewBuffer(nil)
|
|
cmd.Stdout = buf
|
|
if e := cmd.Run(); e != nil {
|
|
return nil, e
|
|
}
|
|
return buf, nil
|
|
}
|