fixed go plugin

This commit is contained in:
Roberto De Ioris
2013-01-20 18:04:06 +01:00
parent 9f55579b87
commit 8f996bb68d
4 changed files with 14 additions and 17 deletions
+1 -1
View File
@@ -420,7 +420,7 @@ void sanitize_args() {
}
}
const char *uwsgi_http_status_msg(char *status, size_t *len) {
const char *uwsgi_http_status_msg(char *status, uint16_t *len) {
struct http_status_codes *http_sc;
for (http_sc = hsc; http_sc->message != NULL; http_sc++) {
if (!strncmp(http_sc->key, status, 3)) {
+1 -1
View File
@@ -28,7 +28,7 @@ int uwsgi_response_prepare_headers(struct wsgi_request *wsgi_req, char *status,
if (status_len <= 4) {
char *new_sc = NULL;
size_t new_sc_len = 0;
size_t sc_len = 0;
uint16_t sc_len = 0;
const char *sc = uwsgi_http_status_msg(status, &sc_len);
if (sc) {
new_sc = uwsgi_concat3n(status, 3, " ", 1, (char *)sc, sc_len);
+11 -14
View File
@@ -163,7 +163,7 @@ func CacheDel(key string) bool {
C.uwsgi_cache_wlock()
if int(C.uwsgi_cache_del(k, C.uint16_t(kl), C.uint64_t(0))) < 0 {
if int(C.uwsgi_cache_del(k, C.uint16_t(kl), C.uint64_t(0), C.uint16_t(0))) < 0 {
C.uwsgi_cache_rwunlock();
return false;
}
@@ -303,7 +303,6 @@ type ResponseWriter struct {
wsgi_req *C.struct_wsgi_request
headers http.Header
wroteHeader bool
headers_chunk string
}
func (w *ResponseWriter) Write(p []byte) (n int, err error) {
@@ -318,27 +317,25 @@ func (w *ResponseWriter) Write(p []byte) (n int, err error) {
// TODO fix it !!!
func (w *ResponseWriter) WriteHeader(status int) {
proto := "HTTP/1.0"
if w.r.ProtoAtLeast(1, 1) {
proto = "HTTP/1.1"
}
codestring := http.StatusText(status)
w.headers_chunk += proto + " " + strconv.Itoa(status) + " " + codestring + "\r\n"
c_status := C.CString(w.headers_chunk)
C.uwsgi_response_preare_headers(w.wsgi_req, c_status, C.size_t(len(w.headers_chunk)) )
var tmp_buf string = strconv.Itoa(status) + " " + codestring
c_status := C.CString(tmp_buf)
defer C.free(unsafe.Pointer(c_status))
C.uwsgi_response_prepare_headers(w.wsgi_req, c_status, C.uint16_t(len(tmp_buf)) )
if w.headers.Get("Content-Type") == "" {
w.headers.Set("Content-Type", "text/html; charset=utf-8")
}
for k := range w.headers {
hk_c := C.CString(k)
defer C.free(unsafe.Pointer(hk_c))
for _, v := range w.headers[k] {
v = strings.NewReplacer("\n", " ", "\r", " ").Replace(v)
v = strings.TrimSpace(v)
w.headers_chunk += k + ": " + v + "\r\n"
hv_c := C.CString(v)
defer C.free(unsafe.Pointer(hv_c))
C.uwsgi_response_add_header(w.wsgi_req, hk_c, C.uint16_t(len(k)), hv_c, C.uint16_t(len(v)))
}
}
c_h_chunk := C.CString(w.headers_chunk)
defer C.free(unsafe.Pointer(c_h_chunk))
C.uwsgi_simple_response_write_header(w.wsgi_req, c_h_chunk, C.size_t(len(w.headers_chunk)))
w.wroteHeader = true
}
@@ -374,7 +371,7 @@ func uwsgi_go_helper_request(env *map[string]string, wsgi_req *C.struct_wsgi_req
if err != nil {
} else {
httpReq.Body = &BodyReader{wsgi_req}
w := ResponseWriter{httpReq, wsgi_req,http.Header{},false, ""}
w := ResponseWriter{httpReq, wsgi_req,http.Header{},false}
if uwsgi_default_request_handler != nil {
uwsgi_default_request_handler(&w, httpReq)
} else if uwsgi_default_handler != nil {
+1 -1
View File
@@ -3765,7 +3765,7 @@ ssize_t uwsgi_sendfile_do(int, int, size_t, size_t);
int uwsgi_proto_base_fix_headers(struct wsgi_request *);
int uwsgi_response_add_content_length(struct wsgi_request *, uint64_t);
const char *uwsgi_http_status_msg(char *, size_t *);
const char *uwsgi_http_status_msg(char *, uint16_t *);
#define uwsgi_response_add_connection_close(x) uwsgi_response_add_header(x, "Connection", 10, "close", 5)
#define uwsgi_response_add_content_type(x, y, z) uwsgi_response_add_header(x, "Content-Type", 12, y, z)