139 questions
1
vote
1
answer
142
views
Go http.FileServer returns 301 for existing file in tests, but works in browser
I'm building a Go web server that serves static files using TDD.
When I run my server and access /static/index.html in the browser, it works fine and returns the file. However, when I run my test ...
0
votes
0
answers
89
views
Force end connections in connection pool if request timedout
I am trying to see whats the best practice for configuring go http client. We recently had a load balancer node of a dependency go down and the node was replaced with same ip. However we see that ...
1
vote
1
answer
145
views
Interactions between Golang http.Client.Timeout and http.Transport.MaxConnsPerHost
The docs for http.Client.Timeout says: The timeout includes connection time, any redirects, and reading the response body
The docs for http.Transport.MaxConnsPerHost says: MaxConnsPerHost optionally ...
1
vote
1
answer
259
views
GoLang CookieJar seemingly not able to find localhost cookies
I'm trying to send some cookies up with a request from some Go code I'm writing, and it seemingly does not work with localhost cookies. Is there an option or something that needs to be done to make ...
0
votes
1
answer
428
views
In Golang, HTTP Client RoundTripper wraps Payload with an unnecessary object
Issue
It seems that the HTTP Client is sending a different message than the Payload I want to send to the server.
In the sample code, you can see that the Payload passed to http.NewRequest is a ...
0
votes
1
answer
273
views
Large Multipart.File uploads directly to AWS S3
I have a go-chi (golang) web application that is hosted behind nginx (reverse proxy - proxy_pass directives), that accepts file uploads that are then uploaded to AWS S3.
The request with a file is ...
1
vote
1
answer
281
views
How to reuse an http.Client instance with a dynamic proxy URL in Go
I'm building an HTTP client in Go and I need to make calls to an endpoint via a proxy server. The proxy address is not fixed, so I'm currently creating a new http.Client instance every time I need to ...
1
vote
2
answers
131
views
Unable to detect client exit in GO with net/http when not on same machine
I am trying to make an application that periodically sends data to a client's browser, unitl the client's browser closes. My problem is, that I am unable to detect client closing the browser.
I have ...
1
vote
1
answer
747
views
Subrouting using net/http in golang 1.22, issue with trailing "/" redirection
I am using the net/http standard library package for subrouting in Golang while developing a simple API. However, I encountered a problem. I have user routes for registration with POST /v1/users/. ...
1
vote
1
answer
136
views
Prepoluting index page before mux Handle call
I recently built a small blog website for testing purposes and I'm a little stuck with this problem while writing the server in Go. I have all the files of the website inside the static folder, which ...
1
vote
2
answers
589
views
Compose middlewares in go-chi?
I am writing an API using go-chi and my endpoint can be authenticated either via Basic Auth or an API Key. How can I compose two independently functioning middlewares?
Here is what the router looks ...
1
vote
0
answers
1k
views
How to remove SSRF vulnerability(CWE ID 918) from http.NewRequestWithContext() function in golang?
We are facing the issue of SSRF vulnerability in http.NewRequestWithContext(ctx, "GET", url, nil) function in Golang during Veracode scan.
The URL that is coming to this function contains ...
-1
votes
1
answer
64
views
unable to recreate CURL equivalent request in go-lang [duplicate]
I'm using a request bin (running on localhost:8080/anything) to capture what my application sends (kennethreitz/httpbin)
so now i have two similar POST requests using two different user agents, which ...
1
vote
0
answers
62
views
Each request takes longer than the last one
I am scanning IP addresses in a network (where I am VPN'ed).
func scanTestHandler(c *gin.Context) {
var ipRanges ScanApiBody
decoder := json.NewDecoder(c.Request.Body)
if err := decoder....
-1
votes
1
answer
481
views
Golang HTTP Request types [closed]
The "net/http" golang package has a response type which I find confusing. It defines a member Body io.ReadCloser which requires an additional call to some form of an io writer to process. ...
1
vote
0
answers
269
views
Self-signed certificate for http webserver in Go not working
BACKGROUND
I created a simple http webserver in go. Below is a snippet of the code where *Static, Addr and port are the frontend files, the server address, and the port respectively
func ...
2
votes
1
answer
384
views
Go HTTP server resets connection on multipart form with file and text
I've been trying to set up an HTTP server in Go that allows users to upload files via HTML forms. This form would also have a text input for other reasons. However, upon submitting the form, my ...
4
votes
1
answer
2k
views
Golang Uploading Big file to external API with multipart. How to avoid `io.Copy(io.Writer, io.Reader)` problem
My objective is to upload a big file to POST https://somehost/media using golang's builtin net/http package.
HTTP format of the Api call
POST /media HTTP/1.1
Host: somehost
Content-Length: 434
Content-...
1
vote
1
answer
2k
views
How to solve "Headers were already written. Wanted to override status code 200 with 400" In gin
I'm trying to calculate a report independently of an HTTP request using the Gin framework, but I also want to return it to the request if it hasn't been closed yet. The following code snippet ...
1
vote
0
answers
408
views
go - Are "http.Transport" and "http.Client" safe for concurrent modification in Go?
According to http.Client and http.Transport documentation in Go's built-in net/http package:
// The Client's Transport typically has internal state (cached TCP
// connections), so Clients should be ...
1
vote
0
answers
101
views
How can I simultaneously listen on multiple sets of ports with different routes and control their open/close status in Go?
In a recent project, I came across a requirement to simultaneously listen on multiple sets of ports with different routes, and have the ability to control the open/close status of each listening group....
0
votes
1
answer
1k
views
http client: faster timeout when no network
When making a http Get request in Go, it waits the full timeout time before returning an error, even when there is no network connection.
I assume in the internals it knows pretty quickly it has ...
1
vote
1
answer
2k
views
Get stacktrace when context.Context is canceled by http.TimeoutHandler
For debugging purposes, how can I get more information on exactly where my http.TimeoutHandler wrapped handler canceled an active http.Request::Context()?
Ideally, a stacktrace should be logged.
...
2
votes
0
answers
213
views
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
...
1
vote
1
answer
130
views
Imagekit - Golang | How to use Context
Im trying to upload images from my Golang backend to imagekit via the imagekit sdk. Im facing problems with understanding what the context api is used for.
Currently I don't really use context in my ...
1
vote
0
answers
180
views
AWS GO SDK returns "AuthFailure: AWS was not able to validate the provided access credentials"
I am developing a simple automation tool using a Go Fiber HTTP server to start and stop AWS instances using the Go SDK v1.44.156.
The service listens to an endpoint at /csm/aws/:region/:instance_id/...
0
votes
0
answers
388
views
How do I pass cookies from HEAD to POST-Request
I need to pass csrf cookies _gorila_csrf and csrf_token from my HEAD-Request to my POST-Request. What is the best practice for that?
For now I get the Cookie Value with res.Cookies() for the two ...
2
votes
1
answer
1k
views
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 ...
1
vote
0
answers
224
views
Is it right when I use the method "mux.HandleFunc()"
I'm a green hand with Go. I have a problem with this code.`
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
mux := http.NewServeMux()
mux....
2
votes
1
answer
607
views
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"...
1
vote
1
answer
787
views
Reusing vs Creating new instance of http.Transport in httputil.ReverseProxy
I've implemented http reverse proxy middleware which used with Gin framework app:
app := gin.New()
app.Use(proxy.ReverseProxy("127.0.0.1:8008")) // HERE I'm attaching ReverseProxy ...
1
vote
2
answers
461
views
Golang follow orginal http method
I am trying to call an API so the thing is when I am trying to call it from Postman with "Follow original HTTP method" on it's working fine but on disabling it giving a 400-Bad request ...
2
votes
1
answer
1k
views
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 ...
1
vote
1
answer
630
views
Make a attendance table for students with Go
I'm trying to create a Student Attendance web app. Currently have a struct
type Student struct {
StudentID int
StudentName string
Created time.Time
}
All student will be listed on list....
1
vote
1
answer
2k
views
docker image for elasticsearch and golang error: unsupported protocol scheme ""
I am running an api using elasticsearch, go, and docker. I have an image for elasticsearch, and an image for the HTTP server scheme. I should be able to run docker-compose up, however for whatever ...
0
votes
1
answer
380
views
Should I reuse context object in http server when calling other service?
I am developing a server application with the net/http package.
Everytime a request arrives, the net/http package reads the request and create a http.Request object.
My server needs to call AWS ...
0
votes
0
answers
84
views
GO get original router url of a request
In flask, I do
from flask import request
route = request.url_rule.rule if request.url_rule else request.path
So that I can get the "original" URL registered in Blueprint.
For example, when ...
1
vote
1
answer
2k
views
Go - After request headers are set, request body is empty
To create an outgoing POST request, func NewRequest() from net/http library is used.
request body is parsed as a param.
After request is created I set request headers using Set() func. After setting ...
1
vote
1
answer
1k
views
Unable to create a handler that responds with error in Go to cause a retry
I am trying to verify if the go-retryablehttp execution performs retries as per the specified config.
The verification methodology is to create a test that
creates a retryable client
creates a new ...
0
votes
1
answer
3k
views
Golang minio client can put and remove but not stat or get objects
My go application can upload and remove objects from a Minio server on the same docker network but statObject and getObject return empty information. The file does exist in the minio console.
Here is ...
5
votes
1
answer
4k
views
go-chi router override middleware to set content type
I have a go API which so far has always returned JSON. I use chi router and set it up using middleware like this in my main function:
func router() http.Handler {
r := chi.NewRouter()
r.Use(render....
1
vote
2
answers
168
views
Go json manipulation
Hey there just started to transform my python code to Go, but have some issue on the json manipulations... here is my code so far
package test
import (
"encoding/json"
"fmt&...
-2
votes
1
answer
901
views
How to reuse HTTP request instance in Go
I'm building an API that scrapes some data off a webpage.
To do so, i need to send a GET request to a home page, scrape a 'RequestVerificationToken' from the HTML, then send another POST request to ...
3
votes
0
answers
869
views
Log error returned in ServeHTTP with custom logger
I am using Go Chi with a custom handler function that returns an error.
Ideally I want to write a middleware function that uses my custom handler function and return an error that will eventually need ...
0
votes
1
answer
301
views
golang http disable TRACE method
Is there something like the traceEnable parameter in apache, in golang net/http?
I do have something like the following, but I do want to listen to GET, POST and HEAD, however not to the TRACE method
...
1
vote
3
answers
2k
views
golang - Exit http handler from anywhere
I'm using the net/http package and wondering how I can exit the handler from anywhere in the code. Say I have this code:
func main() {
http.HandleFunc("/", handler)
http....
1
vote
0
answers
425
views
Go HTTP RoundTripper: Preventing Connection Reuse Based on Response
I have a use case where I want to use an HTTP client in Go with pooled connections (connection re-use), but with the special case where a connection is intentionally closed (not allowed for re-use) if ...
1
vote
1
answer
1k
views
Go HTTP idle connection pool and http trace
I have a long running GO program(version 1.18) which sends hundreds of GET requests simultaneously per second using RESTY to the remote https://api.abcd.com. Each GET request is a separate go-routine ...
2
votes
1
answer
952
views
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 ...
2
votes
0
answers
815
views
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 ...