Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML pages are rendered in raw mode #2283

Closed
tonivj5 opened this issue Dec 25, 2015 · 28 comments
Closed

HTML pages are rendered in raw mode #2283

tonivj5 opened this issue Dec 25, 2015 · 28 comments
Labels
馃拪 bug Something isn't working
Milestone

Comments

@tonivj5
Copy link
Contributor

tonivj5 commented Dec 25, 2015

When I show a HTML file in RAW mode, this doesn't show its code, this is being rendering when It mustn't be so.

  • Example
    image

Saludos! 馃憤

@unknwon
Copy link
Member

unknwon commented Dec 25, 2015

Can you reproduce this on https://try.gogs.io ?

@unknwon unknwon added the status: needs feedback Tell me more about it label Dec 25, 2015
@unknwon unknwon added this to the 0.9.0 milestone Dec 25, 2015
@tonivj5
Copy link
Contributor Author

tonivj5 commented Dec 25, 2015

Yeah! Here is! 馃憤

@unknwon
Copy link
Member

unknwon commented Dec 25, 2015

Thanks! How does GitHub handles it?

I think this is expected behavior. Gogs does not give any assumption for raw format of content, and browser determines it automatically.

Since you use .html as extension, it is reasonable that browser treats it as an HTML page.

@tonivj5
Copy link
Contributor Author

tonivj5 commented Dec 25, 2015

Yeah, I thought same, but GitHub use the <pre> tag.

For example, a web page in RAW mode in GitHub

@unknwon
Copy link
Member

unknwon commented Dec 25, 2015

but GitHub use the

 tag.

How do you know?

@tonivj5
Copy link
Contributor Author

tonivj5 commented Dec 25, 2015

Thanks to inspect element of Chrome...

image

@tonivj5
Copy link
Contributor Author

tonivj5 commented Dec 25, 2015

So, the HTML text isn't interpreted by browser 馃憤

@unknwon
Copy link
Member

unknwon commented Dec 25, 2015

I see. I think GitHub only does this for .html and .xml?

@unknwon unknwon changed the title Problem with RAW mode HTML pages are rendered in raw mode Dec 25, 2015
@unknwon unknwon added the 馃敤 enhancement Make it better, faster label Dec 25, 2015
@tonivj5
Copy link
Contributor Author

tonivj5 commented Dec 25, 2015

I think that for all of them. I'm just see that javascript and php text use it too.

@unknwon
Copy link
Member

unknwon commented Dec 25, 2015

OK... I think it involves something else bigger... I believe if you do curl xxx, GitHub responses pure raw content of any types.

@unknwon unknwon removed this from the 0.9.0 milestone Dec 25, 2015
@unknwon unknwon added 馃拪 bug Something isn't working and removed status: needs feedback Tell me more about it 馃敤 enhancement Make it better, faster labels Dec 25, 2015
@tonivj5
Copy link
Contributor Author

tonivj5 commented Dec 25, 2015

It's possible!

@novaeye
Copy link
Contributor

novaeye commented Dec 25, 2015

how about this:

func ServeData(ctx *middleware.Context, name string, reader io.Reader) error {
    buf := make([]byte, 1024)
    n, _ := reader.Read(buf)
    if n > 0 {
        buf = buf[:n]
    }

    _, isTextFile := base.IsTextFile(buf)
    if !isTextFile {
        _, isImageFile := base.IsImageFile(buf)
        if !isImageFile {
            ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+path.Base(ctx.Repo.TreeName))
            ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary")
        }
    } else {
        ctx.Resp.Header().Set("Content-Type", "text/plain; charset=utf-8") // <<<<<<
    }
    ctx.Resp.Write(buf)
    _, err := io.Copy(ctx.Resp, reader)
    return err
}

@novaeye
Copy link
Contributor

novaeye commented Dec 25, 2015

@xxxTonixxx I think it is a feature of the browser(FF/IE/Chrome), not github

@tonivj5
Copy link
Contributor Author

tonivj5 commented Dec 25, 2015

@novaeye Hmmm, It's true that in source code doesn't appear the <pre> tag ... Good catch! 馃憤

@unknwon unknwon added this to the 0.9.0 milestone Dec 25, 2015
@unknwon unknwon added the status: needs feedback Tell me more about it label Dec 25, 2015
@unknwon
Copy link
Member

unknwon commented Dec 25, 2015

@tonivj5
Copy link
Contributor Author

tonivj5 commented Dec 25, 2015

It's ok! but... There is a problem with encoding characters (谩茅铆贸煤...).

  • These show so:
    image
  • And these must show so:
    image

@andreynering
Copy link
Contributor

Github raw view serves files with Content-Type: text. This means that neither HTML, CSS or JS can be used directly in web pages.

There's a services that serve files from Github with proper content type headers: https://rawgit.com

Maybe in Gogs we could have a URL parameter to it: http://.../index.html?raw=1. So people could still use files directly if they want.

(I think it should default to false if not provided so something like <style href="my.css"> will work by default in a web page, without having to add ?raw=0).

@tonivj5
Copy link
Contributor Author

tonivj5 commented Dec 26, 2015

That will be interesnting 馃憤, but... to work from the address bar doesn't think that it's the best way...

@unknwon
Copy link
Member

unknwon commented Dec 27, 2015

@xxxTonixxx your screenshots more like browser auto-detection thing for me. My Chrome show what I expect:

image

@tonivj5
Copy link
Contributor Author

tonivj5 commented Dec 27, 2015

Ok! I already have changed and right now it's working... but, it's strange that with GitHub's raw mode was working without I change nothing... With Firefox was equal but with IE is working good!

Thank you!!! 馃槃 馃憤

@unknwon
Copy link
Member

unknwon commented Dec 27, 2015

@xxxTonixxx GitHub may do encoding transformation, but Gogs serves "raw" from Git blob.

@unknwon unknwon removed the status: needs feedback Tell me more about it label Dec 27, 2015
@unknwon unknwon closed this as completed Dec 27, 2015
@ghost
Copy link

ghost commented Feb 8, 2016

what if somebody want a raw html rendered.

To get something like gitpages, or so.

Use case:
I want to have a tiddlywiky in my repo, and to serve it directly from gogs.

@unknwon
Copy link
Member

unknwon commented Feb 8, 2016

@pykiss Hmm... maybe you can file another issue and ask likes Allow request header to set HTML rendered in raw mode?

@tkschmidt
Copy link

@pykiss have you already filed a new issue? I would also have such a feature back. All my analysis in R (statistics) are rendered in the end to a html page. Normally I just compare different reports by looking in my git history but now it is broken. It worked until last release.

image

@unknwon
Copy link
Member

unknwon commented Feb 10, 2016

@tkschmidt

Normally I just compare different reports by looking in my git history but now it is broken. It worked until last release.

What does this mean specifically?

@tkschmidt
Copy link

sry, for bad wording. Until last release while looking at the raw file type i got my rendered html. Now, because it is wrapped into another html it is broken and I get the view above.

@unknwon
Copy link
Member

unknwon commented Feb 11, 2016

@tkschmidt OK.. I think this is intended to not render.

You may want to follow up on #2593

@Antisunny
Copy link

Still unsolved?

I wget a python file via its raw url, but the downloaded file is in html format ???????

@gogs gogs locked and limited conversation to collaborators Apr 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
馃拪 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants