forked from invopop/gobl.fatturapa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Alex Malaszkiewicz <[email protected]> Co-authored-by: Grzeg Lisowski <[email protected]>
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package sdi | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"log" | ||
"net/http" | ||
"net/http/httputil" | ||
) | ||
|
||
// SdIMessageHandler processes SOAP requests from SdI (Sistema di Interscambio) | ||
func SdIMessageHandler(w http.ResponseWriter, req *http.Request) { | ||
requestDump, err := httputil.DumpRequest(req, true) | ||
if err != nil { | ||
log.Printf("Failed to dump incoming request: %s\n", err) | ||
http.Error(w, "Internal Server Error", http.StatusInternalServerError) | ||
return | ||
} | ||
log.Printf("Incoming request:\n%s", requestDump) | ||
|
||
responseBody := []byte("Hello World") | ||
response := &http.Response{ | ||
Status: "200 OK", | ||
StatusCode: http.StatusOK, | ||
Proto: "HTTP/2.0", | ||
ProtoMajor: 2, | ||
ProtoMinor: 0, | ||
Body: io.NopCloser(bytes.NewReader(responseBody)), | ||
ContentLength: int64(len(responseBody)), | ||
Header: make(http.Header), | ||
} | ||
response.Header.Set("Content-Type", "text/plain") | ||
|
||
responseDump, err := httputil.DumpResponse(response, true) | ||
if err != nil { | ||
log.Printf("Failed to dump outgoing response: %v", err) | ||
http.Error(w, "Internal Server Error", http.StatusInternalServerError) | ||
return | ||
} | ||
log.Printf("Outgoing response:\n%s", responseDump) | ||
|
||
for k, v := range response.Header { | ||
for _, vv := range v { | ||
w.Header().Add(k, vv) | ||
} | ||
} | ||
|
||
w.WriteHeader(response.StatusCode) | ||
|
||
_, err = w.Write(responseBody) | ||
if err != nil { | ||
log.Printf("Failed to send response: %v", err) | ||
return | ||
} | ||
} |