golang webserver incorrect rendering in browser

74 views
Skip to first unread message

buzze...@gmail.com

unread,
Feb 24, 2022, 4:27:41 PM2/24/22
to golang-nuts
This little program (attached: weird1.go) reads a small file of html code and delivers it through the golang webserver to a browser. The html code (test2.html) defines a box which it fills with an image ("blank grey.png").

If you point the browser to the html file, the image is correctly displayed. If the go program reads the same file and sends it to the browser through the webserver on localhost:8080, the html is displayed correctly except that the image is omitted. If you do a copy of the 'view-page-source' for the incorrectly displayed htm and present it to the browser as a file (identical to the original html file) the image is shown correctly. What is wrong?

weird1.go
test2.html
blank grey.png

Christian von Kietzell

unread,
Feb 24, 2022, 5:45:08 PM2/24/22
to golan...@googlegroups.com
Hi,

your program never defines and registers a handler for the browser to get the
PNG file from the server. You essentially only serve test2.html. If you take a look at
the developer console on the browser (network tab) and reload the page you'll
see that "blank grey.png" will be the same size as test2.html. That's because
your server always returns test2.html for any request... registering "/" is
essentially a catch-all if no other routes are defined.


Chris
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/8e262895-95de-4bdf-ab60-0f168ce7455cn%40googlegroups.com.


>



--
Nothing to see here. Move along.
Reply all
Reply to author
Forward
0 new messages