@@ -21,7 +21,7 @@ var MAX_REQ_BODY_SIZE_ERR error = errors.New(constants.MAX_REQ_BODY_SIZE_ERR_TEX
2121var FAILED_TO_FORWARD_TO_MMAR_CLIENT_ERR error = errors .New (constants .FAILED_TO_FORWARD_TO_MMAR_CLIENT_ERR_TEXT )
2222var FAILED_TO_READ_RESP_FROM_MMAR_CLIENT_ERR error = errors .New (constants .FAILED_TO_READ_RESP_FROM_MMAR_CLIENT_ERR_TEXT )
2323
24- func responseWith (respText string , w http.ResponseWriter , statusCode int ) {
24+ func respondWith (respText string , w http.ResponseWriter , statusCode int ) {
2525 w .Header ().Set ("Content-Length" , strconv .Itoa (len (respText )))
2626 w .Header ().Set ("Connection" , "close" )
2727 w .WriteHeader (statusCode )
@@ -34,15 +34,15 @@ func handleCancel(cause error, w http.ResponseWriter) {
3434 // Cancelled, do nothing
3535 return
3636 case READ_BODY_CHUNK_TIMEOUT_ERR :
37- responseWith (cause .Error (), w , http .StatusRequestTimeout )
37+ respondWith (cause .Error (), w , http .StatusRequestTimeout )
3838 case READ_BODY_CHUNK_ERR , CLIENT_DISCONNECTED_ERR :
39- responseWith (cause .Error (), w , http .StatusBadRequest )
39+ respondWith (cause .Error (), w , http .StatusBadRequest )
4040 case READ_RESP_BODY_ERR :
41- responseWith (cause .Error (), w , http .StatusInternalServerError )
41+ respondWith (cause .Error (), w , http .StatusInternalServerError )
4242 case MAX_REQ_BODY_SIZE_ERR :
43- responseWith (cause .Error (), w , http .StatusRequestEntityTooLarge )
43+ respondWith (cause .Error (), w , http .StatusRequestEntityTooLarge )
4444 case FAILED_TO_FORWARD_TO_MMAR_CLIENT_ERR , FAILED_TO_READ_RESP_FROM_MMAR_CLIENT_ERR :
45- responseWith (cause .Error (), w , http .StatusServiceUnavailable )
45+ respondWith (cause .Error (), w , http .StatusServiceUnavailable )
4646 }
4747}
4848
@@ -119,3 +119,18 @@ func serializeRequest(ctx context.Context, r *http.Request, cancel context.Cance
119119 // Send serialized request through channel
120120 serializedRequestChannel <- requestBuff .Bytes ()
121121}
122+
123+ // Create HTTP response sent from mmar server to the end-user client
124+ func createSerializedServerResp (status string , statusCode int , body string ) bytes.Buffer {
125+ resp := http.Response {
126+ Status : status ,
127+ StatusCode : statusCode ,
128+ Body : io .NopCloser (bytes .NewBufferString (body )),
129+ }
130+
131+ // Writing response to buffer to tunnel it back
132+ var responseBuff bytes.Buffer
133+ resp .Write (& responseBuff )
134+
135+ return responseBuff
136+ }
0 commit comments