Questions tagged [go-http]

This tag is for questions related to Go's HTTP package

Go's net/http package provides HTTP client and server implementations.

121 questions
2
votes
0 answers

Not showing my style in html with embed golang feature

I want to use the embed features in Golang but I can't link up the CSS style to the HTML. I tried to find more information to see what I do wrong, but I could not find any help. main.go package main import ( "embed" "html/template" …
Belin
  • 33
  • 4
2
votes
1 answer

When writing an http handler, do we have to listen for request context cancellation?

Supposed that I'm writing an http handler, that do something else before returning a response, do I have to setup a listener to check wether the http request context has been canceled? so that it can return immediately, or is there any other way to…
2
votes
1 answer

Default HTTP file server - modifications of the content

How can I compose the default Go HTTP file server (serve if exists, show file listing otherwise) with additional HTML? Sample http.go with default file server: package main import "net/http" func main() { http.Handle("/",…
ubndpdhsc
  • 43
  • 5
2
votes
1 answer

Rate limit specific endpoints

I am new to GoLang and working on my first API. I have two endpoints, and I want to rate limit only one of them. I found a helpful tutorial to get me started, and I've based my approach off of the tutorial, recognizing that this approach will rate…
John Harrington
  • 1,314
  • 12
  • 36
2
votes
1 answer

Go HTTP Proxy - Prevent Re-using Proxy Connections

I have a set of SOCKS proxies, which are sitting behind a load balancer (an AWS Network Load Balancer, to be specific). When the load balancer receives a request on the SOCKS port, it forwards the request to the Docker container (proxy) with the…
Jordan
  • 3,998
  • 9
  • 45
  • 81
2
votes
0 answers

Pipe entire http.Response through http.ResponseWriter in Go

I'm trying to proxy a request through Go's net/http package. I copy the http.Request object, send that, and a receive an http.Response object. I want to copy everything from that http.Response object through the http.ResponseWriter back to the…
4343
  • 39
  • 1
2
votes
1 answer

cancel a web request and handle errors inside the ReverseProxy Director function

I am wondering if it would be possible to cancel a web request or send an internal response to the client inside the ReverseProxy.Director function. Suppose we do something that throws an error, or we have other reason to not forward the…
The Fool
  • 16,715
  • 5
  • 52
  • 86
2
votes
1 answer

Golang ServeHTTP make proxy error EOF on POST request

I’m working on proxy server with gin and ServeHTTP. 
Actually GET and OPTIONS request works well. But when I trying multiples POST request I get EOF error one in two request. I’ve test to make repeat request without proxy service and its work well,…
Vivien B
  • 83
  • 8
2
votes
0 answers

How can do Http request with openssl sign on golang

We have a private rsa key and a secret phrase. How can I make a request signed with this? I know how to make a request signed with a certificate, and it works, for example: cert, err := tls.LoadX509KeyPair(path+"user.crt", path+"user.key") if err !=…
codices
  • 49
  • 7
2
votes
1 answer

How to set Home page and static files in same path

if I run the URL http://localhost:8080/ I want to run the Index function and If I run http://localhost:8080/robot.txt it should show static folder files func main() { http.HandleFunc("/", Index) http.Handle("/", http.StripPrefix("/",…
Faizal Ahamed
  • 118
  • 1
  • 4
  • 7
2
votes
0 answers

How to fix net/http: HTTP/1.x transport connection broken: malformed HTTP response

Whenever I try to do a GET requests for google.com I get this error: Get "https://www.google.com/": net/http: HTTP/1.x transport connection broken: malformed HTTP response I want to try to get the homepage for google and I don't know why this is…
jjboi8708
  • 65
  • 1
  • 7
2
votes
1 answer

Handling custom 404 pages with http.FileServer

I'm currently using a basic http.FileServer setup to serve a simple static site. I need to handle 404 errors with a custom not found page. I've been looking into this issue quite a bit, and I cannot determine what the best solution is. I've seen…
Luke Johnson
  • 183
  • 2
  • 12
2
votes
1 answer

FileServer handles not found css with MIME type error instead of 404

I’m running a basic http.FileServer to serve a static site and I’ve come across an issue where requests for css files that don’t exist are getting canceled with a MIME type error: Refused to apply style from 'http://localhost:8080/assets/main.css'…
Luke Johnson
  • 183
  • 2
  • 12
2
votes
1 answer

Sending file to Google drive API from golang code yields error: Unsupported content with type: image/jpeg

based on the Google Drive API docs the proper way of uploading a file is: curl -v -H 'Authorization: Bearer mytoken' -F 'metadata={"name": "test3.jpeg"};type=application/json' -F file=@jpeg_image.jpeg…
zakaria amine
  • 3,412
  • 2
  • 20
  • 35
2
votes
2 answers

different Content-Type with httptest and curl

I'm trying this Go code package main import ( "github.com/gorilla/mux" "io" "log" "net/http" ) func HealthCheckHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type",…
JuanPablo
  • 23,792
  • 39
  • 118
  • 164
1
2
3
8 9