Commits

libqxt  committed d0a0053

QxtWebCore::redirect(QString,int)

  • Participants
  • Parent commits eff3546

Comments (0)

Files changed (3)

File src/web/qxtwebcore.cpp

         return qxt_d().listen(address,port);
         }
 
+void QxtWebCore::redirect(QString location,int code)
+        {
+         instance()->qxt_d().redirect(location,code);
+        }
 
 
 //-----------------------implementation----------------------------
         }
 
 
+void QxtWebCorePrivate::redirect(QString loc,int code)
+        {
+        if(loc.isEmpty())
+                loc="/";
+        QxtWebCore::header("Status",QString::number(code).toUtf8());
+        QxtWebCore::header("Location",loc.toUtf8());
+        send(QString("<a href=\""+loc+"\">"+loc+"</a>").toUtf8());
+        }
 
 
 

File src/web/qxtwebcore.h

                 static QIODevice * socket();
                 int listen (quint16 port = 8000,const QHostAddress & address = QHostAddress::LocalHost);
 
+
+                static void redirect(QString location,int code=303);
+
                 /*helper*/
                 static QxtError parseString(QByteArray str, post_t & POST);
                 static QByteArray readContent(int maxsize=5000);

File src/web/qxtwebcore_p.h

                 void send(QByteArray);
                 void sendheader();
                 void header(QByteArray,QByteArray);
+                void redirect(QString,int );
 
                 virtual void incomingConnection(int socketDescriptor);